This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
479 additions
and
12 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="radixlib", | ||
version="1.0.1", | ||
version="1.1.0", | ||
author="Omar Abdulla", | ||
author_email="[email protected]", | ||
description="A Python API wrapper for the Gateway API of the Radix Blockchain.", | ||
|
@@ -23,7 +23,6 @@ | |
"Programming Language :: Python :: 3.10", | ||
"Programming Language :: Python :: 3.11", | ||
"Natural Language :: English", | ||
"Development Status :: 4 - Beta", | ||
"Operating System :: OS Independent", | ||
"License :: OSI Approved :: MIT License", | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from radixlib.api_types.identifiers import ValidatorIdentifier | ||
from radixlib.serializable import Serializable | ||
from typing import Dict, Any | ||
import radixlib as radix | ||
import json | ||
|
||
class RegisterValidator(Serializable): | ||
""" Defines a RegisterValidator action. """ | ||
|
||
def __init__( | ||
self, | ||
validator_address: str, | ||
) -> None: | ||
""" Instantiates a new RegisterValidator action used for the creation of new tokens. | ||
Args: | ||
validator_address (str): The address of the validator to register to the network. | ||
Raises: | ||
ValueError: If the RRI given does not begin with XRD. | ||
""" | ||
|
||
self.validator: ValidatorIdentifier = ValidatorIdentifier(validator_address) | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
"""" Converts the object to a dictionary """ | ||
return radix.utils.remove_none_values_recursively( | ||
radix.utils.convert_to_dict_recursively({ | ||
"type": "RegisterValidator", | ||
"validator": self.validator, | ||
}) | ||
) | ||
|
||
def to_json_string(self) -> str: | ||
""" Converts the object to a JSON string """ | ||
return json.dumps(self.to_dict()) | ||
|
||
@classmethod | ||
def from_dict( | ||
cls, | ||
dictionary: Dict[Any, Any] | ||
) -> 'RegisterValidator': | ||
""" Loads a RegisterValidator from a Gateway API response dictionary | ||
Args: | ||
dictionary (dict): The dictionary to load the object from | ||
Returns: | ||
RegisterValidator: A new RegisterValidator initalized from the dictionary | ||
Raises: | ||
TypeError: Raised when the type of the action in the dictionary does not match | ||
the action name of the class | ||
""" | ||
|
||
if dictionary.get('type') != "RegisterValidator": | ||
raise TypeError(f"Expected a dictionary with a type of RegisterValidator but got: {dictionary.get('type')}") | ||
|
||
return cls( | ||
validator_address = dictionary['validator']['address'] | ||
) | ||
|
||
@classmethod | ||
def from_json_string( | ||
cls, | ||
json_string: str | ||
) -> 'RegisterValidator': | ||
""" Loads a RegisterValidator from a Gateway API response JSON string. """ | ||
return cls.from_dict(json.loads(json_string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from radixlib.api_types.identifiers import ValidatorIdentifier | ||
from radixlib.serializable import Serializable | ||
from typing import Dict, Any | ||
import radixlib as radix | ||
import json | ||
|
||
class UnregisterValidator(Serializable): | ||
""" Defines a UnregisterValidator action. """ | ||
|
||
def __init__( | ||
self, | ||
validator_address: str, | ||
) -> None: | ||
""" Instantiates a new UnregisterValidator action used for the creation of new tokens. | ||
Args: | ||
validator_address (str): The address of the validator to register to the network. | ||
Raises: | ||
ValueError: If the RRI given does not begin with XRD. | ||
""" | ||
|
||
self.validator: ValidatorIdentifier = ValidatorIdentifier(validator_address) | ||
|
||
def to_dict(self) -> Dict[str, Any]: | ||
"""" Converts the object to a dictionary """ | ||
return radix.utils.remove_none_values_recursively( | ||
radix.utils.convert_to_dict_recursively({ | ||
"type": "UnregisterValidator", | ||
"validator": self.validator, | ||
}) | ||
) | ||
|
||
def to_json_string(self) -> str: | ||
""" Converts the object to a JSON string """ | ||
return json.dumps(self.to_dict()) | ||
|
||
@classmethod | ||
def from_dict( | ||
cls, | ||
dictionary: Dict[Any, Any] | ||
) -> 'UnregisterValidator': | ||
""" Loads a UnregisterValidator from a Gateway API response dictionary | ||
Args: | ||
dictionary (dict): The dictionary to load the object from | ||
Returns: | ||
UnregisterValidator: A new UnregisterValidator initalized from the dictionary | ||
Raises: | ||
TypeError: Raised when the type of the action in the dictionary does not match | ||
the action name of the class | ||
""" | ||
|
||
if dictionary.get('type') != "UnregisterValidator": | ||
raise TypeError(f"Expected a dictionary with a type of UnregisterValidator but got: {dictionary.get('type')}") | ||
|
||
return cls( | ||
validator_address = dictionary['validator']['address'] | ||
) | ||
|
||
@classmethod | ||
def from_json_string( | ||
cls, | ||
json_string: str | ||
) -> 'UnregisterValidator': | ||
""" Loads a UnregisterValidator from a Gateway API response JSON string. """ | ||
return cls.from_dict(json.loads(json_string)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.