3

我在 TestNet 上运行。我正在尝试添加多个交易输入 TxIn() 以便从这些输入中花费。当我广播我的交易时,它返回成功,但我在区块浏览器上看不到它。我已经用一个 TxIn() 处理了一个事务,当我广播它时,它是成功的,我可以在区块浏览器上查看它。我已经在这上面超过 2 天了。将非常感谢您的帮助

var bitcoinPrivateKey = new BitcoinSecret("cNZupUgfs54DmsShwxa1wpomQcszUtuJYFvx9zWPbXrT7KsWtiUd");
        var network = bitcoinPrivateKey.Network;
        var address = bitcoinPrivateKey.GetAddress();
        var client = new QBitNinjaClient(network);
        var balance = client.GetBalance(address).Result;

        var transactionId = uint256.Parse("06c0aec7543467951abad0c28998a2c1fc1cdc34e01113f8ec1fdb22be854771");
        var transactionResponse = client.GetTransaction(transactionId).Result;

        var tx = new Transaction();
        foreach (var operation in balance.Operations)
        {
            OutPoint spendOutPoint = null;

            var coinsReceived = operation.ReceivedCoins;
            foreach (var coin in coinsReceived)
            {
                if (coin.TxOut.ScriptPubKey == bitcoinPrivateKey.ScriptPubKey)
                {
                    spendOutPoint = coin.Outpoint;
                    tx.Inputs.Add(new TxIn()
                    {
                        PrevOut = spendOutPoint
                    });
                }
            }


        }
        var chimaTestDestinationAddress = new BitcoinPubKeyAddress("mxgN2AiqHjKfGvo6Y57fAe4Y754rPdKf4P");
        TxOut chimaTestDestinationAddressTxOut = new TxOut()
        {
            Value = new Money((decimal)0.50, MoneyUnit.BTC),
            ScriptPubKey = chimaTestDestinationAddress.ScriptPubKey
        };
        TxOut ugoChangeBackTxOut = new TxOut()
        {
            Value = new Money((decimal)2.98, MoneyUnit.BTC),
            ScriptPubKey = bitcoinPrivateKey.ScriptPubKey
        };
        tx.Outputs.Add(chimaTestDestinationAddressTxOut);
        tx.Outputs.Add(ugoChangeBackTxOut);
        var msg = "ugo the jedi master";
        var msgBytes = Encoding.UTF8.GetBytes(msg);

        TxOut txDesc = new TxOut()
        {
            Value = Money.Zero,
            ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(msgBytes)
        };
        tx.Outputs.Add(txDesc);


        tx.Inputs[0].ScriptSig = bitcoinPrivateKey.PubKey.WitHash.ScriptPubKey;
        tx.Inputs[1].ScriptSig = bitcoinPrivateKey.PubKey.WitHash.ScriptPubKey;
        tx.Inputs[2].ScriptSig = bitcoinPrivateKey.PubKey.WitHash.ScriptPubKey;
        tx.Inputs[3].ScriptSig = bitcoinPrivateKey.PubKey.WitHash.ScriptPubKey;
        tx.Inputs[4].ScriptSig = bitcoinPrivateKey.PubKey.WitHash.ScriptPubKey;
        tx.Sign(bitcoinPrivateKey, false);

        BroadcastResponse broadcast = client.Broadcast(tx).Result;
        if (!broadcast.Success)
        {
            Console.WriteLine("ErrorCode: " + broadcast.Error.ErrorCode);
            Console.WriteLine("Error message: " + broadcast.Error.Reason);
        }
        else
        {
            Console.WriteLine("Success, you can now checkout the transaction in any block explorer");
            Console.WriteLine("Hash: " + tx.GetHash());
        }
4

0 回答 0