本文整理汇总了C#中NBitcoin.Transaction.Sign方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Sign方法的具体用法?C# Transaction.Sign怎么用?C# Transaction.Sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.Sign方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pay
public static void Pay(BitcoinSecret secret, BitcoinAddress toAddress, Money amount, Transaction fundingTransaction)
{
var fee = Money.Coins(0.0001m);
Transaction payment = new Transaction();
payment.Inputs.Add(new TxIn()
{
PrevOut = new OutPoint(fundingTransaction.GetHash(), 1)
});
payment.Outputs.Add(new TxOut()
{
Value = amount,
ScriptPubKey = toAddress.ScriptPubKey
});
var output = fundingTransaction.Outputs[0];
var change = output.Value - amount - fee;
if (change < 0)
{
Console.WriteLine("There is not enough BTC in the funding transaction ({0}) to make this payment ({1})", output.Value, amount);
Console.WriteLine("No payment being sent");
return;
}
payment.Outputs.Add(new TxOut()
{
Value = output.Value - amount - fee,
ScriptPubKey = output.ScriptPubKey
});
//Feedback !
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);
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);
}
}