From e29b85d0d760e09b3a653bba55285d049cfc4673 Mon Sep 17 00:00:00 2001 From: BlockChainDev Date: Wed, 27 Feb 2019 20:50:00 +0000 Subject: [PATCH] VM:Add abstract stack item --- pkg/vm/stack/stackitem.go | 42 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 pkg/vm/stack/stackitem.go diff --git a/pkg/vm/stack/stackitem.go b/pkg/vm/stack/stackitem.go new file mode 100644 index 000000000..9f29f9d3b --- /dev/null +++ b/pkg/vm/stack/stackitem.go @@ -0,0 +1,42 @@ +package stack + +import ( + "errors" +) + +//Item is an interface which represents object that can be placed on the stack +type Item interface { + Integer() (*Int, error) + Boolean() (*Boolean, error) + ByteArray() (*ByteArray, error) + Array() (*Array, error) +} + +// Represents an `abstract` stack item +// which will hold default values for stack items +// this is intended to be embedded into types that you will use on the stack +type abstractItem struct{} + +// Integer is the default implementation for a stackItem +// Implements Item interface +func (a *abstractItem) Integer() (*Int, error) { + return nil, errors.New("This stack item is not an Integer") +} + +// Boolean is the default implementation for a stackItem +// Implements Item interface +func (a *abstractItem) Boolean() (*Boolean, error) { + return nil, errors.New("This stack item is not a Boolean") +} + +// ByteArray is the default implementation for a stackItem +// Implements Item interface +func (a *abstractItem) ByteArray() (*ByteArray, error) { + return nil, errors.New("This stack item is not a byte array") +} + +// Array is the default implementation for a stackItem +// Implements Item interface +func (a *abstractItem) Array() (*Array, error) { + return nil, errors.New("This stack item is not an array") +}