func TestEmptyTrie(t *testing.T) { trie := NewEmpty() res := trie.Hash() exp := crypto.Sha3(common.Encode("")) if !bytes.Equal(res, exp) { t.Errorf("expected %x got %x", exp, res) } }
func (self *Trie) Hash() []byte { var hash []byte if self.root != nil { t := self.root.Hash() if byts, ok := t.([]byte); ok && len(byts) > 0 { hash = byts } else { hash = crypto.Sha3(common.Encode(self.root.RlpData())) } } else { hash = crypto.Sha3(common.Encode("")) } if !bytes.Equal(hash, self.roothash) { self.revisions.PushBack(self.roothash) self.roothash = hash } return hash }
func (self *Trie) store(node Node) interface{} { data := common.Encode(node) if len(data) >= 32 { key := crypto.Sha3(data) if node.Dirty() { //fmt.Println("save", node) //fmt.Println() self.cache.Put(key, data) } return key } return node.RlpData() }
// State object encoding methods func (c *StateObject) RlpEncode() []byte { return common.Encode([]interface{}{c.nonce, c.balance, c.Root(), c.CodeHash()}) }