private async Task <bool> WarmupBlockchain() { if (await _RPCWithTimeout.GetBlockCountAsync() < _Network.NBitcoinNetwork.Consensus.CoinbaseMaturity) { Logs.Configuration.LogInformation($"{_Network.CryptoCode}: Less than {_Network.NBitcoinNetwork.Consensus.CoinbaseMaturity} blocks, mining some block for regtest"); await _RPCWithTimeout.EnsureGenerateAsync(_Network.NBitcoinNetwork.Consensus.CoinbaseMaturity + 1); return(true); } else { var hash = await _RPCWithTimeout.GetBestBlockHashAsync(); BlockHeader header = null; try { header = await _RPCWithTimeout.GetBlockHeaderAsync(hash); } catch (RPCException ex) when(ex.RPCCode == RPCErrorCode.RPC_METHOD_NOT_FOUND) { header = (await _RPCWithTimeout.GetBlockAsync(hash)).Header; } if ((DateTimeOffset.UtcNow - header.BlockTime) > TimeSpan.FromSeconds(24 * 60 * 60)) { Logs.Configuration.LogInformation($"{_Network.CryptoCode}: It has been a while nothing got mined on regtest... mining 10 blocks"); await _RPCWithTimeout.GenerateAsync(10); return(true); } return(false); } }
public static uint256[] EnsureGenerate(this RPCClient client, int blockCount) { return(client.EnsureGenerateAsync(blockCount).GetAwaiter().GetResult()); }