Пример #1
0
        public IBitcoinBasedTransaction CreatePaymentTx(BitcoinBasedCurrency 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), Common.BobAddress(currency));
            Assert.Equal(tx.Outputs.First(o => o.Value == change).DestinationAddress(currency), Common.AliceAddress(currency));
            Assert.Equal(initTx.TotalOut - fee, tx.TotalOut);
            Assert.Equal(fee, tx.GetFee(initTx.Outputs));

            return(tx);
        }
Пример #2
0
        public IBitcoinBasedTransaction SignHtlcP2PkhScriptSwapRedeemTx(BitcoinBasedCurrency currency)
        {
            const int paymentQty = 1_0000_0000;

            var(paymentTx, redeemScript) = CreateHtlcP2PkhScriptSwapPaymentTx(currency);
            var paymentTxOutputs = paymentTx.Outputs
                                   .Where(o => o.Value == paymentQty)
                                   .ToArray();

            const int amount = 9999_0000;
            const int fee    = 1_0000;

            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);

            var sigHash = new uint256(redeemTx.GetSignatureHash(new Script(redeemScript), paymentTxOutputs.First()));

            var scriptSig = BitcoinBasedSwapTemplate.GenerateP2PkhSwapRedeemForP2Sh(
                sig: Common.Bob.Sign(sigHash, SigHash.All).ToBytes(),
                pubKey: Common.Bob.PubKey.ToBytes(),
                secret: Common.Secret,
                redeemScript: redeemScript);

            redeemTx.NonStandardSign(scriptSig, paymentTxOutputs.First());

            Assert.True(redeemTx.Verify(paymentTxOutputs));

            return(redeemTx);
        }
Пример #3
0
        public IBitcoinBasedTransaction SignHtlcP2PkhSwapRedeemTxByBob(BitcoinBasedCurrency currency)
        {
            const int paymentQty = 3000;

            var paymentTx        = CreateHtlcP2PkhSwapPaymentTxAlice2Bob(currency);
            var paymentTxOutputs = paymentTx.Outputs
                                   .Where(o => o.Value == paymentQty)
                                   .ToArray();

            const int amount = 2000;
            const int fee    = 1000;

            var redeemTx = currency.CreatePaymentTx(
                unspentOutputs: paymentTxOutputs,
                destinationAddress: Common.Bob.PubKey.GetAddress(currency),
                changeAddress: Common.Bob.PubKey.GetAddress(currency),
                amount: amount,
                fee: fee);

            var sigHash      = new uint256(redeemTx.GetSignatureHash(paymentTxOutputs.First()));
            var bobSign      = Common.Bob.Sign(sigHash, SigHash.All).ToBytes();
            var bobPubKey    = Common.Bob.PubKey.ToBytes();
            var redeemScript = BitcoinBasedSwapTemplate.GenerateHtlcP2PkhSwapRedeem(bobSign, bobPubKey, Common.Secret);

            redeemTx.NonStandardSign(redeemScript, paymentTxOutputs.First());

            Assert.True(redeemTx.Verify(paymentTxOutputs));

            return(redeemTx);
        }