Пример #1
0
        /// <summary>
        /// Given a block, enters the initialization state for handling a block.
        /// </summary>
        /// <param name="state">The state to set.</param>
        /// <param name="block">The block which will be processed.</param>
        public override void Initialize(State.State state, Block.Block block)
        {
            // We enter our initialization state
            state.BlockGasUsed = 0;
            state.Bloom        = 0;
            state.TransactionReceipts.Clear();

            // Set our current block
            state.UpdateCurrentBlock(block);

            // TODO: Handle DAO fork transfer
        }
Пример #2
0
        /// <summary>
        /// Obtains a State instance that represents the state after the block with the given hash was processed.
        /// </summary>
        /// <param name="blockHash">The hash of the block to obtain post-processed state of.</param>
        /// <returns>Returns a State instance that represents the state after the block with the given hash was processed.</returns>
        public State.State GetPostBlockState(byte[] blockHash)
        {
            // Obtain the block.
            Block.Block block = GetBlock(blockHash);
            if (block == null)
            {
                return(null);
            }

            // Otherwise we obtain the state with the block's given state root hash and set the current block.
            State.State state = new State.State(Configuration, block.Header.StateRootHash);
            state.UpdateCurrentBlock(block);
            state.BlockGasUsed = block.Header.GasUsed;

            // We'll want to populate our previous block hashes for this state (and one for this block)
            Block.Block currentBlock = block;
            for (int i = 0; i < Configuration.PreviousHashDepth + 1; i++)
            {
                // Add our previous header
                state.PreviousHeaders.Add(currentBlock.Header);

                // If our index is less than our max uncle depth, we add our uncles
                if (i < Configuration.MaxUncleDepth)
                {
                    state.UpdateUncleHashes(currentBlock);
                }

                // Iterate to the previous block.
                currentBlock = GetParentBlock(currentBlock);
                if (currentBlock == null)
                {
                    break;
                }
            }

            return(state);
        }