Initial plugin implementation
* refactor packages, flags, subscriptions * DRY refactor builder tests * use mockgen to generate mocks * update README * MODE=statediff no longer needed for unit tests * simplify func names, clean up metrics * move write params to service field * sql indexer: confirm quit after ipld cache reset prevents negative waitgroup panic * don't let TotalDifficulty become nil * use forked plugeth, plugeth-utils for now
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
package adapt
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/state"
|
||||
"github.com/ethereum/go-ethereum/trie"
|
||||
|
||||
plugeth "github.com/openrelayxyz/plugeth-utils/core"
|
||||
)
|
||||
|
||||
// StateView exposes a minimal interface for state access for diff building
|
||||
type StateView interface {
|
||||
OpenTrie(root common.Hash) (StateTrie, error)
|
||||
ContractCode(codeHash common.Hash) ([]byte, error)
|
||||
}
|
||||
|
||||
// StateTrie is an interface exposing only the necessary methods from state.Trie
|
||||
type StateTrie interface {
|
||||
GetKey([]byte) []byte
|
||||
NodeIterator([]byte) trie.NodeIterator
|
||||
}
|
||||
|
||||
// adapts a state.Database to StateView - used in tests
|
||||
type stateDatabaseView struct {
|
||||
db state.Database
|
||||
}
|
||||
|
||||
var _ StateView = stateDatabaseView{}
|
||||
|
||||
func GethStateView(db state.Database) StateView {
|
||||
return stateDatabaseView{db}
|
||||
}
|
||||
|
||||
func (a stateDatabaseView) OpenTrie(root common.Hash) (StateTrie, error) {
|
||||
return a.db.OpenTrie(common.Hash(root))
|
||||
}
|
||||
|
||||
func (a stateDatabaseView) ContractCode(hash common.Hash) ([]byte, error) {
|
||||
return a.db.ContractCode(common.Hash{}, hash)
|
||||
}
|
||||
|
||||
// adapts geth Trie to plugeth
|
||||
type adaptTrie struct {
|
||||
plugeth.Trie
|
||||
}
|
||||
|
||||
func NewStateTrie(t plugeth.Trie) StateTrie { return adaptTrie{t} }
|
||||
|
||||
func (a adaptTrie) NodeIterator(start []byte) trie.NodeIterator {
|
||||
return NodeIterator(a.Trie.NodeIterator(start))
|
||||
}
|
||||
|
||||
func NodeIterator(it plugeth.NodeIterator) trie.NodeIterator {
|
||||
return adaptIter{it}
|
||||
}
|
||||
|
||||
type adaptIter struct {
|
||||
plugeth.NodeIterator
|
||||
}
|
||||
|
||||
func (it adaptIter) Hash() common.Hash {
|
||||
return common.Hash(it.NodeIterator.Hash())
|
||||
}
|
||||
|
||||
func (it adaptIter) Parent() common.Hash {
|
||||
return common.Hash(it.NodeIterator.Parent())
|
||||
}
|
||||
|
||||
func (it adaptIter) AddResolver(resolver trie.NodeResolver) {
|
||||
r := func(owner plugeth.Hash, path []byte, hash plugeth.Hash) []byte {
|
||||
return resolver(common.Hash(owner), path, common.Hash(hash))
|
||||
}
|
||||
it.NodeIterator.AddResolver(r)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package adapt
|
||||
|
||||
import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
||||
plugeth "github.com/openrelayxyz/plugeth-utils/core"
|
||||
plugeth_params "github.com/openrelayxyz/plugeth-utils/restricted/params"
|
||||
)
|
||||
|
||||
func StateAccount(a *plugeth.StateAccount) *types.StateAccount {
|
||||
return &types.StateAccount{
|
||||
Nonce: a.Nonce,
|
||||
Balance: a.Balance,
|
||||
Root: common.Hash(a.Root),
|
||||
CodeHash: a.CodeHash,
|
||||
}
|
||||
}
|
||||
|
||||
func ChainConfig(cc *plugeth_params.ChainConfig) *params.ChainConfig {
|
||||
return ¶ms.ChainConfig{
|
||||
ChainID: cc.ChainID,
|
||||
HomesteadBlock: cc.HomesteadBlock,
|
||||
DAOForkBlock: cc.DAOForkBlock,
|
||||
DAOForkSupport: cc.DAOForkSupport,
|
||||
EIP150Block: cc.EIP150Block,
|
||||
EIP155Block: cc.EIP155Block,
|
||||
EIP158Block: cc.EIP158Block,
|
||||
ByzantiumBlock: cc.ByzantiumBlock,
|
||||
ConstantinopleBlock: cc.ConstantinopleBlock,
|
||||
PetersburgBlock: cc.PetersburgBlock,
|
||||
IstanbulBlock: cc.IstanbulBlock,
|
||||
MuirGlacierBlock: cc.MuirGlacierBlock,
|
||||
BerlinBlock: cc.BerlinBlock,
|
||||
LondonBlock: cc.LondonBlock,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user