update internal database interface
This commit is contained in:
parent
1741e5f790
commit
82555a5319
42
database.go
42
database.go
@ -3,11 +3,10 @@ package ipld_eth_statedb
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/VictoriaMetrics/fastcache"
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethdb"
|
||||
"github.com/ethereum/go-ethereum/statediff/indexer/ipld"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
@ -28,23 +27,25 @@ var (
|
||||
errNotFound = errors.New("not found")
|
||||
)
|
||||
|
||||
|
||||
// Database interface is a union of the subset of the geth state.Database interface required
|
||||
// to support the vm.StateDB implementation as well as methods specific to this Postgres based implementation
|
||||
type Database interface {
|
||||
ContractCode(addrHash common.Hash, codeHash common.Hash) ([]byte, error)
|
||||
ContractCodeSize(addrHash common.Hash, codeHash common.Hash) (int, error)
|
||||
OpenTrie(root common.Hash) (state.Trie, error)
|
||||
OpenStorageTrie(addrHash common.Hash, root common.Hash) (state.Trie, error)
|
||||
CopyTrie(trie state.Trie) state.Trie
|
||||
StateAccount(address common.Address) (*types.StateAccount, error)
|
||||
StorageSlot(addressHash, slotHash common.Hash) ([]byte, error)
|
||||
}
|
||||
|
||||
var _ Database = &stateDatabase{}
|
||||
|
||||
type stateDatabase struct {
|
||||
pgdb pgxpool.Pool
|
||||
pgdb *pgxpool.Pool
|
||||
trieDB *trie.Database
|
||||
codeSizeCache *lru.Cache
|
||||
codeCache *fastcache.Cache
|
||||
}
|
||||
|
||||
func NewStateDatabase(pgdb pgxpool.Pool, ethdb ethdb.Database, config *trie.Config) (*stateDatabase, error) {
|
||||
func NewStateDatabase(pgdb *pgxpool.Pool, ethdb ethdb.Database, config *trie.Config) (*stateDatabase, error) {
|
||||
csc, _ := lru.New(codeSizeCacheSize)
|
||||
return &stateDatabase{
|
||||
pgdb: pgdb,
|
||||
@ -79,27 +80,10 @@ func (sd *stateDatabase) ContractCodeSize(_, codeHash common.Hash) (int, error)
|
||||
return len(code), err
|
||||
}
|
||||
|
||||
func (sd *stateDatabase) OpenTrie(root common.Hash) (state.Trie, error) {
|
||||
tr, err := trie.NewStateTrie(common.Hash{}, root, sd.trieDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tr, nil
|
||||
func (sd *stateDatabase) StateAccount(address common.Address) (*types.StateAccount, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
||||
func (sd *stateDatabase) OpenStorageTrie(addrHash common.Hash, root common.Hash) (state.Trie, error) {
|
||||
tr, err := trie.NewStateTrie(addrHash, root, sd.trieDB)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return tr, nil
|
||||
}
|
||||
|
||||
func (sd *stateDatabase) CopyTrie(t state.Trie) state.Trie {
|
||||
switch t := t.(type) {
|
||||
case *trie.StateTrie:
|
||||
return t.Copy()
|
||||
default:
|
||||
panic(fmt.Errorf("unknown trie type %T", t))
|
||||
}
|
||||
func (sd *stateDatabase) StorageSlot(addressHash, slotHash common.Hash) ([]byte, error) {
|
||||
panic("implement me")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user