Skip to content

Commit

Permalink
Address comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
arijitAD committed Jun 18, 2021
1 parent b1a6fb0 commit c4f7fa2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
14 changes: 7 additions & 7 deletions pkg/eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -735,19 +735,19 @@ 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
} else if err != nil {
return nil, err
}

_, storageRlp, err := b.IPLDRetriever.RetrieveStorageAtByAddressAndStorageKeyAndBlockHash(address, storageLeafKey, hash)
_, storageRlp, err := b.IPLDRetriever.RetrieveStorageAtByAddressAndStorageSlotAndBlockHash(address, key, hash)
return storageRlp, err
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/eth/backend_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions pkg/eth/ipld_retriever.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit c4f7fa2

Please sign in to comment.