public override BlockStake Get(uint256 blockid) { this.logger.LogTrace("({0}:'{1}')", nameof(blockid), blockid); if (this.network.GenesisHash == blockid) { this.logger.LogTrace("(-)[GENESIS]:*.{0}='{1}'", nameof(this.genesis.HashProof), this.genesis.HashProof); return(this.genesis); } StakeItem block = this.items.TryGet(blockid); if (block != null) { this.logger.LogTrace("(-)[LOADED]:*.{0}='{1}'", nameof(block.BlockStake.HashProof), block.BlockStake.HashProof); return(block.BlockStake); } BlockStake res = this.GetAsync(blockid).GetAwaiter().GetResult(); if (res != null) { this.logger.LogTrace("(-):*.{0}='{1}'", nameof(res.HashProof), res.HashProof); } else { this.logger.LogTrace("(-):null"); } return(res); }
public async Task <BlockStake> GetAsync(uint256 blockid) { this.logger.LogTrace("({0}:'{1}')", nameof(blockid), blockid); var stakeItem = new StakeItem { BlockId = blockid }; await this.dBreezeCoinView.GetStakeAsync(new[] { stakeItem }).ConfigureAwait(false); if (stakeItem.BlockStake != null) { this.logger.LogTrace("(-):*.{0}='{1}'", nameof(stakeItem.BlockStake.HashProof), stakeItem.BlockStake.HashProof); } else { this.logger.LogTrace("(-):null"); } Guard.Assert(stakeItem.BlockStake != null); // if we ask for it then we expect its in store return(stakeItem.BlockStake); }
public async Task SetAsync(ChainedBlock chainedBlock, BlockStake blockStake) { this.logger.LogTrace("({0}:'{1}',{2}.{3}:'{4}')", nameof(chainedBlock), chainedBlock, nameof(blockStake), nameof(blockStake.HashProof), blockStake.HashProof); if (this.items.ContainsKey(chainedBlock.HashBlock)) { this.logger.LogTrace("(-)[ALREADY_EXISTS]"); return; } //var chainedBlock = this.chain.GetBlock(blockid); StakeItem item = new StakeItem { BlockId = chainedBlock.HashBlock, Height = chainedBlock.Height, BlockStake = blockStake, InStore = false }; bool added = this.items.TryAdd(chainedBlock.HashBlock, item); if (added) { await this.FlushAsync(false).ConfigureAwait(false); } this.logger.LogTrace("(-)"); }