forked from cerc-io/plugeth
More nil checks
This commit is contained in:
parent
172b34351a
commit
876ce0fb12
@ -212,6 +212,9 @@ func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) err
|
|||||||
|
|
||||||
block := api.xeth().EthBlockByHash(args.Hash)
|
block := api.xeth().EthBlockByHash(args.Hash)
|
||||||
br := NewBlockRes(block, true)
|
br := NewBlockRes(block, true)
|
||||||
|
if br == nil {
|
||||||
|
*reply = nil
|
||||||
|
}
|
||||||
|
|
||||||
if args.Index >= int64(len(br.Transactions)) || args.Index < 0 {
|
if args.Index >= int64(len(br.Transactions)) || args.Index < 0 {
|
||||||
return NewValidationError("Index", "does not exist")
|
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)
|
block := api.xeth().EthBlockByNumber(args.BlockNumber)
|
||||||
v := NewBlockRes(block, true)
|
v := NewBlockRes(block, true)
|
||||||
|
if v == nil {
|
||||||
|
*reply = nil
|
||||||
|
}
|
||||||
|
|
||||||
if args.Index >= int64(len(v.Transactions)) || args.Index < 0 {
|
if args.Index >= int64(len(v.Transactions)) || args.Index < 0 {
|
||||||
return NewValidationError("Index", "does not exist")
|
return NewValidationError("Index", "does not exist")
|
||||||
|
@ -125,8 +125,6 @@ func (b *BlockRes) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
|
func NewBlockRes(block *types.Block, fullTx bool) *BlockRes {
|
||||||
// TODO respect fullTx flag
|
|
||||||
|
|
||||||
if block == nil {
|
if block == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -182,6 +180,10 @@ type TransactionRes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewTransactionRes(tx *types.Transaction) *TransactionRes {
|
func NewTransactionRes(tx *types.Transaction) *TransactionRes {
|
||||||
|
if tx == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var v = new(TransactionRes)
|
var v = new(TransactionRes)
|
||||||
v.Hash = newHexData(tx.Hash())
|
v.Hash = newHexData(tx.Hash())
|
||||||
v.Nonce = newHexNum(tx.Nonce())
|
v.Nonce = newHexNum(tx.Nonce())
|
||||||
|
Loading…
Reference in New Issue
Block a user