diff options
author | obscuren <geffobscura@gmail.com> | 2014-04-11 09:05:58 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-04-11 09:05:58 +0800 |
commit | 7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0 (patch) | |
tree | b529de034a77da5a4a35526eb4800863ddf1fbdb /ethchain/closure.go | |
parent | d927c154e77027924756d3538139ce0910b1c23a (diff) | |
parent | 25dd46061fc3b732056ea87fe4a9696e160179cc (diff) | |
download | go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.gz go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.bz2 go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.lz go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.xz go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.tar.zst go-tangerine-7d6ba88d2b4a263f2a898c3ef6d40e5258f96bb0.zip |
Merge branch 'split' into develop
Diffstat (limited to 'ethchain/closure.go')
-rw-r--r-- | ethchain/closure.go | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/ethchain/closure.go b/ethchain/closure.go index 2e809aa9d..8e57a0d03 100644 --- a/ethchain/closure.go +++ b/ethchain/closure.go @@ -12,7 +12,7 @@ type Callee interface { Address() []byte } -type ClosureBody interface { +type Reference interface { Callee ethutil.RlpEncodable GetMem(*big.Int) *ethutil.Value @@ -22,7 +22,8 @@ type ClosureBody interface { // Basic inline closure object which implement the 'closure' interface type Closure struct { callee Callee - object ClosureBody + object Reference + Script []byte State *State Gas *big.Int @@ -32,8 +33,8 @@ type Closure struct { } // Create a new closure for the given data items -func NewClosure(callee Callee, object ClosureBody, state *State, gas, val *big.Int) *Closure { - return &Closure{callee, object, state, gas, val, nil} +func NewClosure(callee Callee, object Reference, script []byte, state *State, gas, val *big.Int) *Closure { + return &Closure{callee, object, script, state, gas, val, nil} } // Retuns the x element in data slice @@ -46,6 +47,20 @@ func (c *Closure) GetMem(x *big.Int) *ethutil.Value { return m } +func (c *Closure) Get(x *big.Int) *ethutil.Value { + return c.Gets(x, big.NewInt(1)) +} + +func (c *Closure) Gets(x, y *big.Int) *ethutil.Value { + if x.Int64() > int64(len(c.Script)) || y.Int64() > int64(len(c.Script)) { + return ethutil.NewValue(0) + } + + partial := c.Script[x.Int64() : x.Int64()+y.Int64()] + + return ethutil.NewValue(partial) +} + func (c *Closure) SetMem(x *big.Int, val *ethutil.Value) { c.object.SetMem(x, val) } @@ -81,7 +96,7 @@ func (c *Closure) ReturnGas(gas *big.Int, state *State) { c.Gas.Add(c.Gas, gas) } -func (c *Closure) Object() ClosureBody { +func (c *Closure) Object() Reference { return c.object } |