Beispiel #1
0
        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);
        }
Beispiel #2
0
        public virtual BlockStake Get(uint256 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);
            }

            var stakeItem = new StakeItem {
                BlockId = blockid
            };

            this.dBreezeCoinView.GetStake(new[] { stakeItem });

            Guard.Assert(stakeItem.BlockStake != null); // if we ask for it then we expect its in store
            return(stakeItem.BlockStake);
        }
Beispiel #3
0
        public async Task <BlockStake> GetAsync(uint256 blockid)
        {
            var stakeItem = new StakeItem {
                BlockId = blockid
            };

            await this.dBreezeCoinView.GetStakeAsync(new[] { stakeItem }).ConfigureAwait(false);

            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)
        {
            if (this.items.ContainsKey(chainedBlock.HashBlock))
            {
                return;
            }

            //var chainedBlock = this.chain.GetBlock(blockid);
            var item = new StakeItem {
                BlockId = chainedBlock.HashBlock, Height = chainedBlock.Height, BlockStake = blockStake, InStore = false
            };
            var added = this.items.TryAdd(chainedBlock.HashBlock, item);

            if (added)
            {
                await this.Flush(false);
            }
        }
Beispiel #5
0
        public void Set(ChainedHeader chainedHeader, BlockStake blockStake)
        {
            if (this.items.ContainsKey(chainedHeader.HashBlock))
            {
                this.logger.LogTrace("(-)[ALREADY_EXISTS]");
                return;
            }

            //var chainedHeader = this.chain.GetBlock(blockid);
            var item = new StakeItem {
                BlockId = chainedHeader.HashBlock, Height = chainedHeader.Height, BlockStake = blockStake, InStore = false
            };
            bool added = this.items.TryAdd(chainedHeader.HashBlock, item);

            if (added)
            {
                this.Flush(false);
            }
        }
        public async Task <BlockStake> GetAsync(uint256 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(ChainedHeader chainedHeader, BlockStake blockStake)
        {
            this.logger.LogTrace("({0}:'{1}',{2}.{3}:'{4}')", nameof(chainedHeader), chainedHeader, nameof(blockStake), nameof(blockStake.HashProof), blockStake.HashProof);

            if (this.items.ContainsKey(chainedHeader.HashBlock))
            {
                this.logger.LogTrace("(-)[ALREADY_EXISTS]");
                return;
            }

            //var chainedHeader = this.chain.GetBlock(blockid);
            var item = new StakeItem {
                BlockId = chainedHeader.HashBlock, Height = chainedHeader.Height, BlockStake = blockStake, InStore = false
            };
            bool added = this.items.TryAdd(chainedHeader.HashBlock, item);

            if (added)
            {
                await this.FlushAsync(false).ConfigureAwait(false);
            }

            this.logger.LogTrace("(-)");
        }