aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_object.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-06-17 17:06:06 +0800
committerobscuren <geffobscura@gmail.com>2014-06-17 17:06:06 +0800
commit53e30f750dd0c91279bfebe01bb12fd170cb74ff (patch)
treeb14fcd5845ce21c774ae7730bdd1d42f8836e5a2 /ethchain/state_object.go
parent6656f99c54aef4aaf03ba76dcab3df1cc363ab9a (diff)
downloadgo-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.gz
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.tar.zst
go-tangerine-53e30f750dd0c91279bfebe01bb12fd170cb74ff.zip
Removal of manual updating of state objects
* You'll only ever need to update the state by calling Update. Update will take care of the updating of it's child state objects.
Diffstat (limited to 'ethchain/state_object.go')
-rw-r--r--ethchain/state_object.go26
1 files changed, 15 insertions, 11 deletions
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 1445bcd82..5fc738fee 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -4,8 +4,15 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethutil"
"math/big"
+ "strings"
)
+type Code []byte
+
+func (self Code) String() string {
+ return strings.Join(Disassemble(self), " ")
+}
+
type StateObject struct {
// Address of the object
address []byte
@@ -15,8 +22,8 @@ type StateObject struct {
Nonce uint64
// Contract related attributes
state *State
- script []byte
- initScript []byte
+ script Code
+ initScript Code
// Total gas pool is the total amount of gas currently
// left if this object is the coinbase. Gas is directly
@@ -30,12 +37,9 @@ func MakeContract(tx *Transaction, state *State) *StateObject {
if tx.IsContract() {
addr := tx.CreationAddress()
- value := tx.Value
- contract := NewContract(addr, value, ZeroHash256)
-
+ contract := state.NewStateObject(addr)
contract.initScript = tx.Data
-
- state.UpdateStateObject(contract)
+ contract.state = NewState(ethutil.NewTrie(ethutil.Config.Db, ""))
return contract
}
@@ -120,13 +124,13 @@ func (c *StateObject) ReturnGas(gas, price *big.Int, state *State) {
func (c *StateObject) AddAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Add(c.Amount, amount))
- ethutil.Config.Log.Printf(ethutil.LogLevelSystem, "%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "%x: #%d %v (+ %v)\n", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SubAmount(amount *big.Int) {
c.SetAmount(new(big.Int).Sub(c.Amount, amount))
- ethutil.Config.Log.Printf(ethutil.LogLevelSystem, "%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Amount, amount)
+ ethutil.Config.Log.Printf(ethutil.LogLevelInfo, "%x: #%d %v (- %v)\n", c.Address(), c.Nonce, c.Amount, amount)
}
func (c *StateObject) SetAmount(amount *big.Int) {
@@ -197,12 +201,12 @@ func (c *StateObject) Address() []byte {
}
// Returns the main script body
-func (c *StateObject) Script() []byte {
+func (c *StateObject) Script() Code {
return c.script
}
// Returns the initialization script
-func (c *StateObject) Init() []byte {
+func (c *StateObject) Init() Code {
return c.initScript
}