public IBitcoinBasedTransaction CreateSegwitPaymentTxAlice2Bob(BitcoinBasedCurrency currency) { var initTx = CreateFakeTx(currency, Common.Alice.PubKey); const int amount = 3000; const int fee = 1000; const int change = 2000; var tx = BitcoinBasedCommon.CreateSegwitPaymentTx( currency: currency, outputs: initTx.Outputs, from: Common.Alice.PubKey, to: Common.Bob.PubKey, amount: amount, fee: fee); 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), Common.BobSegwitAddress(currency)); Assert.Equal(initTx.TotalOut - fee, tx.TotalOut); Assert.Equal(fee, tx.GetFee(initTx.Outputs)); return(tx); }
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); }
public IBitcoinBasedTransaction CreateFakeTx(BitcoinBasedCurrency currency, PubKey destination) { const int output1 = 2000; const int output2 = 4000; var tx = BitcoinBasedCommon.CreateFakeTx(currency, destination, output1, output2); Assert.NotNull(tx); Assert.Equal(output1 + output2, tx.TotalOut); return(tx); }