aboutsummaryrefslogtreecommitdiffstats
path: root/core/state_processor.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2016-12-06 09:16:03 +0800
committerFelix Lange <fjl@twurst.com>2016-12-06 09:16:03 +0800
commit3fc7c978277051391f8ea7831559e9f4f83c3166 (patch)
treeb11b41c1723e02adc098ddc9f4188a8bad782ed8 /core/state_processor.go
parent7f79d249a64ee72b185ffa9a9ed78f137b7938de (diff)
downloaddexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.gz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.bz2
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.lz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.xz
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.tar.zst
dexon-3fc7c978277051391f8ea7831559e9f4f83c3166.zip
core, core/vm: implemented a generic environment (#3348)
Environment is now a struct (not an interface). This reduces a lot of tech-debt throughout the codebase where a virtual machine environment had to be implemented in order to test or run it. The new environment is suitable to be used en the json tests, core consensus and light client.
Diffstat (limited to 'core/state_processor.go')
-rw-r--r--core/state_processor.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/core/state_processor.go b/core/state_processor.go
index e346917c3..67a7ad5a1 100644
--- a/core/state_processor.go
+++ b/core/state_processor.go
@@ -96,28 +96,36 @@ func ApplyTransaction(config *params.ChainConfig, bc *BlockChain, gp *GasPool, s
if err != nil {
return nil, nil, nil, err
}
-
- _, gas, err := ApplyMessage(NewEnv(statedb, config, bc, msg, header, cfg), msg, gp)
+ // Create a new context to be used in the EVM environment
+ context := NewEVMContext(msg, header, bc)
+ // Create a new environment which holds all relevant information
+ // about the transaction and calling mechanisms.
+ vmenv := vm.NewEnvironment(context, statedb, config, vm.Config{})
+ // Apply the transaction to the current state (included in the env)
+ _, gas, err := ApplyMessage(vmenv, msg, gp)
if err != nil {
return nil, nil, nil, err
}
// Update the state with pending changes
usedGas.Add(usedGas, gas)
+ // Create a new receipt for the transaction, storing the intermediate root and gas used by the tx
+ // based on the eip phase, we're passing wether the root touch-delete accounts.
receipt := types.NewReceipt(statedb.IntermediateRoot(config.IsEIP158(header.Number)).Bytes(), usedGas)
receipt.TxHash = tx.Hash()
receipt.GasUsed = new(big.Int).Set(gas)
- if MessageCreatesContract(msg) {
- receipt.ContractAddress = crypto.CreateAddress(msg.From(), tx.Nonce())
+ // if the transaction created a contract, store the creation address in the receipt.
+ if msg.To() == nil {
+ receipt.ContractAddress = crypto.CreateAddress(vmenv.Context.Origin, tx.Nonce())
}
- logs := statedb.GetLogs(tx.Hash())
- receipt.Logs = logs
+ // Set the receipt logs and create a bloom for filtering
+ receipt.Logs = statedb.GetLogs(tx.Hash())
receipt.Bloom = types.CreateBloom(types.Receipts{receipt})
glog.V(logger.Debug).Infoln(receipt)
- return receipt, logs, gas, err
+ return receipt, receipt.Logs, gas, err
}
// AccumulateRewards credits the coinbase of the given block with the