System.Collections.Generic.Dictionary.Remove(uint256)

Here are the examples of the csharp api System.Collections.Generic.Dictionary.Remove(uint256) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 Source : TransactionStore.cs
with GNU General Public License v3.0
from chaincase-app

public bool TryRemove(uint256 hash, out SmartTransaction stx)
		{
			bool isRemoved;

			lock (TransactionsLock)
			{
				isRemoved = Transactions.Remove(hash, out stx);
			}

			if (isRemoved)
			{
				_ = TryRemoveFromFileAsync(hash);
			}

			return isRemoved;
		}

19 Source : BlockchainController.cs
with GNU General Public License v3.0
from chaincase-app

[HttpGet("transaction-hexes")]
		[ProducesResponseType(200)]
		[ProducesResponseType(400)]
		public async Task<IActionResult> GetTransactionsAsync([FromQuery, Required] IEnumerable<string> transactionIds)
		{
			if (!ModelState.IsValid)
			{
				return BadRequest("Invalid transaction Ids.");
			}

			var maxTxToRequest = 10;
			if (transactionIds.Count() > maxTxToRequest)
			{
				return BadRequest($"Maximum {maxTxToRequest} transactions can be requested.");
			}

			var parsedIds = new List<uint256>();
			try
			{
				// Remove duplicates, do not use Distinct(), order is not guaranteed.
				foreach (var txid in transactionIds.Select(x => new uint256(x)))
				{
					if (!parsedIds.Contains(txid))
					{
						parsedIds.Add(txid);
					}
				}
			}
			catch
			{
				return BadRequest("Invalid transaction Ids.");
			}

			try
			{
				var hexes = new Dictionary<uint256, string>();
				var queryRpc = false;
				IRPCClient batchingRpc = null;
				List<Task<Transaction>> tasks = null;
				lock (TransactionHexCacheLock)
				{
					foreach (var txid in parsedIds)
					{
						if (TransactionHexCache.TryGetValue(txid, out string hex))
						{
							hexes.Add(txid, hex);
						}
						else
						{
							if (!queryRpc)
							{
								queryRpc = true;
								batchingRpc = RpcClient.PrepareBatch();
								tasks = new List<Task<Transaction>>();
							}
							tasks.Add(batchingRpc.GetRawTransactionAsync(txid));
						}
					}
				}

				if (queryRpc)
				{
					await batchingRpc.SendBatchAsync();

					foreach (var tx in await Task.WhenAll(tasks))
					{
						string hex = tx.ToHex();
						hexes.Add(tx.GetHash(), hex);

						lock (TransactionHexCacheLock)
						{
							if (TransactionHexCache.TryAdd(tx.GetHash(), hex) && TransactionHexCache.Count >= 1000)
							{
								TransactionHexCache.Remove(TransactionHexCache.Keys.First());
							}
						}
					}
				}

				// Order hexes according to the order of the query.
				var orderedResult = parsedIds.Where(x => hexes.ContainsKey(x)).Select(x => hexes[x]);
				return Ok(orderedResult);
			}
			catch (Exception ex)
			{
				Logger.LogDebug(ex);
				return BadRequest(ex.Message);
			}
		}

19 Source : BlockDownloader.cs
with MIT License
from dgarage

internal async IAsyncEnumerable<Block> DownloadBlocks(BlockLocator fork, [EnumeratorCancellation] CancellationToken cancellationToken)
		{
			foreach (var hashes in EnumerateToTip(fork, chain).Select(c => c.Hash).Batch(maxinflight))
			{
				Dictionary<uint256, Block> outoforder = new Dictionary<uint256, Block>();
				var hashesEnum = hashes.GetEnumerator();
				if (!hashesEnum.MoveNext())
					yield break;
				await node.SendMessageAsync(new GetDataPayload(hashes.Select(h => new InventoryVector(node.AddSupportedOptions(InventoryType.MSG_BLOCK), h)).ToArray()));

				
				await foreach (var block in blocks.Reader.ReadAllAsync(cancellationToken))
				{
					var blockHash = block.Header.GetHash();
					if (blockHash == hashesEnum.Current)
					{
						yield return block;
						if (!hashesEnum.MoveNext())
							break;
						while (outoforder.TryGetValue(hashesEnum.Current, out var block2))
						{
							yield return block2;
							outoforder.Remove(hashesEnum.Current);
							if (!hashesEnum.MoveNext())
								break;
						}
					}
					else
					{
						outoforder.TryAdd(blockHash, block);
					}
				}
			}

			
		}