本文整理汇总了C#中NBitcoin.Transaction.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.ToDictionary方法的具体用法?C# Transaction.ToDictionary怎么用?C# Transaction.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.ToDictionary方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SignTransaction
public Transaction SignTransaction(KeyPath keyPath, ICoin[] signedCoins, Transaction[] parents, Transaction transaction)
{
using(Transport.Lock())
{
var pubkey = GetWalletPubKey(keyPath).UncompressedPublicKey.Compress();
var parentsById = parents.ToDictionary(p => p.GetHash());
var coinsByPrevout = signedCoins.ToDictionary(c => c.Outpoint);
List<TrustedInput> trustedInputs = new List<TrustedInput>();
foreach(var input in transaction.Inputs)
{
Transaction parent;
parentsById.TryGetValue(input.PrevOut.Hash, out parent);
if(parent == null)
throw new KeyNotFoundException("Parent transaction " + input.PrevOut.Hash + " not found");
trustedInputs.Add(GetTrustedInput(parent, (int)input.PrevOut.N));
}
var inputs = trustedInputs.ToArray();
transaction = transaction.Clone();
foreach(var input in transaction.Inputs)
{
ICoin previousCoin = null;
coinsByPrevout.TryGetValue(input.PrevOut, out previousCoin);
if(previousCoin != null)
input.ScriptSig = previousCoin.GetScriptCode();
}
bool newTransaction = true;
foreach(var input in transaction.Inputs.AsIndexedInputs())
{
ICoin coin = null;
if(!coinsByPrevout.TryGetValue(input.PrevOut, out coin))
continue;
UntrustedHashTransactionInputStart(newTransaction, input, inputs);
newTransaction = false;
UntrustedHashTransactionInputFinalizeFull(transaction.Outputs);
var sig = UntrustedHashSign(keyPath, null, transaction.LockTime, SigHash.All);
input.ScriptSig = PayToPubkeyHashTemplate.Instance.GenerateScriptSig(sig, pubkey);
ScriptError error;
if(!Script.VerifyScript(coin.TxOut.ScriptPubKey, transaction, (int)input.Index, Money.Zero, out error))
return null;
}
return transaction;
}
}