aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/state_manager.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-25 21:13:54 +0800
committerobscuren <geffobscura@gmail.com>2014-05-25 21:13:54 +0800
commit81ef40010f6f31bc94f654048b41fa3a9f9e07eb (patch)
tree6ce0d9cd254a284fedf9abda8553374cc336e15b /ethchain/state_manager.go
parent99fa9afaf15ceecffcc5b7051ffe9c7f0d179dec (diff)
downloadgo-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar.gz
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar.bz2
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar.lz
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar.xz
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.tar.zst
go-tangerine-81ef40010f6f31bc94f654048b41fa3a9f9e07eb.zip
The body of contracts are now returned instead
Diffstat (limited to 'ethchain/state_manager.go')
-rw-r--r--ethchain/state_manager.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index 4f009b6d3..2d2a32e2f 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -120,16 +120,27 @@ func (sm *StateManager) ApplyTransactions(state *State, block *Block, txs []*Tra
}
func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transaction) (*big.Int, error) {
- // 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.
- // TODO COMMENT THIS SECTION
+ /*
+ Applies transactions to the given state and creates new
+ state objects where needed.
+
+ If said objects needs to be created
+ run the initialization script provided by the transaction and
+ assume there's a return value. The return value will be set to
+ the script section of the state object.
+ */
totalGasUsed := big.NewInt(0)
- if tx.IsContract() {
- err := sm.Ethereum.TxPool().ProcessTransaction(tx, state, false)
+ // Apply the transaction to the current state
+ err := sm.Ethereum.TxPool().ProcessTransaction(tx, state, false)
+ if tx.CreatesContract() {
if err == nil {
+ // Create a new state object and the transaction
+ // as it's data provider.
contract := sm.MakeStateObject(state, tx)
if contract != nil {
+ // Evaluate the initialization script
+ // and use the return value as the
+ // script section for the state object.
script, err := sm.EvalScript(state, contract.Init(), contract, tx, block)
if err != nil {
return nil, fmt.Errorf("[STATE] Error during init script run %v", err)
@@ -143,10 +154,11 @@ func (sm *StateManager) ApplyTransaction(state *State, block *Block, tx *Transac
return nil, fmt.Errorf("[STATE] contract creation tx:", err)
}
} else {
- err := sm.Ethereum.TxPool().ProcessTransaction(tx, state, false)
- contract := state.GetStateObject(tx.Recipient)
- if err == nil && contract != nil && len(contract.Script()) > 0 {
- sm.EvalScript(state, contract.Script(), contract, tx, block)
+ // Find the state object at the "recipient" address. If
+ // there's an object attempt to run the script.
+ stateObject := state.GetStateObject(tx.Recipient)
+ if err == nil && stateObject != nil && len(stateObject.Script()) > 0 {
+ sm.EvalScript(state, stateObject.Script(), stateObject, tx, block)
} else if err != nil {
return nil, fmt.Errorf("[STATE] process:", err)
}