public void SignInputs(Transaction transaction, SignerBag bag) { foreach (var transactionInput in transaction.Inputs) { var redeem = bag.Find(transactionInput.Outpoint); Thrower.If(redeem.IsNull()).Throw <TransactionException>("redeem script was not found"); var redeemScript = new Script.Script(CryptoUtil.ConvertHex(redeem.ScriptPubKeyHex)); var signature = this.CalculateSignature(transaction, transactionInput.Outpoint, redeem.PrivateKey.Key, redeemScript, Transaction.SigHash.All); var signedScript = ScriptBuilder.CreateInputScript(signature, redeem.PrivateKey.Key); transactionInput.ScriptBytes = signedScript.GetProgram(); } }
public void given_a_dummy_transaction_When_createing_input_scripts_Then_all_should_pass() { var dummySig = TransactionSignature.Dummy(); var key = new BitcoinPrivateKey(parameters, "KzXzfn1AKhA9XaBtr2enevcsw1w3NXWXUDgKKpqa8QyVi1cKYKdS").Key; // pay-to-pubkey var inputScript = ScriptBuilder.CreateInputScript(dummySig); Assert.IsTrue(inputScript.Chunks.ElementAt(0).Data.SequenceEqual(dummySig.EncodeToBitcoin())); inputScript = ScriptBuilder.CreateInputScript(null); Assert.AreEqual(inputScript.Chunks.ElementAt(0).Opcode, ScriptOpCodes.OP_0); // pay-to-address inputScript = ScriptBuilder.CreateInputScript(dummySig, key); Assert.IsTrue(inputScript.Chunks.ElementAt(0).Data.SequenceEqual(dummySig.EncodeToBitcoin())); inputScript = ScriptBuilder.CreateInputScript(null, key); Assert.AreEqual(inputScript.Chunks.ElementAt(0).Opcode, ScriptOpCodes.OP_0); Assert.IsTrue(inputScript.Chunks.ElementAt(1).Data.SequenceEqual(key.PublicKeyBytes)); }