diff options
author | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-11-03 18:47:07 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2015-11-03 18:47:07 +0800 |
commit | e5532154a50114d5ffb1ffd850b746cab00cb899 (patch) | |
tree | 0042cc997ccf4166b9b52464339d52d37d7a8ad6 /core/vm_env.go | |
parent | 9666db2a442887ccf8ec2d81f5e2fedc1a3a3d3e (diff) | |
parent | f75becc264f8bde0f58391fc226243d03e78aa7b (diff) | |
download | go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.gz go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.bz2 go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.lz go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.xz go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.tar.zst go-tangerine-e5532154a50114d5ffb1ffd850b746cab00cb899.zip |
Merge branch 'release/1.3.0'
Conflicts:
VERSION
cmd/geth/main.go
Diffstat (limited to 'core/vm_env.go')
-rw-r--r-- | core/vm_env.go | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/core/vm_env.go b/core/vm_env.go index a08f024fe..c8b50debc 100644 --- a/core/vm_env.go +++ b/core/vm_env.go @@ -30,13 +30,13 @@ type VMEnv struct { header *types.Header msg Message depth int - chain *ChainManager + chain *BlockChain typ vm.Type // structured logging logs []vm.StructLog } -func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, header *types.Header) *VMEnv { +func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header) *VMEnv { return &VMEnv{ chain: chain, state: state, @@ -53,43 +53,49 @@ func (self *VMEnv) Time() *big.Int { return self.header.Time } func (self *VMEnv) Difficulty() *big.Int { return self.header.Difficulty } func (self *VMEnv) GasLimit() *big.Int { return self.header.GasLimit } func (self *VMEnv) Value() *big.Int { return self.msg.Value() } -func (self *VMEnv) State() *state.StateDB { return self.state } +func (self *VMEnv) Db() vm.Database { return self.state } func (self *VMEnv) Depth() int { return self.depth } func (self *VMEnv) SetDepth(i int) { self.depth = i } func (self *VMEnv) VmType() vm.Type { return self.typ } func (self *VMEnv) SetVmType(t vm.Type) { self.typ = t } func (self *VMEnv) GetHash(n uint64) common.Hash { - if block := self.chain.GetBlockByNumber(n); block != nil { - return block.Hash() + for block := self.chain.GetBlock(self.header.ParentHash); block != nil; block = self.chain.GetBlock(block.ParentHash()) { + if block.NumberU64() == n { + return block.Hash() + } } return common.Hash{} } -func (self *VMEnv) AddLog(log *state.Log) { +func (self *VMEnv) AddLog(log *vm.Log) { self.state.AddLog(log) } -func (self *VMEnv) CanTransfer(from vm.Account, balance *big.Int) bool { - return from.Balance().Cmp(balance) >= 0 +func (self *VMEnv) CanTransfer(from common.Address, balance *big.Int) bool { + return self.state.GetBalance(from).Cmp(balance) >= 0 } -func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { - return vm.Transfer(from, to, amount) +func (self *VMEnv) MakeSnapshot() vm.Database { + return self.state.Copy() } -func (self *VMEnv) Call(me vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { - exe := NewExecution(self, &addr, data, gas, price, value) - return exe.Call(addr, me) +func (self *VMEnv) SetSnapshot(copy vm.Database) { + self.state.Set(copy.(*state.StateDB)) } -func (self *VMEnv) CallCode(me vm.ContextRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { - maddr := me.Address() - exe := NewExecution(self, &maddr, data, gas, price, value) - return exe.Call(addr, me) + +func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) { + Transfer(from, to, amount) +} + +func (self *VMEnv) Call(me vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { + return Call(self, me, addr, data, gas, price, value) +} +func (self *VMEnv) CallCode(me vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { + return CallCode(self, me, addr, data, gas, price, value) } -func (self *VMEnv) Create(me vm.ContextRef, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) { - exe := NewExecution(self, nil, data, gas, price, value) - return exe.Create(me) +func (self *VMEnv) Create(me vm.ContractRef, data []byte, gas, price, value *big.Int) ([]byte, common.Address, error) { + return Create(self, me, data, gas, price, value) } func (self *VMEnv) StructLogs() []vm.StructLog { |