Here are the examples of the csharp api System.Collections.Generic.List.Contains(uint256) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
4 Examples
19
Source : BlockNotifier.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
protected override async Task ActionAsync(CancellationToken cancel)
{
uint256 bestBlockHash;
uint256 lastInv;
lock (LastInvLock)
{
lastInv = LastInv;
}
// If we did not yet process our last inv, then we can take this as the best known block hash, so we don't need the RPC command.
// Otherwise make the RPC command.
if (lastInv is { } && !ProcessedBlocks.Contains(lastInv))
{
bestBlockHash = lastInv;
}
else
{
bestBlockHash = await RpcClient.GetBestBlockHashAsync().ConfigureAwait(false);
}
// If there's no new block.
if (bestBlockHash == BestBlockHash)
{
return;
}
var arrivedBlock = await RpcClient.GetBlockAsync(bestBlockHash).ConfigureAwait(false);
var arrivedHeader = arrivedBlock.Header;
arrivedHeader.PrecomputeHash(false, true);
// If we haven't processed any block yet then we're processing the first seven to avoid accidental reogs.
// 7 blocks, because
// - That was the largest recorded reorg so far.
// - Reorg in this point of time would be very unlikely anyway.
// - 100 blocks would be the sure, but that'd be a huge performance overkill.
if (!ProcessedBlocks.Any())
{
var reorgProtection7Headers = new List<BlockHeader>()
{
arrivedHeader
};
var currentHeader = arrivedHeader;
while (reorgProtection7Headers.Count < 7 && currentHeader.GetHash() != Network.GenesisHash)
{
currentHeader = await RpcClient.GetBlockHeaderAsync(currentHeader.HashPrevBlock).ConfigureAwait(false);
reorgProtection7Headers.Add(currentHeader);
}
reorgProtection7Headers.Reverse();
foreach (var header in reorgProtection7Headers)
{
// It's initialization. Don't notify about it.
AddHeader(header);
}
BestBlockHash = bestBlockHash;
return;
}
// If block was already processed return.
if (ProcessedBlocks.Contains(arrivedHeader.GetHash()))
{
BestBlockHash = bestBlockHash;
return;
}
// If this block follows the proper order then add.
if (ProcessedBlocks.Last() == arrivedHeader.HashPrevBlock)
{
AddBlock(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
// Else let's sort out things.
var foundPrevBlock = ProcessedBlocks.FirstOrDefault(x => x == arrivedHeader.HashPrevBlock);
// Missed notifications on some previous blocks.
if (foundPrevBlock != null)
{
// Reorg happened.
ReorgToBlock(foundPrevBlock);
AddBlock(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
await HandleMissedBlocksAsync(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
19
Source : BlockNotifier.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
protected override async Task ActionAsync(CancellationToken cancel)
{
uint256 bestBlockHash;
uint256 lastInv;
lock (LastInvLock)
{
lastInv = LastInv;
}
// If we did not yet process our last inv, then we can take this as the best known block hash, so we don't need the RPC command.
// Otherwise make the RPC command.
if (lastInv is { } && !ProcessedBlocks.Contains(lastInv))
{
bestBlockHash = lastInv;
}
else
{
bestBlockHash = await RpcClient.GetBestBlockHashAsync().ConfigureAwait(false);
}
// If there's no new block.
if (bestBlockHash == BestBlockHash)
{
return;
}
var arrivedBlock = await RpcClient.GetBlockAsync(bestBlockHash).ConfigureAwait(false);
var arrivedHeader = arrivedBlock.Header;
arrivedHeader.PrecomputeHash(false, true);
// If we haven't processed any block yet then we're processing the first seven to avoid accidental reogs.
// 7 blocks, because
// - That was the largest recorded reorg so far.
// - Reorg in this point of time would be very unlikely anyway.
// - 100 blocks would be the sure, but that'd be a huge performance overkill.
if (!ProcessedBlocks.Any())
{
var reorgProtection7Headers = new List<BlockHeader>()
{
arrivedHeader
};
var currentHeader = arrivedHeader;
while (reorgProtection7Headers.Count < 7 && currentHeader.GetHash() != Network.GenesisHash)
{
currentHeader = await RpcClient.GetBlockHeaderAsync(currentHeader.HashPrevBlock).ConfigureAwait(false);
reorgProtection7Headers.Add(currentHeader);
}
reorgProtection7Headers.Reverse();
foreach (var header in reorgProtection7Headers)
{
// It's initialization. Don't notify about it.
AddHeader(header);
}
BestBlockHash = bestBlockHash;
return;
}
// If block was already processed return.
if (ProcessedBlocks.Contains(arrivedHeader.GetHash()))
{
BestBlockHash = bestBlockHash;
return;
}
// If this block follows the proper order then add.
if (ProcessedBlocks.Last() == arrivedHeader.HashPrevBlock)
{
AddBlock(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
// Else let's sort out things.
var foundPrevBlock = ProcessedBlocks.FirstOrDefault(x => x == arrivedHeader.HashPrevBlock);
// Missed notifications on some previous blocks.
if (foundPrevBlock != null)
{
// Reorg happened.
ReorgToBlock(foundPrevBlock);
AddBlock(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
await HandleMissedBlocksAsync(arrivedBlock);
BestBlockHash = bestBlockHash;
return;
}
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);
}
}
19
Source : Coordinator.cs
with GNU General Public License v3.0
from chaincase-app
with GNU General Public License v3.0
from chaincase-app
public async Task<bool> ContainsUnconfirmedCoinJoinAsync(uint256 hash)
{
using (await CoinJoinsLock.LockAsync().ConfigureAwait(false))
{
return UnconfirmedCoinJoins.Contains(hash);
}
}