public IBitcoinBasedTransaction SignSwapRefundTxAlice2Bob(BitcoinBasedCurrency currency) { const int paymentQty = 3000; var paymentTx = CreateP2PkSwapPaymentTxAlice2Bob(currency); var paymentTxOutputs = paymentTx.Outputs.Where(o => o.Value == paymentQty).ToArray(); var lockTime = DateTimeOffset.Now.AddHours(12); const int amount = 2000; const int fee = 1000; // change = 0; var refundTx = BitcoinBasedCommon.CreateSwapRefundTx( 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 CreateSwapRefundTxAlice2Bob(BitcoinBasedCurrency currency) { const int paymentQty = 3000; var paymentTx = CreateP2PkSwapPaymentTxAlice2Bob(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 = 2000; const int fee = 1000; // change = 0; var tx = BitcoinBasedCommon.CreateSwapRefundTx( 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); }