From 9c6aca78933c14ca107da30c4690808950718368 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Wed, 16 Apr 2014 04:06:51 +0200
Subject: Merged accounts and contracts in to StateObject

* Account removed
* Contract removed
* Address state changed to CachedStateObject
* Added StateObject
---
 ethchain/state.go | 65 ++++++++++++++-----------------------------------------
 1 file changed, 16 insertions(+), 49 deletions(-)

(limited to 'ethchain/state.go')

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
 }
-- 
cgit v1.2.3


From 1c85d8c66b9db23687b0446b4a7e97e3e61fe188 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Thu, 24 Apr 2014 00:00:50 +0200
Subject: Minor improvements and bug fixes

* Fixed VM base bug
---
 ethchain/state.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'ethchain/state.go')

diff --git a/ethchain/state.go b/ethchain/state.go
index 655848932..fa63accf8 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -34,12 +34,12 @@ func (s *State) Reset() {
 
 // Syncs the trie and all siblings
 func (s *State) Sync() {
-	s.trie.Sync()
-
 	// Sync all nested states
 	for _, state := range s.states {
 		state.Sync()
 	}
+
+	s.trie.Sync()
 }
 
 // Purges the current trie.
-- 
cgit v1.2.3


From 16e52327a4baa5547c38965fce53b3ff40b98173 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Sun, 27 Apr 2014 16:50:44 +0200
Subject: Upped version number

---
 ethchain/state.go | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

(limited to 'ethchain/state.go')

diff --git a/ethchain/state.go b/ethchain/state.go
index fa63accf8..1b5655d4c 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -47,6 +47,7 @@ func (s *State) Purge() int {
 	return s.trie.NewIterator().Purge()
 }
 
+// XXX Deprecated
 func (s *State) GetContract(addr []byte) *StateObject {
 	data := s.trie.Get(string(addr))
 	if data == "" {
@@ -68,6 +69,32 @@ func (s *State) GetContract(addr []byte) *StateObject {
 	return contract
 }
 
+func (s *State) GetStateObject(addr []byte) *StateObject {
+	data := s.trie.Get(string(addr))
+	if data == "" {
+		return nil
+	}
+
+	stateObject := NewStateObjectFromBytes(addr, []byte(data))
+
+	// Check if there's a cached state for this contract
+	cachedStateObject := s.states[string(addr)]
+	if cachedStateObject != nil {
+		stateObject.state = cachedStateObject
+	} else {
+		// If it isn't cached, cache the state
+		s.states[string(addr)] = stateObject.state
+	}
+
+	return stateObject
+}
+
+func (s *State) SetStateObject(stateObject *StateObject) {
+	s.states[string(stateObject.address)] = stateObject.state
+
+	s.UpdateStateObject(stateObject)
+}
+
 func (s *State) GetAccount(addr []byte) (account *StateObject) {
 	data := s.trie.Get(string(addr))
 	if data == "" {
@@ -97,6 +124,7 @@ const (
 	UnknownTy
 )
 
+/*
 // Returns the object stored at key and the type stored at key
 // Returns nil if nothing is stored
 func (s *State) GetStateObject(key []byte) (*ethutil.Value, ObjType) {
@@ -124,6 +152,7 @@ func (s *State) GetStateObject(key []byte) (*ethutil.Value, ObjType) {
 
 	return val, typ
 }
+*/
 
 // Updates any given state object
 func (s *State) UpdateStateObject(object *StateObject) {
-- 
cgit v1.2.3