本文整理汇总了C#中NBitcoin.Transaction.AddInput方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.AddInput方法的具体用法?C# Transaction.AddInput怎么用?C# Transaction.AddInput使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.AddInput方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: CanSignTransactionStandardMode
public void CanSignTransactionStandardMode()
{
var ledger = GetLedger();
var walletPubKey = ledger.GetWalletPubKey(new KeyPath("1'/0"));
var address = (BitcoinAddress)walletPubKey.Address;
Transaction funding = new Transaction();
funding.AddInput(Network.Main.GetGenesis().Transactions[0].Inputs[0]);
funding.Outputs.Add(new TxOut(Money.Coins(1.1m), address));
funding.Outputs.Add(new TxOut(Money.Coins(1.0m), address));
funding.Outputs.Add(new TxOut(Money.Coins(1.2m), address));
var coins = funding.Outputs.AsCoins();
var spending = new Transaction();
spending.LockTime = 1;
spending.Inputs.AddRange(coins.Select(o => new TxIn(o.Outpoint, o.ScriptPubKey)));
spending.Outputs.Add(new TxOut(Money.Coins(0.5m), BitcoinAddress.Create("15sYbVpRh6dyWycZMwPdxJWD4xbfxReeHe")));
spending.Outputs.Add(new TxOut(Money.Coins(0.8m), address));
spending.Outputs.Add(new TxOut(Money.Zero, TxNullDataTemplate.Instance.GenerateScriptPubKey(new byte[] { 1, 2 })));
var signed = ledger.SignTransaction(
new KeyPath("1'/0"),
new Coin[]
{
new Coin(funding, 0),
new Coin(funding, 1),
new Coin(funding, 2),
}, new Transaction[]
{
funding
}, spending);
}