substrate_path
Module for Substrate paths parsing and handling.
- class SubstratePathConst
Bases:
object
Container for Substrate path constants.
- ENCODED_ELEM_MAX_BYTE_LEN: int = 32
- RE_PATH: str = '\\/+[^/]+'
- SOFT_PATH_PREFIX: str = '/'
- HARD_PATH_PREFIX: str = '//'
- SCALE_INT_ENCODERS: Dict[int, Type[SubstrateScaleEncoderBase]] = {8: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU8Encoder'>, 16: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU16Encoder'>, 32: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU32Encoder'>, 64: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU64Encoder'>, 128: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU128Encoder'>, 256: <class 'bip_utils.substrate.scale.substrate_scale_enc_uint.SubstrateScaleU256Encoder'>}
- class SubstratePathElem(elem: str)
Bases:
object
Substrate path element. It represents a Substrate path element.
- m_elem: str
- m_is_hard: bool
- IsHard() bool
Get if the element is hard.
- Returns:
True if hard, false otherwise
- Return type:
bool
- IsSoft() bool
Get if the element is soft.
- Returns:
True if soft, false otherwise
- Return type:
bool
- ChainCode() bytes
Return the chain code.
- Returns:
Chain code
- Return type:
bytes
- ToStr() str
Get the path element as a string.
- Returns:
Path element as a string
- Return type:
str
- __str__() str
Get the path element as a string.
- Returns:
Path element as a string
- Return type:
str
- class SubstratePath(elems: Optional[Sequence[Union[str, SubstratePathElem]]] = None)
Bases:
object
Substrate path. It represents a Substrate path.
- m_elems: List[SubstratePathElem]
- AddElem(elem: Union[str, SubstratePathElem]) SubstratePath
Return a new path object with the specified element added.
- Parameters:
elem (str or SubstratePathElem) – Path element
- Returns:
SubstratePath object
- Return type:
SubstratePath object
- Raises:
SubstratePathError – If the path element is not valid
- Length() int
Get the number of elements of the path.
- Returns:
Number of elements
- Return type:
int
- ToList() List[str]
Get the path as a list of strings.
- Returns:
Path as a list of strings
- Return type:
list[str]
- ToStr() str
Get the path as a string.
- Returns:
Path as a string
- Return type:
str
- __str__() str
Get the path as a string.
- Returns:
Path as a list of integers
- Return type:
str
- __getitem__(idx: int) SubstratePathElem
Get the specified element index.
- Parameters:
idx (int) – Element index
- Returns:
SubstratePathElem object
- Return type:
SubstratePathElem object
- __iter__() Iterator[SubstratePathElem]
Get the iterator to the current element.
- Returns:
Iterator to the current element
- Return type:
Iterator object
- class SubstratePathParser
Bases:
object
Substrate path parser. It parses a Substrate path and returns a SubstratePath object.
- static Parse(path: str) SubstratePath
Parse a path and return a SubstratePath object.
- Parameters:
path (str) – Path
- Returns:
SubstratePath object
- Return type:
SubstratePath object
- Raises:
SubstratePathError – If the path element is not valid