From 7160675ac117cc72b436493704667959d9f3c0c6 Mon Sep 17 00:00:00 2001 From: Evgeniy Stratonikov Date: Fri, 5 Mar 2021 10:43:08 +0300 Subject: [PATCH] compiler/interop: improve conversion to bytes interops Allow to convert to both `Buffer` and `ByteString` and explicitly mention VM types. Rename `ToByteArray` to `ToBytes` to avoid ambiguity. --- pkg/compiler/analysis.go | 2 +- pkg/compiler/convert_test.go | 2 +- pkg/interop/convert/convert.go | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pkg/compiler/analysis.go b/pkg/compiler/analysis.go index d95778773..b95139510 100644 --- a/pkg/compiler/analysis.go +++ b/pkg/compiler/analysis.go @@ -18,7 +18,7 @@ var ( // Custom builtin utility functions. customBuiltins = []string{ "FromAddress", "Equals", "Remove", - "ToBool", "ToByteArray", "ToInteger", + "ToBool", "ToBytes", "ToString", "ToInteger", } ) diff --git a/pkg/compiler/convert_test.go b/pkg/compiler/convert_test.go index c50e11d75..61abb068a 100644 --- a/pkg/compiler/convert_test.go +++ b/pkg/compiler/convert_test.go @@ -17,7 +17,7 @@ func getFunctionName(typ string) string { case "bool": return "Bool" case "[]byte": - return "ByteArray" + return "Bytes" case "int": return "Integer" } diff --git a/pkg/interop/convert/convert.go b/pkg/interop/convert/convert.go index e4c606a81..653f55ca1 100644 --- a/pkg/interop/convert/convert.go +++ b/pkg/interop/convert/convert.go @@ -6,11 +6,16 @@ func ToInteger(v interface{}) int { return v.(int) } -// ToByteArray converts it's argument to a ByteArray. -func ToByteArray(v interface{}) []byte { +// ToBytes converts it's argument to a Buffer VM type. +func ToBytes(v interface{}) []byte { return v.([]byte) } +// ToString converts it's argument to a ByteString VM type. +func ToString(v interface{}) string { + return v.(string) +} + // ToBool converts it's argument to a Boolean. func ToBool(v interface{}) bool { return v.(bool)