我正在使用 NBitcoin 签署交易。这里 Transaction sign(secret, bool) 方法给出错误。(我在互联网上搜索过,但没有任何帮助。)它不是 bool 而是说要传递 Coin 对象,我应该怎么做?这是我的代码:
var fee = Money.Coins(0.0001m);
Transaction payment=Transaction.Create(bitcoinNetwork);
payment.Inputs.Add(new TxIn()
{
PrevOut = new OutPoint(fundingTransaction.GetHash(), 1)
});
payment.Outputs.Add(new TxOut()
{
Value = amount-fee,
ScriptPubKey = toAddress.ScriptPubKey
});
var output = fundingTransaction.Outputs[0];
payment.Outputs.Add(new TxOut()
{
Value = output.Value - amount - fee,
ScriptPubKey = output.ScriptPubKey
});
var message = "Thanks :)";
var bytes = Encoding.UTF8.GetBytes(message);
payment.Outputs.Add(new TxOut()
{
Value = Money.Zero,
ScriptPubKey = TxNullDataTemplate.Instance.GenerateScriptPubKey(bytes)
});
Console.WriteLine(payment);
payment.Inputs[0].ScriptSig = fundingTransaction.Outputs[1].ScriptPubKey;
payment.Sign(secret, false); // the problem arises here
using (var node = Node.Connect(Network.Main))
{
Console.WriteLine("Doing version handshake");
node.VersionHandshake();
Console.WriteLine("Sending message");
node.SendMessage(new InvPayload(InventoryType.MSG_TX, payment.GetHash()));
node.SendMessage(new TxPayload(payment));
Thread.Sleep(500);
}