aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_manager.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-23 17:51:04 +0800
committerobscuren <geffobscura@gmail.com>2014-04-23 17:51:04 +0800
commit3a9a252f6e44abb0f45f57a46c0fa91e2f73c545 (patch)
tree677575939c8f22c30a9601c205450a0d5b98c3ab /ethchain/state_manager.go
parent61cd1594b52514244efcb47bd93722aaec0fe456 (diff)
downloaddexon-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.tar.gz
dexon-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.tar.zst
dexon-3a9a252f6e44abb0f45f57a46c0fa91e2f73c545.zip
Fixed minor issue with gas and added state object init
Diffstat (limited to 'ethchain/state_manager.go')
-rw-r--r--ethchain/state_manager.go53
1 files changed, 46 insertions, 7 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 75a78e9f3..23da77fae 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -91,11 +91,15 @@ func (sm *StateManager) BlockChain() *BlockChain {
return sm.bc
}
-func (sm *StateManager) MakeContract(tx *Transaction) {
+func (sm *StateManager) MakeContract(tx *Transaction) *StateObject {
contract := MakeContract(tx, sm.procState)
if contract != nil {
sm.procState.states[string(tx.Hash()[12:])] = contract.state
+
+ return contract
}
+
+ return nil
}
// Apply transactions uses the transaction passed to it and applies them onto
@@ -103,11 +107,44 @@ func (sm *StateManager) MakeContract(tx *Transaction) {
func (sm *StateManager) ApplyTransactions(block *Block, txs []*Transaction) {
// Process each transaction/contract
for _, tx := range txs {
+ fmt.Printf("Processing Tx: %x\n", tx.Hash())
+ // If there's no recipient, it's a contract
+ // Check if this is a contract creation traction and if so
+ // create a contract of this tx.
+ if tx.IsContract() {
+ err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
+ if err == nil {
+ contract := sm.MakeContract(tx)
+ if contract != nil {
+ sm.EvalScript(contract.Init(), contract, tx, block)
+ } else {
+ ethutil.Config.Log.Infoln("[STATE] Unable to create contract")
+ }
+ } else {
+ ethutil.Config.Log.Infoln("[STATE] contract create:", err)
+ }
+ } else {
+ err := sm.Ethereum.TxPool().ProcessTransaction(tx, block, false)
+ contract := sm.procState.GetContract(tx.Recipient)
+ if err == nil && len(contract.Script()) > 0 {
+ sm.EvalScript(contract.Script(), contract, tx, block)
+ } else if err != nil {
+ ethutil.Config.Log.Infoln("[STATE] process:", err)
+ }
+ }
+ }
+ // Process each transaction/contract
+ for _, tx := range txs {
// If there's no recipient, it's a contract
// Check if this is a contract creation traction and if so
// create a contract of this tx.
if tx.IsContract() {
- sm.MakeContract(tx)
+ contract := sm.MakeContract(tx)
+ if contract != nil {
+ sm.EvalScript(contract.Init(), contract, tx, block)
+ } else {
+ ethutil.Config.Log.Infoln("[STATE] Unable to create contract")
+ }
} else {
// Figure out if the address this transaction was sent to is a
// contract or an actual account. In case of a contract, we process that
@@ -303,11 +340,13 @@ func (sm *StateManager) Stop() {
func (sm *StateManager) EvalScript(script []byte, object *StateObject, tx *Transaction, block *Block) {
// Recovering function in case the VM had any errors
- defer func() {
- if r := recover(); r != nil {
- fmt.Println("Recovered from VM execution with err =", r)
- }
- }()
+ /*
+ defer func() {
+ if r := recover(); r != nil {
+ fmt.Println("Recovered from VM execution with err =", r)
+ }
+ }()
+ */
caller := sm.procState.GetAccount(tx.Sender())
closure := NewClosure(caller, object, script, sm.procState, tx.Gas, tx.GasPrice, tx.Value)