# [Ride v4 and v3] Converting functions
⚠️ This is the documentation for the Standard library version 4 and 3. We recommend to use version 6. Go to version 6
Name | Description | Complexity |
---|---|---|
addressFromPublicKey(ByteVector): Address | Gets the corresponding address of the account public key | 82 for Standard Library version 3 63 for Standard Library version 4 |
parseInt(String): Int|Unit | Converts the string representation of a number to its integer equivalent | 20 for Standard Library version 3 2 for Standard Library version 4 |
parseIntValue(String): Int | Converts the string representation of a number to its integer equivalent. Fails if the string cannot be parsed | 20 for Standard Library version 3 2 for Standard Library version 4 |
toBytes(Boolean): ByteVector | Converts a boolean value to an array of bytes | 1 |
toBytes(Int): ByteVector | Converts an integer to an array of bytes | 1 |
toBytes(String): ByteVector | Converts a string to an array of bytes | 1 for Standard Library version 3 8 for Standard Library version 4 |
toInt(ByteVector): Int | Converts an array of bytes to an integer | 10 for Standard Library version 3 1 for Standard Library version 4 |
toInt(ByteVector, Int): Int | Converts an array of bytes to an integer starting from a certain index | 10 for Standard Library version 3 1 for Standard Library version 4 |
toString(Address): String | Converts an array of bytes of an address to a string | 10 |
toString(Boolean): String | Converts a boolean value to a string | 1 |
toString(Int): String | Converts an integer to a string | 1 |
toUtf8String(ByteVector): String | Converts an array of bytes to a UTF-8 string | 20 for Standard Library version 3 7 for Standard Library version 4 |
transferTransactionFromProto(ByteVector): TransferTransaction|Unit | Deserializes transfer transaction | 5 |
# addressFromPublicKey(ByteVector): Address
Gets the corresponding address of the account public key.
There is no public key size check in version 5 and below.
addressFromPublicKey(publicKey: ByteVector): Address
For a description of the return value, see the Address article.
# Parameters
Parameter | Description |
---|---|
publicKey : ByteVector | Public key |
# Examples
let address = addressFromPublicKey(base58'J1t6NBs5Hd588Dn7mAPytqkhgeBshzv3zecScfFJWE2D')
# parseInt(String): Int|Unit
Converts the string representation of a number to its integer equivalent.
parseInt(str: String): Int|Unit
# Parameters
Parameter | Description |
---|---|
str : String | String to parse |
# Examples
parseInt("10") # Returns 10
parseInt("010") # Returns 10
parseInt("Ride") # Returns Unit
parseInt("10.30") # Returns Unit
# parseIntValue(String): Int
Converts the string representation of a number to its integer equivalent.
Fails if the string cannot be parsed.
parseIntValue(str: String): Int
# Parameters
Parameter | Description |
---|---|
str : String | String to parse |
# Examples
parseIntValue("10") # Returns 10
parseIntValue("010") # Returns 10
parseIntValue("Ride") # Error while parsing string to integer
parseIntValue("10.30") # Error while parsing string to integer
parseIntValue("20 WAVES") # Error while parsing string to integer
# toBytes(Boolean): ByteVector
Converts a boolean value to an array of bytes.
toBytes(b: Boolean): ByteVector
# Parameters
Parameter | Description |
---|---|
b : Boolean | Boolean to convert |
# Examples
toBytes(true) # Returns 2
toBytes(false) # Returns 1
# toBytes(Int): ByteVector
Converts an integer to an array of bytes.
toBytes(n: Int): ByteVector
# Parameters
Parameter | Description |
---|---|
n : Int | Integer to convert |
# Examples
toBytes(10) # Returns 1111111B
# toBytes(String): ByteVector
Converts a string to an array of bytes.
toBytes(s: String): ByteVector
# Parameters
Parameter | Description |
---|---|
s : String | String to convert |
# Examples
toBytes("Ride") # Returns 37BPKA
# toInt(ByteVector): Int
Converts an array of bytes to an integer.
toInt(bin: ByteVector) : Int
# Parameters
Parameter | Description |
---|---|
bin : ByteVector | Array of bytes to convert |
# Examples
toInt(bytes) # Returns 10
# toInt(ByteVector, Int): Int
Converts an array of bytes to an integer starting from a certain index.
toInt(bin: ByteVector, offset: Int): Int
# Parameters
Parameter | Description |
---|---|
bin : ByteVector | Array of bytes to convert |
offset : Int | Index to start from |
# Examples
let bytes = toBytes("Ride on Waves")
toInt(bytes, 2) # Returns 7234224039401641825
toInt(bytes, 6) # Index out of bounds
# toString(Address): String
Converts an array of bytes of an address to a string.
toString(Address: Address): String
# Parameters
Parameter | Description |
---|---|
Address : Address | Address to convert |
# Examples
let address =Address(base58'3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF')
toString(address) # Returns "3NADPfTVhGvVvvRZuqQjhSU4trVqYHwnqjF"
# toString(Boolean): String
Converts a boolean value to a string.
toString(b: Boolean): String
# Parameters
Parameter | Description |
---|---|
b : Boolean | Boolean to convert |
# Examples
toString(true) # Returns "true"
toString(false) # Returns "false"
# toString(Int): String
Converts an integer to a string.
toString(n: Int): String
# Parameters
Parameter | Description |
---|---|
n : Int | Integer to convert |
# Examples
toString(10) # Returns "10"
# toUtf8String(ByteVector): String
Converts an array of bytes to a UTF-8 string.
toUtf8String(u: ByteVector): String
# Parameters
Parameter | Description |
---|---|
u : ByteVector | Array of bytes to convert |
# Examples
let bytes = toBytes("Ride on Waves")
toUtf8String(bytes) # Returns "Ride on Waves"
# transferTransactionFromProto
Deserializes transfer transaction: converts protobuf-encoded binary format specified in transaction.proto to a TransferTransaction structure. Returns unit
if deserialization failed.
⚠️ The functions is added in Standard library version 4.
transferTransactionFromProto(b: ByteVector): TransferTransaction|Unit
For a description of the return value, see the TransferTransaction article.
# Parameters
Parameter | Description |
---|---|
b : ByteVector | Transfer transaction in protobuf-encoded binary format |
# Examples
let transfer = base64'Cr4BCFQSIA7SdnwUqEBY+k4jUf9sCV5+xj0Ry/GYuwmDMCdKTdl3GgQQoI0GIPLIyqL6LSgDwgaHAQoWChT+/s+ZWeOWzh1eRnhdRL3Qh9bxGRIkCiBO/wEBhwH/f/+bAWBRMv+A2yiAOUeBc9rY+UR/a4DxKBBkGkcaRYCcAQAB//9/AX9//0695P8EiICAfxgBgIkefwHYuDmA//83/4ABJgEBAf8d9N+8AAERyo1/j3kAGn/SAb7YIH8y/4CAXg=='
let x = match transferTransactionFromProto(transfer) {
case ttx:TransferTransaction =>
ttx.amount # 3500000000
case _ => throw("Can't find transaction")
}