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.
customBuiltins = []string{
"FromAddress", "Equals", "Remove",
"ToBool", "ToByteArray", "ToInteger",
"ToBool", "ToBytes", "ToString", "ToInteger",
}
)

View file

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

View file

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