From 876ce0fb12d7c1eae2907dad9ea13d01e9b3ac17 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Thu, 2 Apr 2015 14:54:28 +0200 Subject: [PATCH] More nil checks --- rpc/api.go | 6 ++++++ rpc/responses.go | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index ee2a6a0473..b46151cda4 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -212,6 +212,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByHash(args.Hash) br := NewBlockRes(block, true) + if br == nil { + *reply = nil + } if args.Index >= int64(len(br.Transactions)) || args.Index < 0 { return NewValidationError("Index", "does not exist") @@ -225,6 +228,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err block := api.xeth().EthBlockByNumber(args.BlockNumber) v := NewBlockRes(block, true) + if v == nil { + *reply = nil + } if args.Index >= int64(len(v.Transactions)) || args.Index < 0 { return NewValidationError("Index", "does not exist") diff --git a/rpc/responses.go b/rpc/responses.go index 3d1687cb68..079ee87655 100644 --- a/rpc/responses.go +++ b/rpc/responses.go @@ -125,8 +125,6 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) { } func NewBlockRes(block *types.Block, fullTx bool) *BlockRes { - // TODO respect fullTx flag - if block == nil { return nil } @@ -182,6 +180,10 @@ type TransactionRes struct { } func NewTransactionRes(tx *types.Transaction) *TransactionRes { + if tx == nil { + return nil + } + var v = new(TransactionRes) v.Hash = newHexData(tx.Hash()) v.Nonce = newHexNum(tx.Nonce())