stdlib
- class StdLib
Bases:
object
A class used to represent StdLib native contract.
Check out Neo’s Documentation to learn more about the StdLib class.
- classmethod serialize(item: Any) bytes
Serializes the given value into its bytes representation.
>>> StdLib.serialize('42') b'(\x0242'
>>> StdLib.serialize(42) b'!\x01*'
>>> StdLib.serialize([2, 3, 5, 7]) b'@\x04!\x01\x02!\x01\x03!\x01\x05!\x01\x07'
>>> StdLib.serialize({1: 1, 2: 1, 3: 2}) b'H\x03!\x01\x01!\x01\x01!\x01\x02!\x01\x01!\x01\x03!\x01\x02'
- classmethod deserialize(data: bytes) Any
Deserializes the given bytes value.
>>> StdLib.deserialize(b'(\x0242') '42'
>>> StdLib.deserialize(b'!\x01*') 42
>>> StdLib.deserialize(b'@\x04!\x01\x02!\x01\x03!\x01\x05!\x01\x07') [2, 3, 5, 7]
>>> StdLib.deserialize(b'H\x03!\x01\x01!\x01\x01!\x01\x02!\x01\x01!\x01\x03!\x01\x02') {1: 1, 2: 1, 3: 2}
- classmethod json_serialize(item: Any) str
Serializes an item into a json.
>>> StdLib.json_serialize({'one': 1, 'two': 2, 'three': 3}) '{"one":1,"two":2,"three":3}'
- classmethod json_deserialize(json: str) Any
Deserializes a json into some valid type.
>>> StdLib.json_deserialize('{"one":1,"two":2,"three":3}') {'one': 1, 'three': 3, 'two': 2}
- classmethod base64_decode(key: str) bytes
Decodes a string value encoded with base64.
>>> StdLib.base64_decode("dW5pdCB0ZXN0") b"unit test"
- classmethod base64_encode(key: bytes) str
Encodes a bytes value using base64.
>>> StdLib.base64_encode(b'unit test') b"dW5pdCB0ZXN0"
- classmethod base58_decode(key: str) bytes
Decodes a string value encoded with base58.
>>> StdLib.base58_decode('2VhL46g69A1mu') b"unit test"
- classmethod base58_encode(key: bytes) str
Encodes a bytes value using base58.
>>> StdLib.base58_encode(b'unit test') b"2VhL46g69A1mu"
- classmethod base58_check_decode(key: str) bytes
Converts the specified str, which encodes binary data as base-58 digits, to an equivalent bytes value. The encoded str contains the checksum of the binary data.
>>> StdLib.base58_check_decode('AnJcKqvgBwKxsjX75o') b"unit test"
- classmethod base58_check_encode(key: bytes) str
Converts a bytes value to its equivalent str representation that is encoded with base-58 digits. The encoded str contains the checksum of the binary data.
>>> StdLib.base58_check_encode(b'unit test') b"AnJcKqvgBwKxsjX75o"
- classmethod itoa(value: int, base: int = 10) str
Converts the specific type of value to a decimal or hexadecimal string. The default is decimal.
>>> StdLib.itoa(10) '10'
>>> StdLib.itoa(123) '123'
>>> StdLib.itoa(-1, 16) 'f'
>>> StdLib.itoa(15, 16) '0f'
- classmethod atoi(value: str, base: int = 10) int
Converts a character string to a specific base value, decimal or hexadecimal. The default is decimal.
>>> StdLib.atoi('10') 10
>>> StdLib.atoi('123') 123
>>> StdLib.atoi('1f', 16) 31
>>> StdLib.atoi('ff', 16) -1
- classmethod memory_compare(mem1: bytes | str, mem2: bytes | str) int
Compares a memory with another one.
>>> StdLib.memory_compare('abc', 'abc') 0
>>> StdLib.memory_compare('ABC', 'abc') -1
>>> StdLib.memory_compare('abc', 'ABC') 1