implement database.StorageSlot()

This commit is contained in:
i-norden 2023-02-28 11:45:11 -06:00
parent 8754278d18
commit ede0af3c26
2 changed files with 13 additions and 4 deletions

View File

@ -3,9 +3,10 @@ package ipld_eth_statedb
import ( import (
"context" "context"
"errors" "errors"
"github.com/ethereum/go-ethereum/crypto"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/crypto"
"github.com/VictoriaMetrics/fastcache" "github.com/VictoriaMetrics/fastcache"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
@ -103,5 +104,13 @@ func (sd *stateDatabase) StateAccount(address common.Address) (*types.StateAccou
} }
func (sd *stateDatabase) StorageSlot(addressHash, slotHash common.Hash) ([]byte, error) { func (sd *stateDatabase) StorageSlot(addressHash, slotHash common.Hash) ([]byte, error) {
panic("implement me") res := StorageSlotResult{}
if err := sd.pgdb.QueryRow(context.Background(), GetStorageSlot, addressHash.Hex(), slotHash.Hex()).Scan(&res); err != nil {
return nil, errNotFound
}
if res.Removed {
// TODO: check expected behavior for deleted/non existing accounts
return nil, nil
}
return res.Value, nil
} }

4
sql.go
View File

@ -28,8 +28,8 @@ const (
// StorageSlotResult struct for unpacking GetStorageSlot result // StorageSlotResult struct for unpacking GetStorageSlot result
type StorageSlotResult struct { type StorageSlotResult struct {
Value string `db:"val"` Value []byte `db:"val"`
Removed bool `db:"removed"` Removed bool `db:"removed"`
} }
// StateAccountResult struct for unpacking GetStateAccount result // StateAccountResult struct for unpacking GetStateAccount result