/// <inheritdoc /> public async Task <List <IMaturedBlockDeposits> > GetMaturedDepositsAsync(int blockHeight, int maxBlocks) { int matureHeight = (this.chain.Tip.Height - (int)this.depositExtractor.MinimumDepositConfirmations); if (blockHeight > matureHeight) { throw new InvalidOperationException($"Block height {blockHeight} submitted is not mature enough. Blocks less than a height of {matureHeight} can be processed."); } List <ChainedHeader> chainedHeaders = await this.GetChainedHeadersAsync(blockHeight, Math.Min(maxBlocks, matureHeight - blockHeight + 1)); if (chainedHeaders.Count == 0) { throw new InvalidOperationException($"Block with height {blockHeight} was not found on the block chain."); } var maturedBlocks = new List <IMaturedBlockDeposits>(); for (int index = 0; index < chainedHeaders.Count; index++) { IMaturedBlockDeposits maturedBlockDeposits = this.depositExtractor.ExtractBlockDeposits(chainedHeaders[index]); if (maturedBlockDeposits == null) { throw new InvalidOperationException($"Unable to get deposits for block at height {chainedHeaders[index].Height}"); } maturedBlocks.Add(maturedBlockDeposits); } return(maturedBlocks); }
/// <inheritdoc /> public async Task SendMaturedBlockDepositsAsync(IMaturedBlockDeposits maturedBlockDeposits) { if (this.CanSend()) { await this.SendAsync((MaturedBlockDepositsModel)maturedBlockDeposits, FederationGatewayRouteEndPoint.ReceiveMaturedBlocks).ConfigureAwait(false); } }
/// <summary> /// When a block is received it is passed to the monitor. /// </summary> /// <param name="chainedHeaderBlock">The new block.</param> protected override void OnNextCore(ChainedHeaderBlock chainedHeaderBlock) { this.walletSyncManager.ProcessBlock(chainedHeaderBlock.Block); this.blockTipSender.SendBlockTipAsync( new BlockTipModel( chainedHeaderBlock.ChainedHeader.HashBlock, chainedHeaderBlock.ChainedHeader.Height, (int)this.depositExtractor.MinimumDepositConfirmations)).ConfigureAwait(false).GetAwaiter().GetResult(); IReadOnlyList <IWithdrawal> withdrawals = this.withdrawalExtractor.ExtractWithdrawalsFromBlock( chainedHeaderBlock.Block, chainedHeaderBlock.ChainedHeader.Height); this.withdrawalReceiver.ReceiveWithdrawals(withdrawals); IMaturedBlockDeposits maturedBlockDeposits = this.maturedBlocksProvider.ExtractMaturedBlockDeposits(chainedHeaderBlock.ChainedHeader); if (maturedBlockDeposits == null) { return; } this.maturedBlockSender.SendMaturedBlockDepositsAsync(maturedBlockDeposits).ConfigureAwait(false).GetAwaiter().GetResult(); }
public void ShouldSerialiseAsJson() { IMaturedBlockDeposits maturedBlockDeposits = TestingValues.GetMaturedBlockDeposits(3); string asJson = maturedBlockDeposits.ToString(); var reconverted = JsonConvert.DeserializeObject<MaturedBlockDepositsModel>(asJson); reconverted.Block.BlockHash.Should().Be(maturedBlockDeposits.Block.BlockHash); reconverted.Block.BlockHeight.Should().Be(maturedBlockDeposits.Block.BlockHeight); reconverted.Deposits.Should().BeEquivalentTo(maturedBlockDeposits.Deposits); }
public async Task SendMaturedBlockDeposits_Should_Log_Error_When_Failing_To_Send_MaturedBlockDepositAsync() { TestingHttpClient.PrepareFailingHttpClient(ref this.messageHandler, ref this.httpClient, ref this.httpClientFactory); IMaturedBlockDeposits maturedBlockDeposits = TestingValues.GetMaturedBlockDeposits(); var restSender = new RestMaturedBlockSender(this.loggerFactory, this.federationSettings, this.httpClientFactory); await restSender.SendMaturedBlockDepositsAsync(maturedBlockDeposits).ConfigureAwait(false); this.logger.Received(1).Log <object>(LogLevel.Error, 0, Arg.Any <object>(), Arg.Is <Exception>(e => e == null), Arg.Any <Func <object, Exception, string> >()); }