コード例 #1
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.stakdb.GetStake(new[] { stakeItem });

            Guard.Assert(stakeItem.BlockStake != null); // if we ask for it then we expect its in store
            return(stakeItem.BlockStake);
        }
コード例 #2
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);
            }
        }