本文整理匯總了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);
}
}