當前位置: 首頁>>代碼示例>>C#>>正文


C# Transaction.ToDictionary方法代碼示例

本文整理匯總了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;
            }
        }
開發者ID:LedgerHQ,項目名稱:ledger-dotnet-api,代碼行數:53,代碼來源:LedgerClient.cs


注:本文中的NBitcoin.Transaction.ToDictionary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。