本文整理汇总了C#中NBitcoin.Transaction.GetHash方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.GetHash方法的具体用法?C# Transaction.GetHash怎么用?C# Transaction.GetHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NBitcoin.Transaction
的用法示例。
在下文中一共展示了Transaction.GetHash方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddFromTransaction
public void AddFromTransaction(Transaction transaction)
{
var hash = transaction.GetHash();
for(int i = 0 ; i < transaction.Outputs.Count; i++)
{
AddTxOut(new OutPoint(hash, i), transaction.Outputs[i]);
}
}
示例2: OnBroadcastTransaction
internal void OnBroadcastTransaction(Transaction transaction)
{
var hash = transaction.GetHash();
var nodes = Nodes
.Select(n => n.Key.Behaviors.Find<BroadcastHubBehavior>())
.Where(n => n != null)
.ToArray();
foreach(var node in nodes)
{
node.BroadcastTransactionCore(transaction);
}
}
示例3: SendTransaction
public static void SendTransaction(Transaction tx)
{
AddressManager nodeParams = new AddressManager();
IPEndPoint endPoint = TranslateHostNameToIP("http://btcnode.placefullcloud.com", 8333);
nodeParams.Add(new NetworkAddress(endPoint), endPoint.Address);
using (var node = Node.Connect(Network, nodeParams))
{
node.VersionHandshake();
node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));
node.SendMessage(new TxPayload(tx));
}
}
示例4: CreateTransactionFeeCoin
static Coin CreateTransactionFeeCoin(PubKey destination, NoSqlTransactionRepository txRepo)
{
var bitcoinProviderTransaction = new Transaction()
{
Outputs =
{
new TxOut("0.0001" , destination)
}
};
txRepo.Put(bitcoinProviderTransaction.GetHash(), bitcoinProviderTransaction);
return new Coin(new OutPoint(bitcoinProviderTransaction, 0),
bitcoinProviderTransaction.Outputs[0]);
}
示例5: ReceiveTransaction
private void ReceiveTransaction(uint256 block, BlockType? blockType, Transaction tx)
{
var oldBalance = Balance;
var txHash = tx.GetHash();
for(int i = 0 ; i < tx.Outputs.Count ; i++)
{
foreach(var key in _Keys)
{
if(tx.Outputs[i].IsTo(key.PubKey))
{
var entry = new WalletEntry();
entry.Block = block;
entry.ScriptPubKey = tx.Outputs[i].ScriptPubKey;
entry.OutPoint = new OutPoint(tx, i);
entry.Value = tx.Outputs[i].Value;
_Accounts.PushEntry(entry, blockType);
}
}
}
foreach(var txin in tx.Inputs)
{
foreach(var key in _Keys)
{
if(txin.IsFrom(key.PubKey))
{
var entry = new WalletEntry();
entry.Block = block;
entry.OutPoint = txin.PrevOut;
_Accounts.PushEntry(entry, blockType);
}
}
}
OnBalanceChanged(tx, oldBalance, Balance);
}
示例6: AddTransaction
public void AddTransaction(Transaction tx, int height)
{
SetCoins(tx.GetHash(), new Coins(tx, height));
}
示例7: IsRelevantAndUpdate
public bool IsRelevantAndUpdate(Transaction tx)
{
if (tx == null) throw new ArgumentNullException("tx");
var hash = tx.GetHash();
bool fFound = false;
// Match if the filter contains the hash of tx
// for finding tx when they appear in a block
if(isFull)
return true;
if(isEmpty)
return false;
if(Contains(hash))
fFound = true;
for(uint i = 0 ; i < tx.Outputs.Count ; i++)
{
TxOut txout = tx.Outputs[(int)i];
// Match if the filter contains any arbitrary script data element in any scriptPubKey in tx
// If this matches, also add the specific output that was matched.
// This means clients don't have to update the filter themselves when a new relevant tx
// is discovered in order to find spending transactions, which avoids round-tripping and race conditions.
foreach(Op op in txout.ScriptPubKey.ToOps())
{
if(op.PushData != null && op.PushData.Length != 0 && Contains(op.PushData))
{
fFound = true;
if((nFlags & (byte)BloomFlags.UPDATE_MASK) == (byte)BloomFlags.UPDATE_ALL)
Insert(new OutPoint(hash, i));
else if((nFlags & (byte)BloomFlags.UPDATE_MASK) == (byte)BloomFlags.UPDATE_P2PUBKEY_ONLY)
{
var template = StandardScripts.GetTemplateFromScriptPubKey(txout.ScriptPubKey);
if(template != null &&
(template.Type == TxOutType.TX_PUBKEY || template.Type == TxOutType.TX_MULTISIG))
Insert(new OutPoint(hash, i));
}
break;
}
}
}
if(fFound)
return true;
foreach(TxIn txin in tx.Inputs)
{
// Match if the filter contains an outpoint tx spends
if(Contains(txin.PrevOut))
return true;
// Match if the filter contains any arbitrary script data element in any scriptSig in tx
foreach(Op op in txin.ScriptSig.ToOps())
{
if(op.PushData != null && op.PushData.Length != 0 && Contains(op.PushData))
return true;
}
}
return false;
}
示例8: BroadcastTransactionCore
internal void BroadcastTransactionCore(Transaction transaction)
{
if(transaction == null)
throw new ArgumentNullException("transaction");
var tx = new TransactionBroadcast();
tx.Transaction = transaction;
tx.State = BroadcastState.NotSent;
var hash = transaction.GetHash();
if(_HashToTransaction.TryAdd(hash, tx))
{
Announce(tx, hash);
}
}
示例9: BroadcastTransactionAsync
/// <summary>
/// Broadcast a transaction on the hub
/// </summary>
/// <param name="transaction">The transaction to broadcast</param>
/// <returns>The cause of the rejection or null</returns>
public Task<RejectPayload> BroadcastTransactionAsync(Transaction transaction)
{
if(transaction == null)
throw new ArgumentNullException("transaction");
TaskCompletionSource<RejectPayload> completion = new TaskCompletionSource<RejectPayload>();
var hash = transaction.GetHash();
if(BroadcastedTransaction.TryAdd(hash, transaction))
{
TransactionBroadcastedDelegate broadcasted = null;
TransactionRejectedDelegate rejected = null;
broadcasted = (t) =>
{
if(t.GetHash() == hash)
{
completion.SetResult(null);
TransactionRejected -= rejected;
TransactionBroadcasted -= broadcasted;
}
};
TransactionBroadcasted += broadcasted;
rejected = (t, r) =>
{
if(r.Hash == hash)
{
completion.SetResult(r);
TransactionRejected -= rejected;
TransactionBroadcasted -= broadcasted;
}
};
TransactionRejected += rejected;
OnBroadcastTransaction(transaction);
}
return completion.Task;
}
示例10: Put
public static void Put(this ITransactionRepository repo, Transaction tx)
{
repo.Put(tx.GetHash(), tx);
}
示例11: PutAsync
public static Task PutAsync(this ITransactionRepository repo, Transaction tx)
{
return repo.PutAsync(tx.GetHash(), tx);
}
示例12: Main
static void Main(string[] args)
{
var goldGuy = new BitcoinSecret("KyuzoVnpsqW529yzozkzP629wUDBsPmm4QEkh9iKnvw3Dy5JJiNg");
var silverGuy = new BitcoinSecret("L4KvjpqDtdGEn7Lw6HdDQjbg74MwWRrFZMQTgJozeHAKJw5rQ2Kn");
var firstPerson = new BitcoinSecret("5Jnw9Td7PaG6PWBrU7ZCfxyVXsHSsNxdZ9sg5dnZstcr12DLVbJ");
var secondPerson = new BitcoinSecret("5Jn4zJkzS2BWNu7AMRTdSJ6mS7JYfJg27oXKAichaRBbp97ZKks");
var exchangeEntity = new BitcoinSecret("5KA7FeABKmMKerWmkJzYM9FdoqScZEMVcS9u6wvT3EhgF5ZUWv5");
var bitcoinProviderEntity = new BitcoinSecret("5Jcz2A17aAt4bcQP5GEn6itt72JsLwrksNRVKqazy7n284b1bKj");
var issuanceCoinsTransaction = new Transaction()
{
Outputs =
{
new TxOut("1.0", goldGuy.PubKey),
new TxOut("1.0", silverGuy.PubKey),
new TxOut("1.0", firstPerson.PubKey),
new TxOut("1.0", secondPerson.PubKey),
}
};
IssuanceCoin[] issuanceCoins = issuanceCoinsTransaction
.Outputs
.Take(2)
.Select((o, i) => new Coin(new OutPoint(issuanceCoinsTransaction.GetHash(), i), o))
.Select(c => new IssuanceCoin(c))
.ToArray();
var goldIssuanceCoin = issuanceCoins[0];
var silverIssuanceCoin = issuanceCoins[1];
var firstPersonInitialCoin = new Coin(new OutPoint(issuanceCoinsTransaction, 2), issuanceCoinsTransaction.Outputs[2]);
var secondPersonInitialCoin = new Coin(new OutPoint(issuanceCoinsTransaction, 3), issuanceCoinsTransaction.Outputs[3]);
var goldId = goldIssuanceCoin.AssetId;
var silverId = silverIssuanceCoin.AssetId;
var txRepo = new NoSqlTransactionRepository();
txRepo.Put(issuanceCoinsTransaction.GetHash(), issuanceCoinsTransaction);
var ctxRepo = new NoSqlColoredTransactionRepository(txRepo);
TransactionBuilder txBuilder = new TransactionBuilder();
// Issuing gold to first person
// This happens in gold issuer client
Transaction tx = txBuilder
.AddKeys(goldGuy.PrivateKey)
.AddCoins(goldIssuanceCoin)
.IssueAsset(firstPerson.GetAddress(), new AssetMoney(goldId, 20))
.SetChange(goldGuy.GetAddress())
.BuildTransaction(true);
txRepo.Put(tx.GetHash(), tx);
var ctx = tx.GetColoredTransaction(ctxRepo);
var coloredCoins = ColoredCoin.Find(tx, ctx).ToArray();
ColoredCoin firstPersonGoldCoin = coloredCoins[0];
// Issuing silver to second person
// This happens in silver issuer client
txBuilder = new TransactionBuilder();
tx = txBuilder
.AddKeys(silverGuy.PrivateKey)
.AddCoins(silverIssuanceCoin)
.IssueAsset(secondPerson.GetAddress(), new AssetMoney(silverId, 30))
.SetChange(silverGuy.GetAddress())
.BuildTransaction(true);
txRepo.Put(tx.GetHash(), tx);
ctx = tx.GetColoredTransaction(ctxRepo);
coloredCoins = ColoredCoin.Find(tx, ctx).ToArray();
ColoredCoin secondPersonSilverCoin = coloredCoins[0];
// Sending first person gold to exchange
// This happens in first user client
var bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo);
txBuilder = new TransactionBuilder();
tx = txBuilder
.AddCoins(bitcoinProviderCoin)
.AddKeys(bitcoinProviderEntity.PrivateKey)
.AddCoins(firstPersonGoldCoin)
.AddKeys(firstPerson.PrivateKey)
.SendAssetToExchange(exchangeEntity.GetAddress(), new AssetMoney(goldId, 5))
.SetChange(firstPerson.PubKey)
.BuildTransaction(true);
txRepo.Put(tx.GetHash(), tx);
ctx = tx.GetColoredTransaction(ctxRepo);
coloredCoins = ColoredCoin.Find(tx, ctx).ToArray();
ColoredCoin firstPersonColoredCoinInExchange = coloredCoins[1];
// Creating the time-locked transaction which the first user can post to the
// network to claim his/her coin from exchange (it works if the exchange does not touch the coins
// This happens in exchange and the transaction is delivered to first user client
bitcoinProviderCoin = CreateTransactionFeeCoin(bitcoinProviderEntity.PubKey, txRepo);
txBuilder = new TransactionBuilder();
tx = txBuilder
.AddCoins(bitcoinProviderCoin)
.AddKeys(bitcoinProviderEntity.PrivateKey)
.AddCoins(firstPersonColoredCoinInExchange)
.AddKeys(firstPerson.PrivateKey)
//.........这里部分代码省略.........
示例13: OutPoint
public OutPoint(Transaction tx, int i)
: this(tx.GetHash(), i)
{
}
示例14: AddCoins
public TransactionBuilder AddCoins(Transaction transaction)
{
var txId = transaction.GetHash();
AddCoins(transaction.Outputs.Select((o, i) => new Coin(txId, (uint)i, o.Value, o.ScriptPubKey)).ToArray());
return this;
}
示例15: Create
public static MnemonicReference Create(ChainBase chain, Transaction transaction, Block block, int txOutIndex)
{
return Create(chain, transaction, block.Filter(transaction.GetHash()), txOutIndex);
}