Skip to content
This repository has been archived by the owner on Sep 21, 2023. It is now read-only.

Commit

Permalink
Merge and resolving merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
0xOmarA committed Feb 21, 2022
2 parents 94addd1 + 6a8f3da commit 2deb1b4
Show file tree
Hide file tree
Showing 15 changed files with 479 additions and 12 deletions.
2 changes: 0 additions & 2 deletions .vscode/settings.json

This file was deleted.

3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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",
],
Expand Down
4 changes: 4 additions & 0 deletions src/radixlib/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

# the imports for all of the actions
from radixlib.actions.create_token_definition import CreateTokenDefinition
from radixlib.actions.unregister_validator import UnregisterValidator
from radixlib.actions.register_validator import RegisterValidator
from radixlib.actions.transfer_tokens import TransferTokens
from radixlib.actions.unstake_tokens import UnstakeTokens
from radixlib.actions.stake_tokens import StakeTokens
Expand All @@ -12,6 +14,8 @@
from typing import Union as __Union
ActionType = __Union[
CreateTokenDefinition,
UnregisterValidator,
RegisterValidator,
TransferTokens,
UnstakeTokens,
StakeTokens,
Expand Down
139 changes: 138 additions & 1 deletion src/radixlib/actions/action_builder.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from radixlib.network import Network
from radixlib.actions import (
CreateTokenDefinition,
UnregisterValidator,
RegisterValidator,
TransferTokens,
UnstakeTokens,
StakeTokens,
MintTokens,
BurnTokens,
ActionType
)
from typing import Union, List
from typing import Union, List, overload, Optional
import radixlib as radix

class ActionBuilder():
Expand Down Expand Up @@ -323,6 +325,141 @@ def burn_tokens(

return self

@overload
def register_validator(self, *, validator_address: str) -> 'ActionBuilder': ...

@overload
def register_validator(self, *, node_address: str) -> 'ActionBuilder': ...

@overload
def register_validator(self, *, public_key: str) -> 'ActionBuilder': ...

@overload
def register_validator(self, *, account_address: str) -> 'ActionBuilder': ...

def register_validator(
self,
*,
validator_address: Optional[str] = None,
node_address: Optional[str] = None,
public_key: Optional[str] = None,
account_address: Optional[str] = None,
) -> 'ActionBuilder':
""" Creates a new RegisterValidator action.
This method is used to create a new RegisterValidator action and has four overrides to
allow this method to be called using anything that identifies the validator.
Args:
validator_address (:obj:`str`, optional): A string of the validator address to register.
node_address (:obj:`str`, optional): A string of the node address to register.
public_key (:obj:`str`, optional): A string of the public key of the validator to
register.
account_address (:obj:`str`, optional): A string of the account address of the validator
to .
Returns:
ActionBuilder: A reference to self to allow for method chaining when adding actions.
"""

# Getting the validator address from the arguments passed
_validator_address: str = ""
if validator_address:
_validator_address = validator_address
elif node_address:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = radix.derive.public_key_from_node_or_validator_address(node_address),
network = self.network
)
elif public_key:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = public_key,
network = self.network
)
elif account_address:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = radix.derive.public_key_from_wallet_address(account_address),
network = self.network
)
else:
raise ValueError(
"At least one argument needs to be passed to this method to build the action."
)

# Creating the action and appending it to the list of actions that have been created so far.
self.__actions_list.append(
RegisterValidator(_validator_address)
)

return self

@overload
def unregister_validator(self, *, validator_address: str) -> 'ActionBuilder': ...

@overload
def unregister_validator(self, *, node_address: str) -> 'ActionBuilder': ...

@overload
def unregister_validator(self, *, public_key: str) -> 'ActionBuilder': ...

@overload
def unregister_validator(self, *, account_address: str) -> 'ActionBuilder': ...

def unregister_validator(
self,
*,
validator_address: Optional[str] = None,
node_address: Optional[str] = None,
public_key: Optional[str] = None,
account_address: Optional[str] = None,
) -> 'ActionBuilder':
""" Creates a new UnregisterValidator action.
This method is used to create a new UnregisterValidator action and has four overrides to
allow this method to be called using anything that identifies the validator.
Args:
validator_address (:obj:`str`, optional): A string of the validator address to unregister.
node_address (:obj:`str`, optional): A string of the node address to unregister.
public_key (:obj:`str`, optional): A string of the public key of the validator to
unregister.
account_address (:obj:`str`, optional): A string of the account address of the validator
to unregister.
Returns:
ActionBuilder: A reference to self to allow for method chaining when adding actions.
"""

# Getting the validator address from the arguments passed
_validator_address: str = ""
if validator_address:
_validator_address = validator_address
elif node_address:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = radix.derive.public_key_from_node_or_validator_address(node_address),
network = self.network
)
elif public_key:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = public_key,
network = self.network
)
elif account_address:
_validator_address = radix.derive.validator_address_from_public_key(
public_key = radix.derive.public_key_from_wallet_address(account_address),
network = self.network
)
else:
raise ValueError(
"At least one argument needs to be passed to this method to build the action."
)

# Creating the action and appending it to the list of actions that have been created so far.
self.__actions_list.append(
UnregisterValidator(_validator_address)
)

return self

def to_action_list(self) -> List[ActionType]:
""" Gets a list of the actions that have been created by the action builder so far """
return self.__actions_list
69 changes: 69 additions & 0 deletions src/radixlib/actions/register_validator.py
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))
69 changes: 69 additions & 0 deletions src/radixlib/actions/unregister_validator.py
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))
15 changes: 14 additions & 1 deletion src/radixlib/api_types/identifiers/state_identifier.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from radixlib.serializable import Serializable
import radixlib.utils as utils
from typing import Dict, Optional, Set, Any
from typing import Dict, Optional, Set, Any, overload
from datetime import datetime
import dateparser
import json
Expand All @@ -10,8 +10,21 @@
class StateIdentifier(Serializable):
""" The implementation of an StateIdentifier """

@overload
def __init__(self, *, version: int) -> None: ...

@overload
def __init__(self, *, timestamp: datetime) -> None: ...

@overload
def __init__(self, *, epoch: int) -> None: ...

@overload
def __init__(self, *, epoch: int, round: int) -> None: ...

def __init__(
self,
*,
version: Optional[int] = None,
timestamp: Optional[datetime] = None,
epoch: Optional[int] = None,
Expand Down
Loading

0 comments on commit 2deb1b4

Please sign in to comment.