aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/closure.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-04-10 00:27:54 +0800
committerobscuren <geffobscura@gmail.com>2014-04-10 00:27:54 +0800
commite09f0a5f2c1e1b46226656dbac9a4ae10e0dcd14 (patch)
tree7b1ce2f5cd83e3a345cf26230afd41e48110e015 /ethchain/closure.go
parent4f2e9c2640eaa962d085db329221bfd6f1a1799e (diff)
downloadgo-tangerine-e09f0a5f2c1e1b46226656dbac9a4ae10e0dcd14.tar.gz
go-tangerine-e09f0a5f2c1e1b46226656dbac9a4ae10e0dcd14.tar.zst
go-tangerine-e09f0a5f2c1e1b46226656dbac9a4ae10e0dcd14.zip
Split code for contracts
Diffstat (limited to 'ethchain/closure.go')
-rw-r--r--ethchain/closure.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/ethchain/closure.go b/ethchain/closure.go
index e9cb2c8bc..d1fac0f43 100644
--- a/ethchain/closure.go
+++ b/ethchain/closure.go
@@ -12,18 +12,18 @@ type Callee interface {
Address() []byte
}
-type ClosureBody interface {
+type Reference interface {
Callee
ethutil.RlpEncodable
GetMem(*big.Int) *ethutil.Value
SetMem(*big.Int, *ethutil.Value)
- GetInstr(*big.Int) *ethutil.Value
}
// 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
@@ -33,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
@@ -47,8 +47,14 @@ func (c *Closure) GetMem(x *big.Int) *ethutil.Value {
return m
}
-func (c *Closure) GetInstr(x *big.Int) *ethutil.Value {
- return c.object.GetInstr(x)
+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 {
+ partial := c.Script[x.Int64() : x.Int64()+y.Int64()]
+
+ return ethutil.NewValue(partial)
}
func (c *Closure) SetMem(x *big.Int, val *ethutil.Value) {
@@ -86,7 +92,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
}