public void SetToP2PKH_FromPubTest(PublicKey pub, bool comp, byte[] expected) { PubkeyScript scr = new PubkeyScript(); scr.SetToP2PKH(pub, comp); Assert.Equal(expected, scr.Data); }
private IPubkeyScript BuildPubkeyScript(string address) { Address addr = new Address(); if (!addr.TryGetType(address, out PubkeyScriptType scrType, out byte[] hash)) { throw new FormatException(); } PubkeyScript scr = new PubkeyScript(); switch (scrType) { case PubkeyScriptType.P2PKH: scr.SetToP2PKH(hash); break; case PubkeyScriptType.P2SH: scr.SetToP2SH(hash); break; case PubkeyScriptType.P2WPKH: scr.SetToP2WPKH(hash); break; case PubkeyScriptType.P2WSH: scr.SetToP2WSH(hash); break; default: throw new NotImplementedException(); } return(scr); }
public void SetToP2PKH_FromAddressTest() { PubkeyScript scr = new PubkeyScript(); scr.SetToP2PKH(KeyHelper.Pub1CompAddr); byte[] expected = Helper.HexToBytes($"76a914{KeyHelper.Pub1CompHashHex}88ac"); Assert.Equal(expected, scr.Data); }
public void SetToP2PKH_FromByteTest() { PubkeyScript scr = new PubkeyScript(); scr.SetToP2PKH(Helper.GetBytes(20)); byte[] expected = Helper.HexToBytes($"76a914{Helper.GetBytesHex(20)}88ac"); Assert.Equal(expected, scr.Data); }
public void SetToP2PKH_ExceptionTest() { PubkeyScript scr = new PubkeyScript(); byte[] nba = null; PublicKey npub = null; string naddr = null; Assert.Throws <ArgumentNullException>(() => scr.SetToP2PKH(nba)); Assert.Throws <ArgumentOutOfRangeException>(() => scr.SetToP2PKH(new byte[19])); Assert.Throws <ArgumentNullException>(() => scr.SetToP2PKH(npub, true)); Assert.Throws <ArgumentNullException>(() => scr.SetToP2PKH(naddr)); Assert.Throws <ArgumentNullException>(() => scr.SetToP2PKH("")); Assert.Throws <FormatException>(() => scr.SetToP2PKH("$")); Assert.Throws <FormatException>(() => scr.SetToP2PKH("3FuPMWfen385RLwbMsZEVhx9QsHyR6zEmv")); }
public override bool SetOperations() { Errors = null; if (string.IsNullOrEmpty(Address)) { Errors = "Address can not be empty."; return(false); } else if (addrManager.TryGetType(Address, out PubkeyScriptType scrType, out byte[] hash)) { PubkeyScript scr = new PubkeyScript(); switch (scrType) { case PubkeyScriptType.P2PKH: scr.SetToP2PKH(hash); break; case PubkeyScriptType.P2SH: scr.SetToP2SH(hash); break; case PubkeyScriptType.P2WPKH: scr.SetToP2WPKH(hash); break; case PubkeyScriptType.P2WSH: scr.SetToP2WSH(hash); break; default: Errors = "Undefined script type."; // This should never happen. return(false); } OpsToAdd = scr.OperationList; return(true); }