本文整理匯總了C#中NBitcoin.Transaction.AddOutput方法的典型用法代碼示例。如果您正苦於以下問題:C# Transaction.AddOutput方法的具體用法?C# Transaction.AddOutput怎麽用?C# Transaction.AddOutput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.AddOutput方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: CreateSend
public Transaction CreateSend(BitcoinAddress bitcoinAddress, Money value)
{
if(bitcoinAddress.Network != Network)
throw new InvalidOperationException("This bitcoin address does not belong to the network");
Transaction tx = new Transaction();
tx.AddOutput(value, bitcoinAddress);
this.CompleteTx(tx);
return tx;
}
示例2: CompleteTx
public bool CompleteTx(Transaction tx, Money fees, Account pool = null)
{
pool = pool ?? Accounts.Available;
var entries = pool.GetEntriesToCover(tx.TotalOut + fees, false);
if(entries == null)
return false;
foreach(var entry in entries)
{
tx.AddInput(new TxIn(entry.OutPoint));
}
var surplus = entries.Sum(i => i.TxOut.Value) - fees - tx.TotalOut;
if(surplus != Money.Zero)
tx.AddOutput(surplus, GetKey().PubKey.ID);
for(int i = 0 ; i < entries.Length ; i++)
{
var entry = entries[i];
var vin = tx.Inputs[i];
var key = GetKey(entry.TxOut.ScriptPubKey.GetDestination());
tx.Inputs[i].ScriptSig = new PayToPubkeyHashTemplate().GenerateScriptPubKey(key.PubKey);
var hash = tx.Inputs[i].ScriptSig.SignatureHash(tx, i, SigHash.All);
var sig = key.Sign(hash);
tx.Inputs[i].ScriptSig = new PayToPubkeyHashTemplate().GenerateScriptSig(new TransactionSignature(sig, SigHash.All), key.PubKey);
}
return true;
}