From cef4b1ddc6693ef95eae1410a9ee9c7b7e066dbb Mon Sep 17 00:00:00 2001 From: ramil Date: Wed, 21 Apr 2021 22:09:57 +0300 Subject: [PATCH] fix storageAt json-rpc endpoint --- pkg/eth/api.go | 9 ++++++++- pkg/eth/ipld_retriever.go | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/eth/api.go b/pkg/eth/api.go index 879d6fd5..d913e1ce 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -660,7 +660,14 @@ 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 { - return storageVal, nil + var value common.Hash + _, content, _, err := rlp.Split(storageVal) + if err != nil { + return nil, err + } + value.SetBytes(content) + + return value[:], nil } if pea.rpc != nil { var res hexutil.Bytes diff --git a/pkg/eth/ipld_retriever.go b/pkg/eth/ipld_retriever.go index 52cb26ae..78982ecf 100644 --- a/pkg/eth/ipld_retriever.go +++ b/pkg/eth/ipld_retriever.go @@ -432,6 +432,7 @@ func (r *IPLDRetriever) RetrieveAccountByAddressAndBlockNumber(address common.Ad func (r *IPLDRetriever) RetrieveStorageAtByAddressAndStorageKeyAndBlockHash(address common.Address, storageLeafKey, hash common.Hash) (string, []byte, error) { storageResult := new(nodeInfo) stateLeafKey := crypto.Keccak256Hash(address.Bytes()) + storageLeafKey = crypto.Keccak256Hash(storageLeafKey.Bytes()) if err := r.db.Get(storageResult, RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr, stateLeafKey.Hex(), storageLeafKey.Hex(), hash.Hex()); err != nil { return "", nil, err }