diff --git a/pkg/vm/stack.go b/pkg/vm/stack.go index fca28215b..659ff0191 100644 --- a/pkg/vm/stack.go +++ b/pkg/vm/stack.go @@ -162,13 +162,15 @@ func NewStack(n string) *Stack { } func newStack(n string, refc *refCounter) *Stack { - s := &Stack{ - name: n, - refs: refc, - } + s := new(Stack) + initStack(s, n, refc) + return s +} +func initStack(s *Stack, n string, refc *refCounter) { + s.name = n + s.refs = refc s.top.next = &s.top s.top.prev = &s.top - return s } // Clear clears all elements on the stack and set its length to 0. diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 9fe81d69d..4856270e4 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -68,7 +68,7 @@ type VM struct { // callback to get interop price getPrice func(opcode.Opcode, []byte) int64 - istack *Stack // invocation stack. + istack Stack // invocation stack. estack *Stack // execution stack. uncaughtException stackitem.Item // exception being handled @@ -99,7 +99,6 @@ func New() *VM { func NewWithTrigger(t trigger.Type) *VM { vm := &VM{ state: NoneState, - istack: newStack("invocation", nil), trigger: t, SyscallHandler: defaultSyscallHandler, @@ -107,6 +106,7 @@ func NewWithTrigger(t trigger.Type) *VM { } vm.refs.items = make(map[stackitem.Item]int) + initStack(&vm.istack, "invocation", nil) vm.estack = newStack("evaluation", &vm.refs) return vm } @@ -135,7 +135,7 @@ func (v *VM) Estack() *Stack { // Istack returns the invocation stack so interop hooks can utilize this. func (v *VM) Istack() *Stack { - return v.istack + return &v.istack } // LoadArgs loads in the arguments used in the Mian entry point. @@ -340,7 +340,7 @@ func (v *VM) PopResult() interface{} { func (v *VM) Stack(n string) string { var s *Stack if n == "istack" { - s = v.istack + s = &v.istack } if n == "estack" { s = v.estack @@ -1786,7 +1786,7 @@ func (v *VM) GetCallingScriptHash() util.Uint160 { // GetEntryScriptHash implements ScriptHashGetter interface. func (v *VM) GetEntryScriptHash() util.Uint160 { - return v.getContextScriptHash(v.Istack().Len() - 1) + return v.getContextScriptHash(v.istack.len - 1) } // GetCurrentScriptHash implements ScriptHashGetter interface.