Commit 018ee56a authored by George Hotz's avatar George Hotz

fake trie

parent 26559b6a
...@@ -26,3 +26,13 @@ func (db *Database) ContractCodeSize(addr common.Address, codeHash common.Hash) ...@@ -26,3 +26,13 @@ func (db *Database) ContractCodeSize(addr common.Address, codeHash common.Hash)
code := oracle.GetProvedCodeBytes(db.BlockNumber, addr, codeHash) code := oracle.GetProvedCodeBytes(db.BlockNumber, addr, codeHash)
return len(code), nil return len(code), nil
} }
type Trie struct {
BlockNumber *big.Int
StateRoot common.Hash
}
func (trie *Trie) TryGet(key []byte) ([]byte, error) {
enc := oracle.GetProvedAccountBytes(trie.BlockNumber, trie.StateRoot, common.BytesToAddress(key))
return enc, nil
}
...@@ -8,7 +8,6 @@ import ( ...@@ -8,7 +8,6 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
) )
...@@ -18,7 +17,8 @@ var ( ...@@ -18,7 +17,8 @@ var (
) )
type StateDB struct { type StateDB struct {
db Database db Database
trie Trie
blockNumber *big.Int blockNumber *big.Int
stateRoot common.Hash stateRoot common.Hash
...@@ -45,6 +45,7 @@ func NewStateDB(header types.Header) *StateDB { ...@@ -45,6 +45,7 @@ func NewStateDB(header types.Header) *StateDB {
stateObjects: make(map[common.Address]*stateObject), stateObjects: make(map[common.Address]*stateObject),
stateRoot: header.Root, stateRoot: header.Root,
db: Database{BlockNumber: header.Number, StateRoot: header.Root}, db: Database{BlockNumber: header.Number, StateRoot: header.Root},
trie: Trie{BlockNumber: header.Number, StateRoot: header.Root},
accessList: newAccessList(), accessList: newAccessList(),
logs: make(map[common.Hash][]*types.Log), logs: make(map[common.Hash][]*types.Log),
} }
...@@ -336,15 +337,15 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { ...@@ -336,15 +337,15 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject {
//fmt.Println("getDeletedStateObject:", addr) //fmt.Println("getDeletedStateObject:", addr)
// If snapshot unavailable or reading from it failed, load from the database // If snapshot unavailable or reading from it failed, load from the database
/*enc, err := s.trie.TryGet(addr.Bytes()) enc, err := s.trie.TryGet(addr.Bytes())
if err != nil { if err != nil {
fmt.Printf("getDeleteStateObject (%x) error: %v\n", addr.Bytes(), err) fmt.Printf("getDeleteStateObject (%x) error: %v\n", addr.Bytes(), err)
return nil return nil
}*/ }
// TODO: call eth_getProof // TODO: call eth_getProof
// In a higher level, write getProvedAccountBytes(addr) // In a higher level, write getProvedAccountBytes(addr)
//enc := []byte("12") //enc := []byte("12")
enc := oracle.GetProvedAccountBytes(s.blockNumber, s.stateRoot, addr) //enc := oracle.GetProvedAccountBytes(s.blockNumber, s.stateRoot, addr)
if len(enc) == 0 { if len(enc) == 0 {
return nil return nil
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment