aboutsummaryrefslogtreecommitdiffstats
path: root/state
diff options
context:
space:
mode:
Diffstat (limited to 'state')
-rw-r--r--state/dump.go10
-rw-r--r--state/log.go8
-rw-r--r--state/managed_state_test.go4
-rw-r--r--state/state_object.go56
-rw-r--r--state/state_test.go8
-rw-r--r--state/statedb.go16
6 files changed, 51 insertions, 51 deletions
diff --git a/state/dump.go b/state/dump.go
index 2c611d76b..c5f556e1a 100644
--- a/state/dump.go
+++ b/state/dump.go
@@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
type Account struct {
@@ -22,7 +22,7 @@ type World struct {
func (self *StateDB) RawDump() World {
world := World{
- Root: ethutil.Bytes2Hex(self.trie.Root()),
+ Root: common.Bytes2Hex(self.trie.Root()),
Accounts: make(map[string]Account),
}
@@ -30,14 +30,14 @@ func (self *StateDB) RawDump() World {
for it.Next() {
stateObject := NewStateObjectFromBytes(it.Key, it.Value, self.db)
- account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: ethutil.Bytes2Hex(stateObject.Root()), CodeHash: ethutil.Bytes2Hex(stateObject.codeHash)}
+ account := Account{Balance: stateObject.balance.String(), Nonce: stateObject.nonce, Root: common.Bytes2Hex(stateObject.Root()), CodeHash: common.Bytes2Hex(stateObject.codeHash)}
account.Storage = make(map[string]string)
storageIt := stateObject.State.trie.Iterator()
for storageIt.Next() {
- account.Storage[ethutil.Bytes2Hex(storageIt.Key)] = ethutil.Bytes2Hex(storageIt.Value)
+ account.Storage[common.Bytes2Hex(storageIt.Key)] = common.Bytes2Hex(storageIt.Value)
}
- world.Accounts[ethutil.Bytes2Hex(it.Key)] = account
+ world.Accounts[common.Bytes2Hex(it.Key)] = account
}
return world
}
diff --git a/state/log.go b/state/log.go
index d503bd1a0..a0859aaf2 100644
--- a/state/log.go
+++ b/state/log.go
@@ -3,11 +3,11 @@ package state
import (
"fmt"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
type Log interface {
- ethutil.RlpEncodable
+ common.RlpEncodable
Address() []byte
Topics() [][]byte
@@ -43,7 +43,7 @@ func (self *StateLog) Number() uint64 {
return self.number
}
-func NewLogFromValue(decoder *ethutil.Value) *StateLog {
+func NewLogFromValue(decoder *common.Value) *StateLog {
log := &StateLog{
address: decoder.Get(0).Bytes(),
data: decoder.Get(2).Bytes(),
@@ -58,7 +58,7 @@ func NewLogFromValue(decoder *ethutil.Value) *StateLog {
}
func (self *StateLog) RlpData() interface{} {
- return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data}
+ return []interface{}{self.address, common.ByteSliceToInterface(self.topics), self.data}
}
func (self *StateLog) String() string {
diff --git a/state/managed_state_test.go b/state/managed_state_test.go
index f819d8ad3..4aad1e1e3 100644
--- a/state/managed_state_test.go
+++ b/state/managed_state_test.go
@@ -3,10 +3,10 @@ package state
import (
"testing"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
-var addr = ethutil.Address([]byte("test"))
+var addr = common.Address([]byte("test"))
func create() (*ManagedState, *account) {
ms := ManageState(&StateDB{stateObjects: make(map[string]*StateObject)})
diff --git a/state/state_object.go b/state/state_object.go
index dccbe8dad..8be9e28fc 100644
--- a/state/state_object.go
+++ b/state/state_object.go
@@ -6,7 +6,7 @@ import (
"math/big"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/trie"
)
@@ -17,7 +17,7 @@ func (self Code) String() string {
return string(self) //strings.Join(Disassemble(self), " ")
}
-type Storage map[string]*ethutil.Value
+type Storage map[string]*common.Value
func (self Storage) String() (str string) {
for key, value := range self {
@@ -39,7 +39,7 @@ func (self Storage) Copy() Storage {
type StateObject struct {
// State database for storing state changes
- db ethutil.Database
+ db common.Database
// The state object
State *StateDB
@@ -77,12 +77,12 @@ func (self *StateObject) Reset() {
self.State.Reset()
}
-func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
+func NewStateObject(addr []byte, db common.Database) *StateObject {
// This to ensure that it has 20 bytes (and not 0 bytes), thus left or right pad doesn't matter.
- address := ethutil.Address(addr)
+ address := common.Address(addr)
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
- object.State = New(nil, db) //New(trie.New(ethutil.Config.Db, ""))
+ object.State = New(nil, db) //New(trie.New(common.Config.Db, ""))
object.storage = make(Storage)
object.gasPool = new(big.Int)
object.prepaid = new(big.Int)
@@ -90,7 +90,7 @@ func NewStateObject(addr []byte, db ethutil.Database) *StateObject {
return object
}
-func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateObject {
+func NewStateObjectFromBytes(address, data []byte, db common.Database) *StateObject {
// TODO clean me up
var extobject struct {
Nonce uint64
@@ -110,7 +110,7 @@ func NewStateObjectFromBytes(address, data []byte, db ethutil.Database) *StateOb
object.balance = extobject.Balance
object.codeHash = extobject.CodeHash
object.State = New(extobject.Root, db)
- object.storage = make(map[string]*ethutil.Value)
+ object.storage = make(map[string]*common.Value)
object.gasPool = new(big.Int)
object.prepaid = new(big.Int)
object.code, _ = db.Get(extobject.CodeHash)
@@ -124,18 +124,18 @@ func (self *StateObject) MarkForDeletion() {
statelogger.Debugf("%x: #%d %v X\n", self.Address(), self.nonce, self.balance)
}
-func (c *StateObject) getAddr(addr []byte) *ethutil.Value {
- return ethutil.NewValueFromBytes([]byte(c.State.trie.Get(addr)))
+func (c *StateObject) getAddr(addr []byte) *common.Value {
+ return common.NewValueFromBytes([]byte(c.State.trie.Get(addr)))
}
func (c *StateObject) setAddr(addr []byte, value interface{}) {
- c.State.trie.Update(addr, ethutil.Encode(value))
+ c.State.trie.Update(addr, common.Encode(value))
}
-func (self *StateObject) GetStorage(key *big.Int) *ethutil.Value {
+func (self *StateObject) GetStorage(key *big.Int) *common.Value {
return self.GetState(key.Bytes())
}
-func (self *StateObject) SetStorage(key *big.Int, value *ethutil.Value) {
+func (self *StateObject) SetStorage(key *big.Int, value *common.Value) {
self.SetState(key.Bytes(), value)
}
@@ -143,8 +143,8 @@ func (self *StateObject) Storage() Storage {
return self.storage
}
-func (self *StateObject) GetState(k []byte) *ethutil.Value {
- key := ethutil.LeftPadBytes(k, 32)
+func (self *StateObject) GetState(k []byte) *common.Value {
+ key := common.LeftPadBytes(k, 32)
value := self.storage[string(key)]
if value == nil {
@@ -158,8 +158,8 @@ func (self *StateObject) GetState(k []byte) *ethutil.Value {
return value
}
-func (self *StateObject) SetState(k []byte, value *ethutil.Value) {
- key := ethutil.LeftPadBytes(k, 32)
+func (self *StateObject) SetState(k []byte, value *common.Value) {
+ key := common.LeftPadBytes(k, 32)
self.storage[string(key)] = value.Copy()
self.dirty = true
}
@@ -176,12 +176,12 @@ func (self *StateObject) Sync() {
self.storage = make(Storage)
}
-func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
+func (c *StateObject) GetInstr(pc *big.Int) *common.Value {
if int64(len(c.code)-1) < pc.Int64() {
- return ethutil.NewValue(0)
+ return common.NewValue(0)
}
- return ethutil.NewValueFromBytes([]byte{c.code[pc.Int64()]})
+ return common.NewValueFromBytes([]byte{c.code[pc.Int64()]})
}
func (c *StateObject) AddBalance(amount *big.Int) {
@@ -252,13 +252,13 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
func (self *StateObject) Copy() *StateObject {
stateObject := NewStateObject(self.Address(), self.db)
stateObject.balance.Set(self.balance)
- stateObject.codeHash = ethutil.CopyBytes(self.codeHash)
+ stateObject.codeHash = common.CopyBytes(self.codeHash)
stateObject.nonce = self.nonce
if self.State != nil {
stateObject.State = self.State.Copy()
}
- stateObject.code = ethutil.CopyBytes(self.code)
- stateObject.initCode = ethutil.CopyBytes(self.initCode)
+ stateObject.code = common.CopyBytes(self.code)
+ stateObject.initCode = common.CopyBytes(self.initCode)
stateObject.storage = self.storage.Copy()
stateObject.gasPool.Set(self.gasPool)
stateObject.remove = self.remove
@@ -330,19 +330,19 @@ func (self *StateObject) Nonce() uint64 {
// State object encoding methods
func (c *StateObject) RlpEncode() []byte {
- return ethutil.Encode([]interface{}{c.nonce, c.balance, c.Root(), c.CodeHash()})
+ return common.Encode([]interface{}{c.nonce, c.balance, c.Root(), c.CodeHash()})
}
-func (c *StateObject) CodeHash() ethutil.Bytes {
+func (c *StateObject) CodeHash() common.Bytes {
return crypto.Sha3(c.code)
}
func (c *StateObject) RlpDecode(data []byte) {
- decoder := ethutil.NewValueFromBytes(data)
+ decoder := common.NewValueFromBytes(data)
c.nonce = decoder.Get(0).Uint()
c.balance = decoder.Get(1).BigInt()
- c.State = New(decoder.Get(2).Bytes(), c.db) //New(trie.New(ethutil.Config.Db, decoder.Get(2).Interface()))
- c.storage = make(map[string]*ethutil.Value)
+ c.State = New(decoder.Get(2).Bytes(), c.db) //New(trie.New(common.Config.Db, decoder.Get(2).Interface()))
+ c.storage = make(map[string]*common.Value)
c.gasPool = new(big.Int)
c.codeHash = decoder.Get(3).Bytes()
diff --git a/state/state_test.go b/state/state_test.go
index 07e35f7e2..3ecc03ae0 100644
--- a/state/state_test.go
+++ b/state/state_test.go
@@ -6,7 +6,7 @@ import (
checker "gopkg.in/check.v1"
"github.com/ethereum/go-ethereum/ethdb"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
)
type StateSuite struct {
@@ -63,9 +63,9 @@ func (s *StateSuite) SetUpTest(c *checker.C) {
func (s *StateSuite) TestSnapshot(c *checker.C) {
stateobjaddr := []byte("aa")
- storageaddr := ethutil.Big("0")
- data1 := ethutil.NewValue(42)
- data2 := ethutil.NewValue(43)
+ storageaddr := common.Big("0")
+ data1 := common.NewValue(42)
+ data2 := common.NewValue(43)
// get state object
stateObject := s.state.GetOrNewStateObject(stateobjaddr)
diff --git a/state/statedb.go b/state/statedb.go
index a0dc7732f..80bbe2afd 100644
--- a/state/statedb.go
+++ b/state/statedb.go
@@ -4,7 +4,7 @@ import (
"bytes"
"math/big"
- "github.com/ethereum/go-ethereum/ethutil"
+ "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/trie"
)
@@ -17,7 +17,7 @@ var statelogger = logger.NewLogger("STATE")
// * Contracts
// * Accounts
type StateDB struct {
- db ethutil.Database
+ db common.Database
trie *trie.SecureTrie
stateObjects map[string]*StateObject
@@ -28,8 +28,8 @@ type StateDB struct {
}
// Create a new state from a given trie
-func New(root []byte, db ethutil.Database) *StateDB {
- trie := trie.NewSecure(ethutil.CopyBytes(root), db)
+func New(root []byte, db common.Database) *StateDB {
+ trie := trie.NewSecure(common.CopyBytes(root), db)
return &StateDB{db: db, trie: trie, stateObjects: make(map[string]*StateObject), refund: make(map[string]*big.Int)}
}
@@ -59,7 +59,7 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
return stateObject.balance
}
- return ethutil.Big0
+ return common.Big0
}
func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
@@ -113,7 +113,7 @@ func (self *StateDB) SetCode(addr, code []byte) {
func (self *StateDB) SetState(addr, key []byte, value interface{}) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
- stateObject.SetState(key, ethutil.NewValue(value))
+ stateObject.SetState(key, common.NewValue(value))
}
}
@@ -161,7 +161,7 @@ func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
// Retrieve a state object given my the address. Nil if not found
func (self *StateDB) GetStateObject(addr []byte) *StateObject {
- addr = ethutil.Address(addr)
+ addr = common.Address(addr)
stateObject := self.stateObjects[string(addr)]
if stateObject != nil {
@@ -195,7 +195,7 @@ func (self *StateDB) GetOrNewStateObject(addr []byte) *StateObject {
// Create a state object whether it exist in the trie or not
func (self *StateDB) NewStateObject(addr []byte) *StateObject {
- addr = ethutil.Address(addr)
+ addr = common.Address(addr)
statelogger.Debugf("(+) %x\n", addr)