From e50b5296312c09e05b22c3a01a2d692fb60e6442 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 23 Mar 2020 11:50:03 +0300 Subject: [PATCH] vm: implement Null item --- pkg/vm/stack_item.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/pkg/vm/stack_item.go b/pkg/vm/stack_item.go index 6cfd772f3..3500281bd 100644 --- a/pkg/vm/stack_item.go +++ b/pkg/vm/stack_item.go @@ -185,6 +185,44 @@ func (i *StructItem) Clone() *StructItem { return ret } +// NullItem represents null on the stack. +type NullItem struct{} + +// String implements StackItem interface. +func (i NullItem) String() string { + return "Null" +} + +// Value implements StackItem interface. +func (i NullItem) Value() interface{} { + return nil +} + +// Dup implements StackItem interface. +// There is no need to perform a real copy here, +// as NullItem has no internal state. +func (i NullItem) Dup() StackItem { + return i +} + +// TryBytes implements StackItem interface. +func (i NullItem) TryBytes() ([]byte, error) { + return nil, errors.New("can't convert Null to ByteArray") +} + +// Equals implements StackItem interface. +func (i NullItem) Equals(s StackItem) bool { + _, ok := s.(NullItem) + return ok +} + +// ToContractParameter implements StackItem interface. +func (i NullItem) ToContractParameter(map[StackItem]bool) smartcontract.Parameter { + return smartcontract.Parameter{ + Type: smartcontract.AnyType, + } +} + // BigIntegerItem represents a big integer on the stack. type BigIntegerItem struct { value *big.Int