From c4f7fa28216a0e2a1844b5a31c7727af355773ea Mon Sep 17 00:00:00 2001 From: Arijit Das Date: Fri, 18 Jun 2021 12:12:29 +0530 Subject: [PATCH] Address comments. --- pkg/eth/backend.go | 14 +++++++------- pkg/eth/backend_utils.go | 8 +++----- pkg/eth/ipld_retriever.go | 8 ++++---- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/pkg/eth/backend.go b/pkg/eth/backend.go index b2a4d438..b91032a7 100644 --- a/pkg/eth/backend.go +++ b/pkg/eth/backend.go @@ -699,18 +699,18 @@ func (b *Backend) GetCodeByHash(ctx context.Context, address common.Address, has } // GetStorageByNumberOrHash returns the storage value for the provided contract address an storage key at the block corresponding to the provided number or hash -func (b *Backend) GetStorageByNumberOrHash(ctx context.Context, address common.Address, storageLeafKey common.Hash, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { +func (b *Backend) GetStorageByNumberOrHash(ctx context.Context, address common.Address, key common.Hash, blockNrOrHash rpc.BlockNumberOrHash) (hexutil.Bytes, error) { if blockNr, ok := blockNrOrHash.Number(); ok { - return b.GetStorageByNumber(ctx, address, storageLeafKey, blockNr) + return b.GetStorageByNumber(ctx, address, key, blockNr) } if hash, ok := blockNrOrHash.Hash(); ok { - return b.GetStorageByHash(ctx, address, storageLeafKey, hash) + return b.GetStorageByHash(ctx, address, key, hash) } return nil, errors.New("invalid arguments; neither block nor hash specified") } // GetStorageByNumber returns the storage value for the provided contract address an storage key at the block corresponding to the provided number -func (b *Backend) GetStorageByNumber(ctx context.Context, address common.Address, storageLeafKey common.Hash, blockNumber rpc.BlockNumber) (hexutil.Bytes, error) { +func (b *Backend) GetStorageByNumber(ctx context.Context, address common.Address, key common.Hash, blockNumber rpc.BlockNumber) (hexutil.Bytes, error) { var err error number := blockNumber.Int64() if blockNumber == rpc.LatestBlockNumber { @@ -735,11 +735,11 @@ func (b *Backend) GetStorageByNumber(ctx context.Context, address common.Address return nil, err } - return b.GetStorageByHash(ctx, address, storageLeafKey, hash) + return b.GetStorageByHash(ctx, address, key, hash) } // GetStorageByHash returns the storage value for the provided contract address an storage key at the block corresponding to the provided hash -func (b *Backend) GetStorageByHash(ctx context.Context, address common.Address, storageLeafKey, hash common.Hash) (hexutil.Bytes, error) { +func (b *Backend) GetStorageByHash(ctx context.Context, address common.Address, key, hash common.Hash) (hexutil.Bytes, error) { _, err := b.HeaderByHash(context.Background(), hash) if err == sql.ErrNoRows { return nil, errHeaderHashNotFound @@ -747,7 +747,7 @@ func (b *Backend) GetStorageByHash(ctx context.Context, address common.Address, return nil, err } - _, storageRlp, err := b.IPLDRetriever.RetrieveStorageAtByAddressAndStorageKeyAndBlockHash(address, storageLeafKey, hash) + _, storageRlp, err := b.IPLDRetriever.RetrieveStorageAtByAddressAndStorageSlotAndBlockHash(address, key, hash) return storageRlp, err } diff --git a/pkg/eth/backend_utils.go b/pkg/eth/backend_utils.go index 7a7191ed..32c04274 100644 --- a/pkg/eth/backend_utils.go +++ b/pkg/eth/backend_utils.go @@ -22,15 +22,13 @@ import ( "fmt" "math/big" - "github.com/ethereum/go-ethereum/params" - "github.com/ethereum/go-ethereum" - "github.com/ethereum/go-ethereum/rpc" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" + "github.com/ethereum/go-ethereum/rpc" "github.com/vulcanize/ipld-eth-indexer/pkg/ipfs" ) @@ -312,7 +310,7 @@ Logs: } // If the to filtered topics is greater than the amount of topics in logs, skip. if len(topics) > len(log.Topics) { - continue Logs + continue } for i, sub := range topics { match := len(sub) == 0 // empty rule set == wildcard diff --git a/pkg/eth/ipld_retriever.go b/pkg/eth/ipld_retriever.go index 78982ecf..4d50cfaa 100644 --- a/pkg/eth/ipld_retriever.go +++ b/pkg/eth/ipld_retriever.go @@ -428,12 +428,12 @@ func (r *IPLDRetriever) RetrieveAccountByAddressAndBlockNumber(address common.Ad return accountResult.CID, i[1].([]byte), nil } -// RetrieveStorageAtByAddressAndStorageKeyAndBlockHash returns the cid and rlp bytes for the storage value corresponding to the provided address, storage key, and block hash -func (r *IPLDRetriever) RetrieveStorageAtByAddressAndStorageKeyAndBlockHash(address common.Address, storageLeafKey, hash common.Hash) (string, []byte, error) { +// RetrieveStorageAtByAddressAndStorageSlotAndBlockHash returns the cid and rlp bytes for the storage value corresponding to the provided address, storage slot, and block hash +func (r *IPLDRetriever) RetrieveStorageAtByAddressAndStorageSlotAndBlockHash(address common.Address, key, 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 { + storageHash := crypto.Keccak256Hash(key.Bytes()) + if err := r.db.Get(storageResult, RetrieveStorageLeafByAddressHashAndLeafKeyAndBlockHashPgStr, stateLeafKey.Hex(), storageHash.Hex(), hash.Hex()); err != nil { return "", nil, err } if storageResult.Removed {