public class Helper
extends java.lang.Object
| Constructor and Description |
|---|
Helper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
abort()
Aborts the execution of the contract.
|
static byte |
asByte(int value)
Asserts that the given value is in the range [-128, 127], i.e., the value range of a signed
byte.
|
static void |
assertTrue(boolean condition)
Asserts if the given boolean is true.
|
static byte |
asSignedByte(int value)
Asserts that the given value is in the range [0, 255], i.e., the range of an unsigned byte.
|
static byte[] |
concat(byte[] first,
byte[] second)
Concatenates the two given byte arrays.
|
static java.lang.String |
concat(java.lang.String first,
java.lang.String second)
Concatenates the two given strings.
|
static byte[] |
last(byte[] source,
int n)
Returns the last n elements of the given byte array.
|
static java.lang.String |
last(java.lang.String source,
int n)
Returns the last n characters of the given String.
|
static byte[] |
range(byte[] source,
int index,
int n)
Returns n consecutive bytes from the given source starting at the given index.
|
static java.lang.String |
range(java.lang.String source,
int index,
int n)
Returns n consecutive characters from the given string starting at the given index.
|
static byte[] |
reverse(byte[] source)
Returns a reversed copy of the given bytes.
|
static java.lang.String |
reverse(java.lang.String source)
Returns a reversed copy of the given string.
|
static byte[] |
take(byte[] source,
int n)
Returns the first n elements from the given byte array.
|
static java.lang.String |
take(java.lang.String source,
int n)
Returns the first n characters from the given string.
|
static byte[] |
toByteArray(byte source)
Converts the given byte to a byte array.
|
static byte[] |
toByteArray(java.lang.String source)
Converts the given string to a byte array using UTF-8 encoding.
|
static java.lang.String |
toByteString(byte[] source)
Casts the given byte array to a string.
|
static int |
toInt(byte[] source)
Converts the given byte array to an integer.
|
static boolean |
within(int x,
int a,
int b)
Checks if the value of x is in the range [a, b).
|
public static void assertTrue(boolean condition)
condition - The condition to check.public static void abort()
public static byte[] toByteArray(byte source)
source - The byte to convert.public static byte[] toByteArray(java.lang.String source)
This method cannot be used to convert a Neo address to a valid script hash byte array, or a script hash in hexadecimal format into its corresponding byte array.
Examples
source - The string to convert.public static byte asByte(int value)
Examples:
value - The value to cast.public static byte asSignedByte(int value)
value - The value to cast.public static int toInt(byte[] source)
The value of the converted integer can be outside of Integer.MAX_VALUE because the
neo-vm doesn't have that limit for int as the JVM has.
Examples
source - The byte array to convert.public static java.lang.String toByteString(byte[] source)
In the NeoVM strings are represented as ByteStrings. Hence the method name.
Examples:
source - The byte array to cast.public static boolean within(int x,
int a,
int b)
Examples: x=5 a=5 b=15 is true; x=15 a=5 b=15 is false
x - The value to check if it is in the range.a - The beginning of the range (inclusive).b - The end of the range (exclusive).public static byte[] concat(byte[] first,
byte[] second)
first - The first byte array.second - The second byte array.public static java.lang.String concat(java.lang.String first,
java.lang.String second)
first - The first string.second - The second string.public static java.lang.String range(java.lang.String source,
int index,
int n)
source - The string to take the bytes from.index - The start index of the range (inclusive).n - The size of the range, i.e. number of characters to take.public static byte[] range(byte[] source,
int index,
int n)
source - The array to take the bytes from.index - The start index of the range (inclusive).n - The size of the range, i.e. number of bytes to take.public static byte[] take(byte[] source,
int n)
n < 0.source - The array to take the bytes from.n - The number of bytes to return.public static java.lang.String take(java.lang.String source,
int n)
n < 0.source - The string to take the characters from.n - The number of characters to return.public static byte[] last(byte[] source,
int n)
n < 0.source - The array to take the bytes from.n - The number of bytes to return.public static java.lang.String last(java.lang.String source,
int n)
n < 0.source - The string.n - The number characters to return.public static byte[] reverse(byte[] source)
source - The bytes to reverse.public static java.lang.String reverse(java.lang.String source)
source - The string to reverse.