aboutsummaryrefslogtreecommitdiffstats
path: root/core/state/statedb.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-08-30 16:19:10 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-10-04 07:13:54 +0800
commit361082ec4b942aea7c01fcb1be1782cb68b6fe3a (patch)
treed3ed9276cc61d314a6de14de1a61ea2c2d9a70b2 /core/state/statedb.go
parentf7a71996fbbe9cea4445600ffa3c232a6cf42803 (diff)
downloadgo-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar.gz
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar.bz2
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar.lz
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar.xz
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.tar.zst
go-tangerine-361082ec4b942aea7c01fcb1be1782cb68b6fe3a.zip
cmd/evm, core/vm, test: refactored VM and core
* Moved `vm.Transfer` to `core` package and changed execution to call `env.Transfer` instead of `core.Transfer` directly. * core/vm: byte code VM moved to jump table instead of switch * Moved `vm.Transfer` to `core` package and changed execution to call `env.Transfer` instead of `core.Transfer` directly. * Byte code VM now shares the same code as the JITVM * Renamed Context to Contract * Changed initialiser of state transition & unexported methods * Removed the Execution object and refactor `Call`, `CallCode` & `Create` in to their own functions instead of being methods. * Removed the hard dep on the state for the VM. The VM now depends on a Database interface returned by the environment. In the process the core now depends less on the statedb by usage of the env * Moved `Log` from package `core/state` to package `core/vm`.
Diffstat (limited to 'core/state/statedb.go')
-rw-r--r--core/state/statedb.go41
1 files changed, 27 insertions, 14 deletions
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 4233c763b..499ea5f52 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -21,6 +21,7 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/common"
+ "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
@@ -42,7 +43,7 @@ type StateDB struct {
thash, bhash common.Hash
txIndex int
- logs map[common.Hash]Logs
+ logs map[common.Hash]vm.Logs
logSize uint
}
@@ -59,7 +60,7 @@ func New(root common.Hash, db ethdb.Database) *StateDB {
trie: tr,
stateObjects: make(map[string]*StateObject),
refund: new(big.Int),
- logs: make(map[common.Hash]Logs),
+ logs: make(map[common.Hash]vm.Logs),
}
}
@@ -69,7 +70,7 @@ func (self *StateDB) StartRecord(thash, bhash common.Hash, ti int) {
self.txIndex = ti
}
-func (self *StateDB) AddLog(log *Log) {
+func (self *StateDB) AddLog(log *vm.Log) {
log.TxHash = self.thash
log.BlockHash = self.bhash
log.TxIndex = uint(self.txIndex)
@@ -78,30 +79,34 @@ func (self *StateDB) AddLog(log *Log) {
self.logSize++
}
-func (self *StateDB) GetLogs(hash common.Hash) Logs {
+func (self *StateDB) GetLogs(hash common.Hash) vm.Logs {
return self.logs[hash]
}
-func (self *StateDB) Logs() Logs {
- var logs Logs
+func (self *StateDB) Logs() vm.Logs {
+ var logs vm.Logs
for _, lgs := range self.logs {
logs = append(logs, lgs...)
}
return logs
}
-func (self *StateDB) Refund(gas *big.Int) {
+func (self *StateDB) AddRefund(gas *big.Int) {
self.refund.Add(self.refund, gas)
}
-/*
- * GETTERS
- */
-
func (self *StateDB) HasAccount(addr common.Address) bool {
return self.GetStateObject(addr) != nil
}
+func (self *StateDB) Exist(addr common.Address) bool {
+ return self.GetStateObject(addr) != nil
+}
+
+func (self *StateDB) GetAccount(addr common.Address) vm.Account {
+ return self.GetStateObject(addr)
+}
+
// Retrieve the balance from the given address or 0 if object not found
func (self *StateDB) GetBalance(addr common.Address) *big.Int {
stateObject := self.GetStateObject(addr)
@@ -245,7 +250,7 @@ func (self *StateDB) SetStateObject(object *StateObject) {
func (self *StateDB) GetOrNewStateObject(addr common.Address) *StateObject {
stateObject := self.GetStateObject(addr)
if stateObject == nil || stateObject.deleted {
- stateObject = self.CreateAccount(addr)
+ stateObject = self.CreateStateObject(addr)
}
return stateObject
@@ -264,7 +269,7 @@ func (self *StateDB) newStateObject(addr common.Address) *StateObject {
}
// Creates creates a new state object and takes ownership. This is different from "NewStateObject"
-func (self *StateDB) CreateAccount(addr common.Address) *StateObject {
+func (self *StateDB) CreateStateObject(addr common.Address) *StateObject {
// Get previous (if any)
so := self.GetStateObject(addr)
// Create a new one
@@ -278,6 +283,10 @@ func (self *StateDB) CreateAccount(addr common.Address) *StateObject {
return newSo
}
+func (self *StateDB) CreateAccount(addr common.Address) vm.Account {
+ return self.CreateStateObject(addr)
+}
+
//
// Setting, copying of the state methods
//
@@ -292,7 +301,7 @@ func (self *StateDB) Copy() *StateDB {
state.refund.Set(self.refund)
for hash, logs := range self.logs {
- state.logs[hash] = make(Logs, len(logs))
+ state.logs[hash] = make(vm.Logs, len(logs))
copy(state.logs[hash], logs)
}
state.logSize = self.logSize
@@ -309,6 +318,10 @@ func (self *StateDB) Set(state *StateDB) {
self.logSize = state.logSize
}
+func (self *StateDB) GetRefund() *big.Int {
+ return self.refund
+}
+
// IntermediateRoot computes the current root hash of the state trie.
// It is called in between transactions to get the root hash that
// goes into transaction receipts.