Skip to content

Commit 4dc7ee9

Browse files
committed
Closure => Context
1 parent e2d1d83 commit 4dc7ee9

File tree

13 files changed

+107
-119
lines changed

13 files changed

+107
-119
lines changed

cmd/evm/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu
144144
return core.NewExecution(self, addr, data, gas, price, value)
145145
}
146146

147-
func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
147+
func (self *VMEnv) Call(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
148148
exe := self.vm(addr, data, gas, price, value)
149149
ret, err := exe.Call(addr, caller)
150150
self.Gas = exe.Gas
151151

152152
return ret, err
153153
}
154-
func (self *VMEnv) CallCode(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
154+
func (self *VMEnv) CallCode(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
155155
exe := self.vm(caller.Address(), data, gas, price, value)
156156
return exe.Call(addr, caller)
157157
}
158158

159-
func (self *VMEnv) Create(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) {
159+
func (self *VMEnv) Create(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
160160
exe := self.vm(addr, data, gas, price, value)
161161
return exe.Create(caller)
162162
}

cmd/utils/vm_env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *core.Execu
5252
return core.NewExecution(self, addr, data, gas, price, value)
5353
}
5454

55-
func (self *VMEnv) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
55+
func (self *VMEnv) Call(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
5656
exe := self.vm(addr, data, gas, price, value)
5757
ret, err := exe.Call(addr, caller)
5858
self.Gas = exe.Gas
5959

6060
return ret, err
6161
}
62-
func (self *VMEnv) CallCode(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
62+
func (self *VMEnv) CallCode(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
6363
exe := self.vm(caller.Address(), data, gas, price, value)
6464
return exe.Call(addr, caller)
6565
}
6666

67-
func (self *VMEnv) Create(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) {
67+
func (self *VMEnv) Create(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
6868
exe := self.vm(addr, data, gas, price, value)
6969
return exe.Create(caller)
7070
}

core/chain_manager.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,6 @@ type StateQuery interface {
2020
GetAccount(addr []byte) *state.StateObject
2121
}
2222

23-
/*
24-
func AddTestNetFunds(block *types.Block) {
25-
for _, addr := range []string{
26-
"51ba59315b3a95761d0863b05ccc7a7f54703d99",
27-
"e4157b34ea9615cfbde6b4fda419828124b70c78",
28-
"b9c015918bdaba24b4ff057a92a3873d6eb201be",
29-
"6c386a4b26f73c802f34673f7248bb118f97424a",
30-
"cd2a3d9f938e13cd947ec05abc7fe734df8dd826",
31-
"2ef47100e0787b915105fd5e3f4ff6752079d5cb",
32-
"e6716f9544a56c530d868e4bfbacb172315bdead",
33-
"1a26338f0d905e295fccb71fa9ea849ffa12aaf4",
34-
} {
35-
codedAddr := ethutil.Hex2Bytes(addr)
36-
account := block.State().GetAccount(codedAddr)
37-
account.SetBalance(ethutil.Big("1606938044258990275541962092341162602522202993782792835301376")) //ethutil.BigPow(2, 200)
38-
block.State().UpdateStateObject(account)
39-
}
40-
}
41-
*/
42-
4323
func CalcDifficulty(block, parent *types.Block) *big.Int {
4424
diff := new(big.Int)
4525

core/execution.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func (self *Execution) Addr() []byte {
2424
return self.address
2525
}
2626

27-
func (self *Execution) Call(codeAddr []byte, caller vm.ClosureRef) ([]byte, error) {
27+
func (self *Execution) Call(codeAddr []byte, caller vm.ContextRef) ([]byte, error) {
2828
// Retrieve the executing code
2929
code := self.env.State().GetCode(codeAddr)
3030

3131
return self.exec(code, codeAddr, caller)
3232
}
3333

34-
func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret []byte, err error) {
34+
func (self *Execution) exec(code, contextAddr []byte, caller vm.ContextRef) (ret []byte, err error) {
3535
env := self.env
3636
evm := vm.New(env, vm.DebugVmTy)
3737

@@ -63,7 +63,7 @@ func (self *Execution) exec(code, contextAddr []byte, caller vm.ClosureRef) (ret
6363
return
6464
}
6565

66-
func (self *Execution) Create(caller vm.ClosureRef) (ret []byte, err error, account *state.StateObject) {
66+
func (self *Execution) Create(caller vm.ContextRef) (ret []byte, err error, account *state.StateObject) {
6767
ret, err = self.exec(self.input, nil, caller)
6868
account = self.env.State().GetStateObject(self.address)
6969

core/state_transition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func (self *StateTransition) TransitionState() (ret []byte, err error) {
184184
}
185185

186186
vmenv := self.VmEnv()
187-
var ref vm.ClosureRef
187+
var ref vm.ContextRef
188188
if MessageCreatesContract(msg) {
189189
contract := MakeContract(msg, self.state)
190190
ret, err, ref = vmenv.Create(sender, contract.Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)

core/vm_env.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,16 @@ func (self *VMEnv) vm(addr, data []byte, gas, price, value *big.Int) *Execution
4646
return NewExecution(self, addr, data, gas, price, value)
4747
}
4848

49-
func (self *VMEnv) Call(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
49+
func (self *VMEnv) Call(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
5050
exe := self.vm(addr, data, gas, price, value)
5151
return exe.Call(addr, me)
5252
}
53-
func (self *VMEnv) CallCode(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
53+
func (self *VMEnv) CallCode(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
5454
exe := self.vm(me.Address(), data, gas, price, value)
5555
return exe.Call(addr, me)
5656
}
5757

58-
func (self *VMEnv) Create(me vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) {
58+
func (self *VMEnv) Create(me vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
5959
exe := self.vm(addr, data, gas, price, value)
6060
return exe.Create(me)
6161
}

tests/helper/vm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ func (self *Env) vm(addr, data []byte, gas, price, value *big.Int) *core.Executi
7474
return exec
7575
}
7676

77-
func (self *Env) Call(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
77+
func (self *Env) Call(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
7878
exe := self.vm(addr, data, gas, price, value)
7979
ret, err := exe.Call(addr, caller)
8080
self.Gas = exe.Gas
8181

8282
return ret, err
8383
}
84-
func (self *Env) CallCode(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
84+
func (self *Env) CallCode(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error) {
8585
exe := self.vm(caller.Address(), data, gas, price, value)
8686
return exe.Call(addr, caller)
8787
}
8888

89-
func (self *Env) Create(caller vm.ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ClosureRef) {
89+
func (self *Env) Create(caller vm.ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, vm.ContextRef) {
9090
exe := self.vm(addr, data, gas, price, value)
9191
return exe.Create(caller)
9292
}

vm/closure.go renamed to vm/context.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ import (
88
"github.com/ethereum/go-ethereum/state"
99
)
1010

11-
type ClosureRef interface {
11+
type ContextRef interface {
1212
ReturnGas(*big.Int, *big.Int)
1313
Address() []byte
1414
SetCode([]byte)
1515
}
1616

17-
type Closure struct {
18-
caller ClosureRef
19-
object ClosureRef
17+
type Context struct {
18+
caller ContextRef
19+
object ContextRef
2020
Code []byte
2121
message *state.Message
2222

@@ -25,9 +25,9 @@ type Closure struct {
2525
Args []byte
2626
}
2727

28-
// Create a new closure for the given data items
29-
func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code []byte, gas, price *big.Int) *Closure {
30-
c := &Closure{message: msg, caller: caller, object: object, Code: code, Args: nil}
28+
// Create a new context for the given data items
29+
func NewContext(msg *state.Message, caller ContextRef, object ContextRef, code []byte, gas, price *big.Int) *Context {
30+
c := &Context{message: msg, caller: caller, object: object, Code: code, Args: nil}
3131

3232
// Gas should be a pointer so it can safely be reduced through the run
3333
// This pointer will be off the state transition
@@ -40,30 +40,30 @@ func NewClosure(msg *state.Message, caller ClosureRef, object ClosureRef, code [
4040
return c
4141
}
4242

43-
func (c *Closure) GetOp(x uint64) OpCode {
43+
func (c *Context) GetOp(x uint64) OpCode {
4444
return OpCode(c.GetByte(x))
4545
}
4646

47-
func (c *Closure) GetByte(x uint64) byte {
47+
func (c *Context) GetByte(x uint64) byte {
4848
if x < uint64(len(c.Code)) {
4949
return c.Code[x]
5050
}
5151

5252
return 0
5353
}
5454

55-
func (c *Closure) GetBytes(x, y int) []byte {
55+
func (c *Context) GetBytes(x, y int) []byte {
5656
return c.GetRangeValue(uint64(x), uint64(y))
5757
}
5858

59-
func (c *Closure) GetRangeValue(x, size uint64) []byte {
59+
func (c *Context) GetRangeValue(x, size uint64) []byte {
6060
x = uint64(math.Min(float64(x), float64(len(c.Code))))
6161
y := uint64(math.Min(float64(x+size), float64(len(c.Code))))
6262

6363
return ethutil.LeftPadBytes(c.Code[x:y], int(size))
6464
}
6565

66-
func (c *Closure) Return(ret []byte) []byte {
66+
func (c *Context) Return(ret []byte) []byte {
6767
// Return the remaining gas to the caller
6868
c.caller.ReturnGas(c.Gas, c.Price)
6969

@@ -73,7 +73,7 @@ func (c *Closure) Return(ret []byte) []byte {
7373
/*
7474
* Gas functions
7575
*/
76-
func (c *Closure) UseGas(gas *big.Int) bool {
76+
func (c *Context) UseGas(gas *big.Int) bool {
7777
if c.Gas.Cmp(gas) < 0 {
7878
return false
7979
}
@@ -86,19 +86,19 @@ func (c *Closure) UseGas(gas *big.Int) bool {
8686
}
8787

8888
// Implement the caller interface
89-
func (c *Closure) ReturnGas(gas, price *big.Int) {
90-
// Return the gas to the closure
89+
func (c *Context) ReturnGas(gas, price *big.Int) {
90+
// Return the gas to the context
9191
c.Gas.Add(c.Gas, gas)
9292
c.UsedGas.Sub(c.UsedGas, gas)
9393
}
9494

9595
/*
9696
* Set / Get
9797
*/
98-
func (c *Closure) Address() []byte {
98+
func (c *Context) Address() []byte {
9999
return c.object.Address()
100100
}
101101

102-
func (self *Closure) SetCode(code []byte) {
102+
func (self *Context) SetCode(code []byte) {
103103
self.Code = code
104104
}

vm/environment.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type Environment interface {
2626
Depth() int
2727
SetDepth(i int)
2828

29-
Call(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
30-
CallCode(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
31-
Create(me ClosureRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, ClosureRef)
29+
Call(me ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
30+
CallCode(me ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error)
31+
Create(me ContextRef, addr, data []byte, gas, price, value *big.Int) ([]byte, error, ContextRef)
3232
}
3333

3434
type Object interface {

vm/virtual_machine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "math/big"
44

55
type VirtualMachine interface {
66
Env() Environment
7-
Run(me, caller ClosureRef, code []byte, value, gas, price *big.Int, data []byte) ([]byte, error)
7+
Run(me, caller ContextRef, code []byte, value, gas, price *big.Int, data []byte) ([]byte, error)
88
Printf(string, ...interface{}) VirtualMachine
99
Endl() VirtualMachine
1010
}

0 commit comments

Comments
 (0)