From 70c539c8d7f21ecbbbfff0cf3b280e62fa76cfdc Mon Sep 17 00:00:00 2001 From: n0cte Date: Thu, 19 Aug 2021 11:47:42 +0300 Subject: [PATCH] fix encoding when storage is empty --- pkg/eth/api.go | 3 +++ pkg/graphql/graphql.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/eth/api.go b/pkg/eth/api.go index e9e9c922..2c0ca3ab 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -709,6 +709,9 @@ func (pea *PublicEthAPI) localGetBalance(ctx context.Context, address common.Add func (pea *PublicEthAPI) GetStorageAt(ctx context.Context, address common.Address, key string, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { storageVal, err := pea.B.GetStorageByNumberOrHash(ctx, address, common.HexToHash(key), blockNrOrHash) if storageVal != nil && err == nil { + if len(storageVal) == 0 { + return make([]byte, 32), nil + } var value common.Hash _, content, _, err := rlp.Split(storageVal) if err == io.ErrUnexpectedEOF { diff --git a/pkg/graphql/graphql.go b/pkg/graphql/graphql.go index d12838e2..561abc29 100644 --- a/pkg/graphql/graphql.go +++ b/pkg/graphql/graphql.go @@ -1010,6 +1010,9 @@ func (r *Resolver) GetStorageAt(ctx context.Context, args struct { return nil, err } + if len(rlpValue) == 0 { + return &StorageResult{value: make([]byte, 32), cid: cid, ipldBlock: ipldBlock}, nil + } var value interface{} err = rlp.DecodeBytes(rlpValue, &value)