From cfa0c133229ef7cc7610b54949eaa53fa54fe40a Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Tue, 1 Oct 2019 20:11:01 +0300 Subject: [PATCH] vm: add InteropItem type for interop data This is an opaque data item that is to be used by the interop functions. --- pkg/vm/stack.go | 2 ++ pkg/vm/stack_item.go | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/pkg/vm/stack.go b/pkg/vm/stack.go index e0987637d..86f652166 100644 --- a/pkg/vm/stack.go +++ b/pkg/vm/stack.go @@ -92,6 +92,8 @@ func (e *Element) Bool() bool { } } return false + case *InteropItem: + return t.value != nil default: panic("can't convert to bool: " + t.String()) } diff --git a/pkg/vm/stack_item.go b/pkg/vm/stack_item.go index 9389178f8..b00d32383 100644 --- a/pkg/vm/stack_item.go +++ b/pkg/vm/stack_item.go @@ -248,3 +248,30 @@ func toMapKey(key StackItem) interface{} { panic("wrong key type") } } + +// InteropItem represents interop data on the stack. +type InteropItem struct { + value interface{} +} + +// NewInteropItem returns new InteropItem object. +func NewInteropItem(value interface{}) *InteropItem { + return &InteropItem{ + value: value, + } +} + +// Value implements StackItem interface. +func (i *InteropItem) Value() interface{} { + return i.value +} + +// String implements stringer interface. +func (i *InteropItem) String() string { + return "InteropItem" +} + +// MarshalJSON implements the json.Marshaler interface. +func (i *InteropItem) MarshalJSON() ([]byte, error) { + return json.Marshal(i.value) +}