aboutsummaryrefslogtreecommitdiffstats
path: root/ethstate
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-07-30 06:31:15 +0800
committerobscuren <geffobscura@gmail.com>2014-07-30 06:31:15 +0800
commit1f9894c0845a5259adbfd30fe3a86631e6403b8d (patch)
tree7e038ca62c65482d576d3a8b3fde5419ac866f2f /ethstate
parent27f892265312255811867fab83acbeefa1626cec (diff)
downloadgo-tangerine-1f9894c0845a5259adbfd30fe3a86631e6403b8d.tar.gz
go-tangerine-1f9894c0845a5259adbfd30fe3a86631e6403b8d.tar.zst
go-tangerine-1f9894c0845a5259adbfd30fe3a86631e6403b8d.zip
Old code removed and renamed amount to balance
Diffstat (limited to 'ethstate')
-rw-r--r--ethstate/state.go5
-rw-r--r--ethstate/state_object.go39
2 files changed, 23 insertions, 21 deletions
diff --git a/ethstate/state.go b/ethstate/state.go
index 51b585d4d..693a591c3 100644
--- a/ethstate/state.go
+++ b/ethstate/state.go
@@ -1,11 +1,12 @@
package ethstate
import (
+ "math/big"
+
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethlog"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
- "math/big"
)
var statelogger = ethlog.NewLogger("STATE")
@@ -33,7 +34,7 @@ func NewState(trie *ethtrie.Trie) *State {
func (self *State) GetBalance(addr []byte) *big.Int {
stateObject := self.GetStateObject(addr)
if stateObject != nil {
- return stateObject.Amount
+ return stateObject.Balance
}
return ethutil.Big0
diff --git a/ethstate/state_object.go b/ethstate/state_object.go
index ab14b8604..5932fbee6 100644
--- a/ethstate/state_object.go
+++ b/ethstate/state_object.go
@@ -2,10 +2,11 @@ package ethstate
import (
"fmt"
+ "math/big"
+
"github.com/ethereum/eth-go/ethcrypto"
"github.com/ethereum/eth-go/ethtrie"
"github.com/ethereum/eth-go/ethutil"
- "math/big"
)
type Code []byte
@@ -30,7 +31,7 @@ type StateObject struct {
// Address of the object
address []byte
// Shared attributes
- Amount *big.Int
+ Balance *big.Int
CodeHash []byte
Nonce uint64
// Contract related attributes
@@ -78,7 +79,7 @@ func NewStateObject(addr []byte) *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)
- object := &StateObject{address: address, Amount: new(big.Int), gasPool: new(big.Int)}
+ object := &StateObject{address: address, Balance: new(big.Int), gasPool: new(big.Int)}
object.State = NewState(ethtrie.NewTrie(ethutil.Config.Db, ""))
object.storage = make(Storage)
object.gasPool = new(big.Int)
@@ -86,9 +87,9 @@ func NewStateObject(addr []byte) *StateObject {
return object
}
-func NewContract(address []byte, Amount *big.Int, root []byte) *StateObject {
+func NewContract(address []byte, balance *big.Int, root []byte) *StateObject {
contract := NewStateObject(address)
- contract.Amount = Amount
+ contract.Balance = balance
contract.State = NewState(ethtrie.NewTrie(ethutil.Config.Db, string(root)))
return contract
@@ -103,7 +104,7 @@ func NewStateObjectFromBytes(address, data []byte) *StateObject {
func (self *StateObject) MarkForDeletion() {
self.remove = true
- statelogger.DebugDetailf("%x: #%d %v (deletion)\n", self.Address(), self.Nonce, self.Amount)
+ statelogger.DebugDetailf("%x: #%d %v (deletion)\n", self.Address(), self.Nonce, self.Balance)
}
func (c *StateObject) GetAddr(addr []byte) *ethutil.Value {
@@ -190,19 +191,19 @@ func (c *StateObject) GetInstr(pc *big.Int) *ethutil.Value {
}
func (c *StateObject) AddAmount(amount *big.Int) {
- c.SetAmount(new(big.Int).Add(c.Amount, amount))
+ c.SetBalance(new(big.Int).Add(c.Balance, amount))
- statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ statelogger.Debugf("%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Balance, amount)
}
func (c *StateObject) SubAmount(amount *big.Int) {
- c.SetAmount(new(big.Int).Sub(c.Amount, amount))
+ c.SetBalance(new(big.Int).Sub(c.Balance, amount))
- statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ statelogger.Debugf("%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Balance, amount)
}
-func (c *StateObject) SetAmount(amount *big.Int) {
- c.Amount = amount
+func (c *StateObject) SetBalance(amount *big.Int) {
+ c.Balance = amount
}
//
@@ -213,8 +214,8 @@ func (c *StateObject) SetAmount(amount *big.Int) {
func (c *StateObject) ReturnGas(gas, price *big.Int) {}
func (c *StateObject) ConvertGas(gas, price *big.Int) error {
total := new(big.Int).Mul(gas, price)
- if total.Cmp(c.Amount) > 0 {
- return fmt.Errorf("insufficient amount: %v, %v", c.Amount, total)
+ if total.Cmp(c.Balance) > 0 {
+ return fmt.Errorf("insufficient amount: %v, %v", c.Balance, total)
}
c.SubAmount(total)
@@ -247,12 +248,12 @@ func (self *StateObject) RefundGas(gas, price *big.Int) {
rGas := new(big.Int).Set(gas)
rGas.Mul(rGas, price)
- self.Amount.Sub(self.Amount, rGas)
+ self.Balance.Sub(self.Balance, rGas)
}
func (self *StateObject) Copy() *StateObject {
stateObject := NewStateObject(self.Address())
- stateObject.Amount.Set(self.Amount)
+ stateObject.Balance.Set(self.Balance)
stateObject.CodeHash = ethutil.CopyBytes(self.CodeHash)
stateObject.Nonce = self.Nonce
if self.State != nil {
@@ -290,7 +291,7 @@ func (c *StateObject) Init() Code {
// Debug stuff
func (self *StateObject) CreateOutputForDiff() {
- fmt.Printf("%x %x %x %x\n", self.Address(), self.State.Root(), self.Amount.Bytes(), self.Nonce)
+ fmt.Printf("%x %x %x %x\n", self.Address(), self.State.Root(), self.Balance.Bytes(), self.Nonce)
self.EachStorage(func(addr string, value *ethutil.Value) {
fmt.Printf("%x %x\n", addr, value.Bytes())
})
@@ -309,14 +310,14 @@ func (c *StateObject) RlpEncode() []byte {
root = ""
}
- return ethutil.Encode([]interface{}{c.Nonce, c.Amount, root, ethcrypto.Sha3Bin(c.Code)})
+ return ethutil.Encode([]interface{}{c.Nonce, c.Balance, root, ethcrypto.Sha3Bin(c.Code)})
}
func (c *StateObject) RlpDecode(data []byte) {
decoder := ethutil.NewValueFromBytes(data)
c.Nonce = decoder.Get(0).Uint()
- c.Amount = decoder.Get(1).BigInt()
+ c.Balance = decoder.Get(1).BigInt()
c.State = NewState(ethtrie.NewTrie(ethutil.Config.Db, decoder.Get(2).Interface()))
c.storage = make(map[string]*ethutil.Value)
c.gasPool = new(big.Int)