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.
This commit is contained in:
Evgeniy Stratonikov 2021-03-05 10:43:08 +03:00
parent e66d36900c
commit 7160675ac1
3 changed files with 9 additions and 4 deletions

View file

@ -18,7 +18,7 @@ var (
// Custom builtin utility functions. // Custom builtin utility functions.
customBuiltins = []string{ customBuiltins = []string{
"FromAddress", "Equals", "Remove", "FromAddress", "Equals", "Remove",
"ToBool", "ToByteArray", "ToInteger", "ToBool", "ToBytes", "ToString", "ToInteger",
} }
) )

View file

@ -17,7 +17,7 @@ func getFunctionName(typ string) string {
case "bool": case "bool":
return "Bool" return "Bool"
case "[]byte": case "[]byte":
return "ByteArray" return "Bytes"
case "int": case "int":
return "Integer" return "Integer"
} }

View file

@ -6,11 +6,16 @@ func ToInteger(v interface{}) int {
return v.(int) return v.(int)
} }
// ToByteArray converts it's argument to a ByteArray. // ToBytes converts it's argument to a Buffer VM type.
func ToByteArray(v interface{}) []byte { func ToBytes(v interface{}) []byte {
return v.([]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. // ToBool converts it's argument to a Boolean.
func ToBool(v interface{}) bool { func ToBool(v interface{}) bool {
return v.(bool) return v.(bool)