public IBitcoinBasedTransaction CreateP2PkSwapRefundTx(BitcoinBasedCurrency currency) { const int paymentQty = 1_0000_0000; var paymentTx = CreateP2PkSwapPaymentTx(currency); var paymentTxOutputs = paymentTx.Outputs .Where(o => o.Value == paymentQty) .ToArray(); var paymentTxTotal = paymentTxOutputs.Aggregate(0L, (s, output) => s + output.Value); var lockTime = DateTimeOffset.Now.AddHours(12); const int amount = 9999_0000; const int fee = 1_0000; // change = 0; var tx = BitcoinBasedCommon.CreatePaymentTx( currency: Common.BtcTestNet, outputs: paymentTxOutputs, from: Common.Alice.PubKey, to: Common.Alice.PubKey, amount: amount, fee: fee, lockTime: lockTime ); Assert.True(tx.Check()); Assert.Equal(paymentTxTotal - fee, tx.TotalOut); Assert.Equal(fee, tx.GetFee(paymentTxOutputs)); return(tx); }
public IBitcoinBasedTransaction SignP2PkSwapRefundTx(BitcoinBasedCurrency currency) { const int paymentQty = 1_0000_0000; var paymentTx = CreateP2PkSwapPaymentTx(currency); var paymentTxOutputs = paymentTx.Outputs.Where(o => o.Value == paymentQty).ToArray(); var lockTime = DateTimeOffset.Now.AddHours(12); const int amount = 9999_0000; const int fee = 1_0000; // change = 0; var refundTx = BitcoinBasedCommon.CreatePaymentTx( currency: Common.BtcTestNet, outputs: paymentTxOutputs, from: Common.Alice.PubKey, to: Common.Alice.PubKey, amount: amount, fee: fee, lockTime: lockTime ); var sigHash = new uint256(refundTx.GetSignatureHash(paymentTxOutputs.First())); var aliceSign = Common.Alice.Sign(sigHash, SigHash.All); var bobSign = Common.Bob.Sign(sigHash, SigHash.All); var refundScript = BitcoinBasedSwapTemplate.GenerateSwapRefund(aliceSign, bobSign); refundTx.NonStandardSign(refundScript, paymentTxOutputs.First()); Assert.True(refundTx.Verify(paymentTxOutputs)); return(refundTx); }
public IBitcoinBasedTransaction SignHtlcP2PkhScriptSwapRefundTx(BitcoinBasedConfig currency) { const int paymentQty = 1_0000_0000; var(paymentTx, redeemScriptBytes) = CreateHtlcP2PkhScriptSwapPaymentTx(currency); var paymentTxOutputs = paymentTx.Outputs.Where(o => o.Value == paymentQty).ToArray(); var lockTime = DateTimeOffset.UtcNow.AddHours(1); const int amount = 9999_0000; const int fee = 1_0000; // change = 0; var redeemScript = new Script(redeemScriptBytes); var refundTx = BitcoinBasedCommon.CreatePaymentTx( currency: Common.BtcTestNet, outputs: paymentTxOutputs, from: Common.Alice.PubKey, to: Common.Alice.PubKey, amount: amount, fee: fee, lockTime: lockTime, knownRedeems: redeemScript ); var sigHash = new uint256(refundTx.GetSignatureHash(redeemScript, paymentTxOutputs.First())); var aliceSign = Common.Alice.Sign(sigHash, SigHash.All); var refundScript = BitcoinBasedSwapTemplate.GenerateHtlcSwapRefundForP2Sh( aliceRefundSig: aliceSign.ToBytes(), aliceRefundPubKey: Common.Alice.PubKey.ToBytes(), redeemScript: redeemScriptBytes); refundTx.NonStandardSign(refundScript, paymentTxOutputs.First()); Assert.True(refundTx.Verify(paymentTxOutputs, currency)); return(refundTx); }