aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-03-24 17:24:39 +0800
committerMaran <maran.hidskes@gmail.com>2014-03-24 17:24:39 +0800
commit97786d03d57e1ca79e34ce5fd9aa172c61c3e665 (patch)
tree251a5e54305e5cedf568f2fb73dbff9302df4185 /ethchain/state.go
parent274d5cc91c45349ec8d7a1f5a20ef29896b38b2e (diff)
parent6a86c517c4f4b372cad0ae1d92e926a482eac5ba (diff)
downloadgo-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar.gz
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar.bz2
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar.lz
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar.xz
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.tar.zst
go-tangerine-97786d03d57e1ca79e34ce5fd9aa172c61c3e665.zip
Merge branch 'master' into miner
Diffstat (limited to 'ethchain/state.go')
-rw-r--r--ethchain/state.go55
1 files changed, 39 insertions, 16 deletions
diff --git a/ethchain/state.go b/ethchain/state.go
index b9c2c576d..1860647f2 100644
--- a/ethchain/state.go
+++ b/ethchain/state.go
@@ -63,8 +63,7 @@ func (s *State) GetContract(addr []byte) *Contract {
}
// build contract
- contract := &Contract{}
- contract.RlpDecode([]byte(data))
+ contract := NewContractFromBytes(addr, []byte(data))
// Check if there's a cached state for this contract
cachedState := s.states[string(addr)]
@@ -78,27 +77,19 @@ func (s *State) GetContract(addr []byte) *Contract {
return contract
}
-func (s *State) UpdateContract(addr []byte, contract *Contract) {
- s.trie.Update(string(addr), string(contract.RlpEncode()))
-}
-
-func Compile(code []string) (script []string) {
- script = make([]string, len(code))
- for i, val := range code {
- instr, _ := ethutil.CompileInstr(val)
-
- script[i] = string(instr)
- }
+func (s *State) UpdateContract(contract *Contract) {
+ addr := contract.Address()
- return
+ s.states[string(addr)] = contract.state
+ s.trie.Update(string(addr), string(contract.RlpEncode()))
}
func (s *State) GetAccount(addr []byte) (account *Account) {
data := s.trie.Get(string(addr))
if data == "" {
- account = NewAccount(big.NewInt(0))
+ account = NewAccount(addr, big.NewInt(0))
} else {
- account = NewAccountFromData([]byte(data))
+ account = NewAccountFromData(addr, []byte(data))
}
return
@@ -153,3 +144,35 @@ 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))
+}
+
+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)
+ }
+
+ return
+}
+
+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)
+ }
+
+ return
+}