aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain/state.go')
-rw-r--r--ethchain/state.go65
1 files changed, 16 insertions, 49 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index 1860647f2..655848932 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -47,23 +47,14 @@ func (s *State) Purge() int {
return s.trie.NewIterator().Purge()
}
-func (s *State) GetContract(addr []byte) *Contract {
+func (s *State) GetContract(addr []byte) *StateObject {
data := s.trie.Get(string(addr))
if data == "" {
return nil
}
- // Whet get contract is called the retrieved value might
- // be an account. The StateManager uses this to check
- // to see if the address a tx was sent to is a contract
- // or an account
- value := ethutil.NewValueFromBytes([]byte(data))
- if value.Len() == 2 {
- return nil
- }
-
// build contract
- contract := NewContractFromBytes(addr, []byte(data))
+ contract := NewStateObjectFromBytes(addr, []byte(data))
// Check if there's a cached state for this contract
cachedState := s.states[string(addr)]
@@ -77,28 +68,17 @@ func (s *State) GetContract(addr []byte) *Contract {
return contract
}
-func (s *State) UpdateContract(contract *Contract) {
- addr := contract.Address()
-
- s.states[string(addr)] = contract.state
- s.trie.Update(string(addr), string(contract.RlpEncode()))
-}
-
-func (s *State) GetAccount(addr []byte) (account *Account) {
+func (s *State) GetAccount(addr []byte) (account *StateObject) {
data := s.trie.Get(string(addr))
if data == "" {
account = NewAccount(addr, big.NewInt(0))
} else {
- account = NewAccountFromData(addr, []byte(data))
+ account = NewStateObjectFromBytes(addr, []byte(data))
}
return
}
-func (s *State) UpdateAccount(addr []byte, account *Account) {
- s.trie.Update(string(addr), string(account.RlpEncode()))
-}
-
func (s *State) Cmp(other *State) bool {
return s.trie.Cmp(other.trie)
}
@@ -119,7 +99,7 @@ const (
// Returns the object stored at key and the type stored at key
// Returns nil if nothing is stored
-func (s *State) Get(key []byte) (*ethutil.Value, ObjType) {
+func (s *State) GetStateObject(key []byte) (*ethutil.Value, ObjType) {
// Fetch data from the trie
data := s.trie.Get(string(key))
// Returns the nil type, indicating nothing could be retrieved.
@@ -145,34 +125,21 @@ func (s *State) Get(key []byte) (*ethutil.Value, ObjType) {
return val, typ
}
-func (s *State) Put(key, object []byte) {
- s.trie.Update(string(key), string(object))
-}
+// Updates any given state object
+func (s *State) UpdateStateObject(object *StateObject) {
+ addr := object.Address()
-func (s *State) Root() interface{} {
- return s.trie.Root
-}
-
-// Script compilation functions
-// Compiles strings to machine code
-func Compile(code []string) (script []string) {
- script = make([]string, len(code))
- for i, val := range code {
- instr, _ := ethutil.CompileInstr(val)
-
- script[i] = string(instr)
+ if object.state != nil {
+ s.states[string(addr)] = object.state
}
- return
+ s.trie.Update(string(addr), string(object.RlpEncode()))
}
-func CompileToValues(code []string) (script []*ethutil.Value) {
- script = make([]*ethutil.Value, len(code))
- for i, val := range code {
- instr, _ := ethutil.CompileInstr(val)
-
- script[i] = ethutil.NewValue(instr)
- }
+func (s *State) Put(key, object []byte) {
+ s.trie.Update(string(key), string(object))
+}
- return
+func (s *State) Root() interface{} {
+ return s.trie.Root
}