Here are the examples of the csharp api System.Collections.Generic.Dictionary.ContainsKey(uint256) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
19
Source : TransactionStore.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
public bool Contains(uint256 hash)
{
lock (TransactionsLock)
{
return Transactions.ContainsKey(hash);
}
}
19
Source : BlockchainController.cs
with GNU General Public License v3.0
from chaincase-app
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);
}
}