public IBitcoinBasedTransaction CreatePaymentTx(BitcoinBasedConfig currency) { var initTx = BitcoinBasedCommon.CreateFakeTx(currency, Common.Alice.PubKey, 1_0000_0000, 1_0000_0000); const int amount = 1_0000_0000; const int fee = 1_0000; const int change = 9999_0000; var tx = currency.CreatePaymentTx( unspentOutputs: initTx.Outputs, destinationAddress: Common.Bob.PubKey.GetAddress(currency), changeAddress: Common.Alice.PubKey.GetAddress(currency), amount: amount, fee: fee, lockTime: DateTimeOffset.MinValue); Assert.NotNull(tx); Assert.True(tx.Check()); Assert.NotNull(tx.Outputs.FirstOrDefault(o => o.Value == amount)); Assert.NotNull(tx.Outputs.FirstOrDefault(o => o.Value == change)); Assert.Equal(tx.Outputs.First(o => o.Value == amount).DestinationAddress(currency.Network), Common.BobAddress(currency)); Assert.Equal(tx.Outputs.First(o => o.Value == change).DestinationAddress(currency.Network), Common.AliceAddress(currency)); Assert.Equal(initTx.TotalOut - fee, tx.TotalOut); Assert.Equal(fee, tx.GetFee(initTx.Outputs)); return(tx); }
public IBitcoinBasedTransaction SignHtlcP2PkhScriptSwapRedeemTx(BitcoinBasedConfig currency) { const int paymentQty = 1_0000_0000; var(paymentTx, redeemScriptBytes) = CreateHtlcP2PkhScriptSwapPaymentTx(currency); var paymentTxOutputs = paymentTx.Outputs .Where(o => o.Value == paymentQty) .ToArray(); const int amount = 9999_0000; const int fee = 1_0000; var redeemScript = new Script(redeemScriptBytes); var redeemTx = currency.CreatePaymentTx( unspentOutputs: paymentTxOutputs, destinationAddress: Common.Bob.PubKey.GetAddress(currency), changeAddress: Common.Bob.PubKey.GetAddress(currency), amount: amount, fee: fee, lockTime: DateTimeOffset.MinValue, knownRedeems: redeemScript); var sigHash = new uint256(redeemTx.GetSignatureHash(redeemScript, paymentTxOutputs.First())); var scriptSig = BitcoinBasedSwapTemplate.GenerateP2PkhSwapRedeemForP2Sh( sig: Common.Bob.Sign(sigHash, SigHash.All).ToBytes(), pubKey: Common.Bob.PubKey.ToBytes(), secret: Common.Secret, redeemScript: redeemScriptBytes); redeemTx.NonStandardSign(scriptSig, paymentTxOutputs.First()); Assert.True(redeemTx.Verify(paymentTxOutputs, currency)); return(redeemTx); }