本文整理汇总了C#中NBitcoin.Transaction.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.Clone方法的具体用法?C# Transaction.Clone怎么用?C# Transaction.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.Clone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例2: CombineSignaturesCore
private Transaction CombineSignaturesCore(Transaction signed1, Transaction signed2)
{
if(signed1 == null)
return signed2;
if(signed2 == null)
return signed1;
var tx = signed1.Clone();
for(int i = 0; i < tx.Inputs.Count; i++)
{
if(i >= signed2.Inputs.Count)
break;
var txIn = tx.Inputs[i];
var coin = FindCoin(txIn.PrevOut);
var scriptPubKey = coin == null
? (DeduceScriptPubKey(txIn.ScriptSig) ?? DeduceScriptPubKey(signed2.Inputs[i].ScriptSig))
: coin.TxOut.ScriptPubKey;
Money amount = null;
if(coin != null)
amount = coin is IColoredCoin ? ((IColoredCoin)coin).Bearer.Amount : ((Coin)coin).Amount;
var result = Script.CombineSignatures(
scriptPubKey,
new TransactionChecker(tx, i, amount),
GetScriptSigs(signed1.Inputs.AsIndexedInputs().Skip(i).First()),
GetScriptSigs(signed2.Inputs.AsIndexedInputs().Skip(i).First()));
var input = tx.Inputs.AsIndexedInputs().Skip(i).First();
input.WitScript = result.WitSig;
input.ScriptSig = result.ScriptSig;
}
return tx;
}
示例3: EstimateSize
public int EstimateSize(Transaction tx)
{
if(tx == null)
throw new ArgumentNullException("tx");
var clone = tx.Clone();
clone.Inputs.Clear();
var baseSize = clone.ToBytes().Length;
int inputSize = 0;
foreach(var txin in tx.Inputs.AsIndexedInputs())
{
var coin = FindSignableCoin(txin) ?? FindCoin(txin.PrevOut);
if(coin == null)
throw CoinNotFound(txin);
inputSize += EstimateScriptSigSize(coin) + 41;
}
return baseSize + inputSize;
}
示例4: ContinueToBuild
/// <summary>
/// Allows to keep building on the top of a partially built transaction
/// </summary>
/// <param name="transaction">Transaction to complete</param>
/// <returns></returns>
public TransactionBuilder ContinueToBuild(Transaction transaction)
{
if(_CompletedTransaction != null)
throw new InvalidOperationException("Transaction to complete already set");
_CompletedTransaction = transaction.Clone();
return this;
}
示例5: SignTransaction
public Transaction SignTransaction(Transaction transaction, SigHash sigHash)
{
var tx = transaction.Clone();
SignTransactionInPlace(tx, sigHash);
return tx;
}