Base
RuntimeConfigurationObject
¶
Container for runtime configuration, for example type definitions and runtime upgrade information
get_decoder_class(type_string: Union[str, dict])
¶
Lookup and return a ScaleDecoder class for given type_string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_string |
Union[str, dict]
|
required |
Returns:
Type | Description |
---|---|
ScaleDecoder
|
create_scale_object(type_string: str, data: Optional[ScaleBytes] = None, **kwargs) -> ScaleType
¶
Creates a new ScaleType
object with given type_string, for example 'u32', 'Bytes' or 'scale_info::2'
(scale_info:: prefixed types are defined in the PortableRegistry
object of the runtime metadata.)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_string |
str
|
required | |
data |
Optional[ScaleBytes]
|
None
|
|
kwargs |
{}
|
Returns:
Type | Description |
---|---|
ScaleType
|
get_runtime_id_from_upgrades(block_number: int) -> Optional[int]
¶
Retrieve runtime_id for given block_number if runtime_upgrades are specified in the type registry
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_number |
int
|
required |
Returns:
Type | Description |
---|---|
Runtime id
|
set_runtime_upgrades_head(block_number: int)
¶
Sets head for given block_number to last runtime_id in runtime_upgrades cache
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block_number |
int
|
required |
ScaleBytes
¶
Representation of SCALE encoded Bytes.
__init__(data: Union[str, bytes, bytearray])
¶
Constructs a SCALE bytes-stream with provided data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Union[str, bytes, bytearray]
|
required |
get_next_bytes(length: int) -> bytearray
¶
Retrieve length
amount of bytes of the stream
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length |
int
|
required |
Returns:
Type | Description |
---|---|
bytearray
|
get_remaining_bytes() -> bytearray
¶
Retrieves all remaining bytes from the stream
Returns:
Type | Description |
---|---|
bytearray
|
get_remaining_length() -> int
¶
Returns how many bytes are left in the stream
Returns:
Type | Description |
---|---|
int
|
reset()
¶
Resets the pointer of the stream to the beginning
to_hex() -> str
¶
Return a hex-string (e.g. "0x00") representation of the byte-stream
Returns:
Type | Description |
---|---|
str
|
ScaleDecoder
¶
Bases: ABC
Base class for all SCALE decoding/encoding
__init__(data: ScaleBytes, sub_type: str = None, runtime_config: RuntimeConfigurationObject = None)
¶
Constructs an SCALE codec class capable of encoding and decoding SCALE-bytes
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ScaleBytes
|
required | |
sub_type |
str
|
None
|
|
runtime_config |
RuntimeConfigurationObject
|
None
|
get_next_bytes(length) -> bytearray
¶
Retrieve length
amount of bytes of the SCALE-bytes stream
Parameters:
Name | Type | Description | Default |
---|---|---|---|
length |
required |
Returns:
Type | Description |
---|---|
bytearray
|
get_next_u8() -> int
¶
Retrieves the next byte and convert to an int
Returns:
Type | Description |
---|---|
int
|
get_next_bool() -> bool
¶
Retrieves the next byte and convert to an bool
Returns:
Type | Description |
---|---|
bool
|
get_remaining_bytes() -> bytearray
¶
Retrieves all remaining bytes from the stream
Returns:
Type | Description |
---|---|
bytearray
|
get_used_bytes() -> bytearray
¶
Returns a bytearray of all SCALE-bytes used in the decoding process
Returns:
Type | Description |
---|---|
bytearray
|
process()
abstractmethod
¶
Implementation of the decoding process
decode(data: ScaleBytes = None, check_remaining = True)
¶
Decodes available SCALE-bytes according to type specification of this ScaleType
If no data
is provided, it will try to decode data specified during init
If check_remaining
is enabled, an exception will be raised when data is remaining after decoding
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
ScaleBytes
|
None
|
|
check_remaining |
True
|
encode(value = None) -> ScaleBytes
¶
Encodes the serialized value
representation of current ScaleType
to a ScaleBytes
stream
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
None
|
Returns:
Type | Description |
---|---|
ScaleBytes
|
process_encode(value) -> ScaleBytes
¶
Implementation of the encoding process
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value |
required |
Returns:
Type | Description |
---|---|
ScaleBytes
|
get_decoder_class(type_string, data = None, runtime_config = None, **kwargs)
classmethod
¶
Retrieves the decoding class for provided type_string
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_string |
required | ||
data |
None
|
||
runtime_config |
None
|
||
kwargs |
{}
|
Returns:
Type | Description |
---|---|
ScaleType
|
serialize()
¶
Returns a serialized representation of current ScaleType
ScaleType
¶
Bases: ScaleDecoder
, ABC
Base class for all SCALE types
__init__(data = None, sub_type = None, metadata = None, runtime_config = None)
¶
Initializes an ScaleType
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
None
|
||
sub_type |
None
|
||
metadata |
None
|
||
runtime_config |
None
|