@@ -549,21 +549,23 @@ func (api *BlockChainAPI) GetUncleByBlockHashAndIndex(ctx context.Context, block
549549}
550550
551551// GetUncleCountByBlockNumber returns number of uncles in the block for the given block number
552- func (api * BlockChainAPI ) GetUncleCountByBlockNumber (ctx context.Context , blockNr rpc.BlockNumber ) * hexutil.Uint {
553- if block , _ := api .b .BlockByNumber (ctx , blockNr ); block != nil {
552+ func (api * BlockChainAPI ) GetUncleCountByBlockNumber (ctx context.Context , blockNr rpc.BlockNumber ) (* hexutil.Uint , error ) {
553+ block , err := api .b .BlockByNumber (ctx , blockNr )
554+ if block != nil {
554555 n := hexutil .Uint (len (block .Uncles ()))
555- return & n
556+ return & n , nil
556557 }
557- return nil
558+ return nil , err
558559}
559560
560561// GetUncleCountByBlockHash returns number of uncles in the block for the given block hash
561- func (api * BlockChainAPI ) GetUncleCountByBlockHash (ctx context.Context , blockHash common.Hash ) * hexutil.Uint {
562- if block , _ := api .b .BlockByHash (ctx , blockHash ); block != nil {
562+ func (api * BlockChainAPI ) GetUncleCountByBlockHash (ctx context.Context , blockHash common.Hash ) (* hexutil.Uint , error ) {
563+ block , err := api .b .BlockByHash (ctx , blockHash )
564+ if block != nil {
563565 n := hexutil .Uint (len (block .Uncles ()))
564- return & n
566+ return & n , nil
565567 }
566- return nil
568+ return nil , err
567569}
568570
569571// GetCode returns the code stored at the given address in the state for the given block number.
@@ -596,9 +598,7 @@ func (api *BlockChainAPI) GetStorageAt(ctx context.Context, address common.Addre
596598func (api * BlockChainAPI ) GetBlockReceipts (ctx context.Context , blockNrOrHash rpc.BlockNumberOrHash ) ([]map [string ]interface {}, error ) {
597599 block , err := api .b .BlockByNumberOrHash (ctx , blockNrOrHash )
598600 if block == nil || err != nil {
599- // When the block doesn't exist, the RPC method should return JSON null
600- // as per specification.
601- return nil , nil
601+ return nil , err
602602 }
603603 receipts , err := api .b .GetReceipts (ctx , block .Hash ())
604604 if err != nil {
@@ -1258,37 +1258,41 @@ func NewTransactionAPI(b Backend, nonceLock *AddrLocker) *TransactionAPI {
12581258}
12591259
12601260// GetBlockTransactionCountByNumber returns the number of transactions in the block with the given block number.
1261- func (api * TransactionAPI ) GetBlockTransactionCountByNumber (ctx context.Context , blockNr rpc.BlockNumber ) * hexutil.Uint {
1262- if block , _ := api .b .BlockByNumber (ctx , blockNr ); block != nil {
1261+ func (api * TransactionAPI ) GetBlockTransactionCountByNumber (ctx context.Context , blockNr rpc.BlockNumber ) (* hexutil.Uint , error ) {
1262+ block , err := api .b .BlockByNumber (ctx , blockNr )
1263+ if block != nil {
12631264 n := hexutil .Uint (len (block .Transactions ()))
1264- return & n
1265+ return & n , nil
12651266 }
1266- return nil
1267+ return nil , err
12671268}
12681269
12691270// GetBlockTransactionCountByHash returns the number of transactions in the block with the given hash.
1270- func (api * TransactionAPI ) GetBlockTransactionCountByHash (ctx context.Context , blockHash common.Hash ) * hexutil.Uint {
1271- if block , _ := api .b .BlockByHash (ctx , blockHash ); block != nil {
1271+ func (api * TransactionAPI ) GetBlockTransactionCountByHash (ctx context.Context , blockHash common.Hash ) (* hexutil.Uint , error ) {
1272+ block , err := api .b .BlockByHash (ctx , blockHash )
1273+ if block != nil {
12721274 n := hexutil .Uint (len (block .Transactions ()))
1273- return & n
1275+ return & n , nil
12741276 }
1275- return nil
1277+ return nil , err
12761278}
12771279
12781280// GetTransactionByBlockNumberAndIndex returns the transaction for the given block number and index.
1279- func (api * TransactionAPI ) GetTransactionByBlockNumberAndIndex (ctx context.Context , blockNr rpc.BlockNumber , index hexutil.Uint ) * RPCTransaction {
1280- if block , _ := api .b .BlockByNumber (ctx , blockNr ); block != nil {
1281- return newRPCTransactionFromBlockIndex (block , uint64 (index ), api .b .ChainConfig ())
1281+ func (api * TransactionAPI ) GetTransactionByBlockNumberAndIndex (ctx context.Context , blockNr rpc.BlockNumber , index hexutil.Uint ) (* RPCTransaction , error ) {
1282+ block , err := api .b .BlockByNumber (ctx , blockNr )
1283+ if block != nil {
1284+ return newRPCTransactionFromBlockIndex (block , uint64 (index ), api .b .ChainConfig ()), nil
12821285 }
1283- return nil
1286+ return nil , err
12841287}
12851288
12861289// GetTransactionByBlockHashAndIndex returns the transaction for the given block hash and index.
1287- func (api * TransactionAPI ) GetTransactionByBlockHashAndIndex (ctx context.Context , blockHash common.Hash , index hexutil.Uint ) * RPCTransaction {
1288- if block , _ := api .b .BlockByHash (ctx , blockHash ); block != nil {
1289- return newRPCTransactionFromBlockIndex (block , uint64 (index ), api .b .ChainConfig ())
1290+ func (api * TransactionAPI ) GetTransactionByBlockHashAndIndex (ctx context.Context , blockHash common.Hash , index hexutil.Uint ) (* RPCTransaction , error ) {
1291+ block , err := api .b .BlockByHash (ctx , blockHash )
1292+ if block != nil {
1293+ return newRPCTransactionFromBlockIndex (block , uint64 (index ), api .b .ChainConfig ()), nil
12901294 }
1291- return nil
1295+ return nil , err
12921296}
12931297
12941298// GetRawTransactionByBlockNumberAndIndex returns the bytes of the transaction for the given block number and index.
0 commit comments