public static Block GetBlock(this IBlockchainBridge blockchainBridge, BlockParameter blockParameter, bool allowNulls = false, bool recoverTxSenders = false) { Block block; switch (blockParameter.Type) { case BlockParameterType.Pending: { block = blockchainBridge.FindPendingBlock(); break; } case BlockParameterType.Latest: { block = blockchainBridge.FindLatestBlock(); break; } case BlockParameterType.Earliest: { block = blockchainBridge.FindEarliestBlock(); break; } case BlockParameterType.BlockId: { if (blockParameter.BlockId == null) { throw new JsonRpcException(ErrorType.InvalidParams, $"Block number is required for {BlockParameterType.BlockId}"); } block = blockchainBridge.FindBlock(blockParameter.BlockId.Value); break; } default: throw new Exception($"{nameof(BlockParameterType)} not supported: {blockParameter.Type}"); } if (block == null && !allowNulls) { throw new JsonRpcException(ErrorType.NotFound, $"Cannot find block {blockParameter}"); } if (block != null && recoverTxSenders) { blockchainBridge.RecoverTxSenders(block); } return(block); }