From 3173bf345e84c3a2604f22478ef8e5b9ad26a61e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 12 Oct 2021 17:39:35 +0300 Subject: [PATCH] [#907] morph/event: Implement Op to string converter Implement `StringFromOpcode` function that tries to retrieve `string` to `Op`. Add a comment about neo-go source code that is used for implementation of converters. Signed-off-by: Leonard Lyubich --- pkg/morph/event/opcodes.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/morph/event/opcodes.go b/pkg/morph/event/opcodes.go index 7548ac974..3385c2eac 100644 --- a/pkg/morph/event/opcodes.go +++ b/pkg/morph/event/opcodes.go @@ -25,6 +25,8 @@ func (o Op) Param() []byte { return o.param } +// Below are the functions which reverse the results of github.com/nspcc-dev/neo-go/pkg/vm/emit.Array function. + // BytesFromOpcode tries to retrieve bytes from Op. func BytesFromOpcode(op Op) ([]byte, error) { switch code := op.Code(); code { @@ -48,3 +50,10 @@ func IntFromOpcode(op Op) (int64, error) { return 0, fmt.Errorf("unexpected INT opcode %s", code) } } + +// StringFromOpcode tries to retrieve string from Op. +func StringFromOpcode(op Op) (string, error) { + // strings are emitted like bytes + data, err := BytesFromOpcode(op) + return string(data), err +}