-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Import/Export WalletData (#9)
- Loading branch information
1 parent
bdabb2d
commit 6d18e53
Showing
5 changed files
with
128 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -28,4 +28,4 @@ install-deps: | |
|
||
.PHONY: docs | ||
docs: | ||
sphinx-apidoc -o docs/ ./cdp/ | ||
sphinx-apidoc -f -o docs/ ./cdp/ |
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,73 @@ | ||
class WalletData: | ||
"""A class representing wallet data required to recreate a wallet.""" | ||
|
||
def __init__(self, wallet_id: str, seed: str) -> None: | ||
"""Initialize the WalletData class. | ||
Args: | ||
wallet_id (str): The ID of the wallet. | ||
seed (str): The seed of the wallet. | ||
""" | ||
self._wallet_id = wallet_id | ||
self._seed = seed | ||
|
||
@property | ||
def wallet_id(self) -> str: | ||
"""Get the ID of the wallet. | ||
Returns: | ||
str: The ID of the wallet. | ||
""" | ||
return self._wallet_id | ||
|
||
@property | ||
def seed(self) -> str: | ||
"""Get the seed of the wallet. | ||
Returns: | ||
str: The seed of the wallet. | ||
""" | ||
return self._seed | ||
|
||
def to_dict(self) -> dict[str, str]: | ||
"""Convert the wallet data to a dictionary. | ||
Returns: | ||
dict[str, str]: The dictionary representation of the wallet data. | ||
""" | ||
return {"wallet_id": self.wallet_id, "seed": self.seed} | ||
|
||
@classmethod | ||
def from_dict(cls, data: dict[str, str]) -> "WalletData": | ||
"""Create a WalletData class instance from the given dictionary. | ||
Args: | ||
data (dict[str, str]): The data to create the WalletData object from. | ||
Returns: | ||
WalletData: The wallet data. | ||
""" | ||
return cls(data["wallet_id"], data["seed"]) | ||
|
||
def __str__(self) -> str: | ||
"""Return a string representation of the WalletData object. | ||
Returns: | ||
str: A string representation of the wallet data. | ||
""" | ||
return f"WalletData: (wallet_id: {self.wallet_id}, seed: {self.seed})" | ||
|
||
def __repr__(self) -> str: | ||
"""Return a string representation of the WalletData object. | ||
Returns: | ||
str: A string representation of the wallet data. | ||
""" | ||
return str(self) |
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