aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/closure.go
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain/closure.go')
-rw-r--r--ethchain/closure.go25
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
}