diff --git a/database.go b/database.go index 64d605f..cfb6e18 100644 --- a/database.go +++ b/database.go @@ -94,7 +94,8 @@ func (sd *stateDatabase) ContractCodeSize(_, codeHash common.Hash) (int, error) // StateAccount satisfies Database, it returns the types.StateAccount for a provided address and block hash func (sd *stateDatabase) StateAccount(addressHash, blockHash common.Hash) (*types.StateAccount, error) { res := StateAccountResult{} - err := sd.pgdb.QueryRow(context.Background(), GetStateAccount, addressHash.Hex(), blockHash.Hex()).Scan(&res) + err := sd.pgdb.QueryRow(context.Background(), GetStateAccount, addressHash.Hex(), blockHash.Hex()). + Scan(&res.Balance, &res.Nonce, &res.CodeHash, &res.StorageRoot, &res.Removed) if err != nil { return nil, errNotFound } @@ -108,14 +109,16 @@ func (sd *stateDatabase) StateAccount(addressHash, blockHash common.Hash) (*type Nonce: res.Nonce, Balance: bal, Root: common.HexToHash(res.StorageRoot), - CodeHash: res.CodeHash, + CodeHash: common.HexToHash(res.CodeHash).Bytes(), }, nil } // StorageValue satisfies Database, it returns the storage value for the provided address, slot, and block hash func (sd *stateDatabase) StorageValue(addressHash, slotHash, blockHash common.Hash) ([]byte, error) { res := StorageSlotResult{} - err := sd.pgdb.QueryRow(context.Background(), GetStorageSlot, addressHash.Hex(), slotHash.Hex(), blockHash.Hex()).Scan(&res) + err := sd.pgdb.QueryRow(context.Background(), GetStorageSlot, + addressHash.Hex(), slotHash.Hex(), blockHash.Hex()). + Scan(&res.Value, &res.Removed) if err != nil { return nil, errNotFound } diff --git a/sql.go b/sql.go index 2dd648d..e5a0237 100644 --- a/sql.go +++ b/sql.go @@ -1,7 +1,7 @@ package ipld_eth_statedb const ( - GetContractCodePgStr = `SELECT data FROM public.blocks WHERE key = $1` + GetContractCodePgStr = `SELECT data FROM ipld.blocks WHERE key = $1` GetStateAccount = `SELECT balance, nonce, code_hash, storage_root, removed FROM eth.state_cids INNER JOIN eth.header_cids ON ( state_cids.header_id = header_cids.block_hash @@ -39,7 +39,7 @@ type StorageSlotResult struct { type StateAccountResult struct { Balance string `db:"balance"` Nonce uint64 `db:"nonce"` - CodeHash []byte `db:"code_hash"` + CodeHash string `db:"code_hash"` StorageRoot string `db:"storage_root"` Removed bool `db:"removed"` } diff --git a/statedb.go b/statedb.go index e60e4f2..ab823ed 100644 --- a/statedb.go +++ b/statedb.go @@ -332,7 +332,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { s.AccountReads += time.Since(start) } if err != nil { - s.setError(fmt.Errorf("getDeleteStateObject (%x) error: %w", addr.Bytes(), err)) + s.setError(fmt.Errorf("getDeletedStateObject (%x) error: %w", addr.Bytes(), err)) return nil } if data == nil {