当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.GetHash方法代码示例

本文整理汇总了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]);
     }
 }
开发者ID:royosherove,项目名称:NBitcoin,代码行数:8,代码来源:TxOutRepository.cs

示例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);
			}
		}
开发者ID:n1rvana,项目名称:NBitcoin,代码行数:12,代码来源:BroadcastTransactionBehavior.cs

示例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));
     }
 }
开发者ID:monkeysSuck,项目名称:BitcoinPlayground,代码行数:12,代码来源:Program.cs

示例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]);
 }
开发者ID:LykkeCity,项目名称:Prototypes,代码行数:13,代码来源:Program.cs

示例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);
        }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:37,代码来源:Wallet.cs

示例6: AddTransaction

 public void AddTransaction(Transaction tx, int height)
 {
     SetCoins(tx.GetHash(), new Coins(tx, height));
 }
开发者ID:nikropht,项目名称:NBitcoin,代码行数:4,代码来源:CoinsView.cs

示例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;
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:59,代码来源:BloomFilter.cs

示例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);
			}
		}
开发者ID:n1rvana,项目名称:NBitcoin,代码行数:13,代码来源:BroadcastTransactionBehavior.cs

示例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;
		}
开发者ID:n1rvana,项目名称:NBitcoin,代码行数:40,代码来源:BroadcastTransactionBehavior.cs

示例10: Put

		public static void Put(this ITransactionRepository repo, Transaction tx)
		{
			repo.Put(tx.GetHash(), tx);
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:4,代码来源:ITransactionRepository.cs

示例11: PutAsync

		public static Task PutAsync(this ITransactionRepository repo, Transaction tx)
		{
			return repo.PutAsync(tx.GetHash(), tx);
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:4,代码来源:ITransactionRepository.cs

示例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)
//.........这里部分代码省略.........
开发者ID:LykkeCity,项目名称:Prototypes,代码行数:101,代码来源:Program.cs

示例13: OutPoint

 public OutPoint(Transaction tx, int i)
     : this(tx.GetHash(), i)
 {
 }
开发者ID:royosherove,项目名称:NBitcoin,代码行数:4,代码来源:Transaction.cs

示例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;
		}
开发者ID:crowar,项目名称:NBitcoin,代码行数:6,代码来源:TransactionBuilder.cs

示例15: Create

		public static MnemonicReference Create(ChainBase chain, Transaction transaction, Block block, int txOutIndex)
		{
			return Create(chain, transaction, block.Filter(transaction.GetHash()), txOutIndex);
		}
开发者ID:woutersmit,项目名称:NBitcoin,代码行数:4,代码来源:MnemonicReference.cs


注:本文中的NBitcoin.Transaction.GetHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。