aboutsummaryrefslogtreecommitdiffstats
path: root/state/statedb.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-16 18:59:52 +0800
committerobscuren <geffobscura@gmail.com>2015-03-16 18:59:52 +0800
commitf486c0ae563eaf89a601ca5d60f30be96db2e69a (patch)
treea134ae6e38b90a268d91c61eab4ceb17856f2144 /state/statedb.go
parentb5234413611ce5984292f85a01de1f56c045b490 (diff)
downloadgo-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar.gz
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar.bz2
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar.lz
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar.xz
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.tar.zst
go-tangerine-f486c0ae563eaf89a601ca5d60f30be96db2e69a.zip
new type + additional methods
Diffstat (limited to 'state/statedb.go')
-rw-r--r--state/statedb.go49
1 files changed, 25 insertions, 24 deletions
diff --git a/state/statedb.go b/state/statedb.go
index 80bbe2afd..0c97fc464 100644
--- a/state/statedb.go
+++ b/state/statedb.go
@@ -45,15 +45,16 @@ func (self *StateDB) Logs() Logs {
return self.logs
}
-func (self *StateDB) Refund(addr []byte, gas *big.Int) {
- if self.refund[string(addr)] == nil {
- self.refund[string(addr)] = new(big.Int)
+func (self *StateDB) Refund(address common.Address, gas *big.Int) {
+ addr := address.Str()
+ if self.refund[addr] == nil {
+ self.refund[addr] = new(big.Int)
}
- self.refund[string(addr)].Add(self.refund[string(addr)], gas)
+ self.refund[addr].Add(self.refund[addr], gas)
}
// Retrieve the balance from the given address or 0 if object not found
-func (self *StateDB) GetBalance(addr []byte) *big.Int {
+func (self *StateDB) GetBalance(addr common.Address) *big.Int {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
return stateObject.balance
@@ -62,14 +63,14 @@ func (self *StateDB) GetBalance(addr []byte) *big.Int {
return common.Big0
}
-func (self *StateDB) AddBalance(addr []byte, amount *big.Int) {
+func (self *StateDB) AddBalance(addr common.Address, amount *big.Int) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.AddBalance(amount)
}
}
-func (self *StateDB) GetNonce(addr []byte) uint64 {
+func (self *StateDB) GetNonce(addr common.Address) uint64 {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
return stateObject.nonce
@@ -78,7 +79,7 @@ func (self *StateDB) GetNonce(addr []byte) uint64 {
return 0
}
-func (self *StateDB) GetCode(addr []byte) []byte {
+func (self *StateDB) GetCode(addr common.Address) []byte {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
return stateObject.code
@@ -87,7 +88,7 @@ func (self *StateDB) GetCode(addr []byte) []byte {
return nil
}
-func (self *StateDB) GetState(a, b []byte) []byte {
+func (self *StateDB) GetState(a common.Adress, b common.Hash) []byte {
stateObject := self.GetStateObject(a)
if stateObject != nil {
return stateObject.GetState(b).Bytes()
@@ -96,28 +97,28 @@ func (self *StateDB) GetState(a, b []byte) []byte {
return nil
}
-func (self *StateDB) SetNonce(addr []byte, nonce uint64) {
+func (self *StateDB) SetNonce(addr common.Address, nonce uint64) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
}
-func (self *StateDB) SetCode(addr, code []byte) {
+func (self *StateDB) SetCode(addr common.Address, code []byte) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.SetCode(code)
}
}
-func (self *StateDB) SetState(addr, key []byte, value interface{}) {
+func (self *StateDB) SetState(addr common.Address, key common.Hash, value interface{}) {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.SetState(key, common.NewValue(value))
}
}
-func (self *StateDB) Delete(addr []byte) bool {
+func (self *StateDB) Delete(addr common.Address) bool {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
stateObject.MarkForDeletion()
@@ -129,7 +130,7 @@ func (self *StateDB) Delete(addr []byte) bool {
return false
}
-func (self *StateDB) IsDeleted(addr []byte) bool {
+func (self *StateDB) IsDeleted(addr common.Address) bool {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
return stateObject.remove
@@ -143,27 +144,27 @@ func (self *StateDB) IsDeleted(addr []byte) bool {
// Update the given state object and apply it to state trie
func (self *StateDB) UpdateStateObject(stateObject *StateObject) {
- addr := stateObject.Address()
+ //addr := stateObject.Address()
if len(stateObject.CodeHash()) > 0 {
self.db.Put(stateObject.CodeHash(), stateObject.code)
}
- self.trie.Update(addr, stateObject.RlpEncode())
+ self.trie.Update(stateObject.Address(), stateObject.RlpEncode())
}
// Delete the given state object and delete it from the state trie
func (self *StateDB) DeleteStateObject(stateObject *StateObject) {
self.trie.Delete(stateObject.Address())
- delete(self.stateObjects, string(stateObject.Address()))
+ delete(self.stateObjects, stateObject.Address().Str())
}
// Retrieve a state object given my the address. Nil if not found
-func (self *StateDB) GetStateObject(addr []byte) *StateObject {
- addr = common.Address(addr)
+func (self *StateDB) GetStateObject(addr common.Address) *StateObject {
+ //addr = common.Address(addr)
- stateObject := self.stateObjects[string(addr)]
+ stateObject := self.stateObjects[addr.Str()]
if stateObject != nil {
return stateObject
}
@@ -180,11 +181,11 @@ func (self *StateDB) GetStateObject(addr []byte) *StateObject {
}
func (self *StateDB) SetStateObject(object *StateObject) {
- self.stateObjects[string(object.address)] = object
+ self.stateObjects[object.Address().Str()] = object
}
// Retrieve a state object or create a new state object if nil
-func (self *StateDB) GetOrNewStateObject(addr []byte) *StateObject {
+func (self *StateDB) GetOrNewStateObject(addr common.Address) *StateObject {
stateObject := self.GetStateObject(addr)
if stateObject == nil {
stateObject = self.NewStateObject(addr)
@@ -194,8 +195,8 @@ 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 = common.Address(addr)
+func (self *StateDB) NewStateObject(addr common.Address) *StateObject {
+ //addr = common.Address(addr)
statelogger.Debugf("(+) %x\n", addr)