[#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 <leonard@nspcc.ru>
remotes/fyrchik/container-alias-fee
Leonard Lyubich 2021-10-12 17:39:35 +03:00 committed by Alex Vanin
parent 123328a2f4
commit 3173bf345e
1 changed files with 9 additions and 0 deletions

View File

@ -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
}