Official Go implementation of the Ethereum protocol
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-ethereum/trie/secure_trie.go

41 lines
1.0 KiB

10 years ago
package trie
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
)
10 years ago
type SecureTrie struct {
*Trie
}
func NewSecure(root common.Hash, backend Backend) *SecureTrie {
10 years ago
return &SecureTrie{New(root, backend)}
}
func (self *SecureTrie) Update(key common.Hash, value []byte) Node {
return self.Trie.Update(common.BytesToHash(crypto.Sha3(key[:])), value)
10 years ago
}
10 years ago
func (self *SecureTrie) UpdateString(key, value string) Node {
return self.Update(common.StringToHash(key), []byte(value))
10 years ago
}
func (self *SecureTrie) Get(key common.Hash) []byte {
return self.Trie.Get(common.BytesToHash(crypto.Sha3(key[:])))
10 years ago
}
func (self *SecureTrie) GetString(key string) []byte {
return self.Get(common.StringToHash(key))
10 years ago
}
func (self *SecureTrie) Delete(key common.Hash) Node {
return self.Trie.Delete(common.BytesToHash(crypto.Sha3(key[:])))
10 years ago
}
10 years ago
func (self *SecureTrie) DeleteString(key string) Node {
return self.Delete(common.StringToHash(key))
10 years ago
}
func (self *SecureTrie) Copy() *SecureTrie {
return &SecureTrie{self.Trie.Copy()}
}