Commit a37c36e5 authored by George Hotz's avatar George Hotz

RamFromTrie works

parent daada814
......@@ -9,6 +9,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/oracle"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)
......@@ -90,7 +91,24 @@ func ParseNode(node common.Hash, depth int, callback func(common.Hash) []byte) {
func RamFromTrie(root common.Hash) map[uint32](uint32) {
ram := make(map[uint32](uint32))
// TODO: write this
// load into oracle
pp := oracle.Preimages()
for k, v := range Preimages {
pp[k] = v
}
triedb := trie.Database{Root: root}
tt, err := trie.New(root, &triedb)
check(err)
tni := tt.NodeIterator([]byte{})
for tni.Next(true) {
if tni.Leaf() {
tk := binary.BigEndian.Uint32(tni.LeafKey())
tv := binary.BigEndian.Uint32(tni.LeafBlob())
ram[tk*4] = tv
}
}
return ram
}
......
......@@ -35,7 +35,12 @@ func TestTrie(t *testing.T) {
t.Fatal("preimage length mismatch")
}
// TODO: load memory when ready
// load memory
newram := RamFromTrie(newroot)
if !reflect.DeepEqual(ram, newram) {
t.Fatal("ram to/from mismatch")
}
}
func printRoot(ram map[uint32](uint32)) {
......
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