private ResultWrapper <Core.Block> GetBlock(BlockParameter blockParameter, bool allowNulls = false) { switch (blockParameter.Type) { case BlockParameterType.Pending: var pending = _blockchainBridge.FindBlock(_blockchainBridge.BestSuggested.Hash, false); return(ResultWrapper <Block> .Success(pending)); // TODO: a pending block for sealEngine, work in progress case BlockParameterType.Latest: return(ResultWrapper <Block> .Success(_blockchainBridge.RetrieveHeadBlock())); case BlockParameterType.Earliest: var genesis = _blockchainBridge.RetrieveGenesisBlock(); return(ResultWrapper <Block> .Success(genesis)); case BlockParameterType.BlockId: if (blockParameter.BlockId == null) { return(ResultWrapper <Block> .Fail($"Block number is required for {BlockParameterType.BlockId}", ErrorType.InvalidParams)); } Block block = _blockchainBridge.FindBlock(blockParameter.BlockId.Value); if (block == null && !allowNulls) { return(ResultWrapper <Block> .Fail($"Cannot find block {blockParameter.BlockId.Value}", ErrorType.NotFound)); } return(ResultWrapper <Block> .Success(block)); default: throw new Exception($"{nameof(BlockParameterType)} not supported: {blockParameter.Type}"); } }
private ResultWrapper <Core.Block> GetBlock(BlockParameter blockParameter) { switch (blockParameter.Type) { case BlockParameterType.Pending: var pending = _blockchainBridge.FindBlock(_blockchainBridge.BestSuggested.Hash, false); return(ResultWrapper <Core.Block> .Success(pending)); // TODO: a pending block for sealEngine, work in progress case BlockParameterType.Latest: return(ResultWrapper <Core.Block> .Success(_blockchainBridge.RetrieveHeadBlock())); case BlockParameterType.Earliest: var genesis = _blockchainBridge.RetrieveGenesisBlock(); return(ResultWrapper <Core.Block> .Success(genesis)); case BlockParameterType.BlockId: if (blockParameter.BlockId?.Value == null) { return(ResultWrapper <Core.Block> .Fail($"Block id is required for {BlockParameterType.BlockId}", ErrorType.InvalidParams)); } var value = blockParameter.BlockId.AsNumber(); if (!value.HasValue) { return(ResultWrapper <Core.Block> .Fail("Invalid block id", ErrorType.InvalidParams)); } var block = _blockchainBridge.FindBlock(new UInt256(value.Value)); if (block == null) { return(ResultWrapper <Core.Block> .Fail($"Cannot find block for {value.Value}", ErrorType.NotFound)); } return(ResultWrapper <Core.Block> .Success(block)); default: throw new Exception($"BlockParameterType not supported: {blockParameter.Type}"); } }
private ResultWrapper <Core.Block> GetBlock(BlockParameter blockParameter) { switch (blockParameter.Type) { case BlockParameterType.Pending: var pending = _blockchainBridge.FindBlock(_blockchainBridge.BestSuggested.Hash, false); return(ResultWrapper <Core.Block> .Success(pending)); // TODO: a pending block for sealEngine, work in progress case BlockParameterType.Latest: return(ResultWrapper <Core.Block> .Success(_blockchainBridge.RetrieveHeadBlock())); case BlockParameterType.Earliest: var genesis = _blockchainBridge.RetrieveGenesisBlock(); return(ResultWrapper <Core.Block> .Success(genesis)); case BlockParameterType.BlockId: if (blockParameter.BlockId?.Value == null) { return(ResultWrapper <Core.Block> .Fail($"Block id is required for {BlockParameterType.BlockId}", ErrorType.InvalidParams)); } var value = blockParameter.BlockId.GetValue(); if (!value.HasValue) { return(ResultWrapper <Core.Block> .Fail("Invalid block id", ErrorType.InvalidParams)); } throw new NotImplementedException(); // TODO: TKS - discuss with me later, there was a rebuilt of BlockStore / Blockchain, work in progress now, so just commenting it out // var block = _blockTree.FindBlock(value.Value); // if (block == null) // { // return ResultWrapper<Core.Block>.Fail($"Cannot find block for {value.Value}", ErrorType.NotFound); // } // return ResultWrapper<Core.Block>.Success(block); default: throw new Exception($"BlockParameterType not supported: {blockParameter.Type}"); } }