├── .github ├── FUNDING.yml └── workflows │ └── python-app.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── pyproject.toml ├── requirements.txt └── src └── chia_py_rpc ├── __init__.py ├── rpc_connect.py └── wallet.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | patreon: 95706337 2 | -------------------------------------------------------------------------------- /.github/workflows/python-app.yml: -------------------------------------------------------------------------------- 1 | # This workflow will install Python dependencies, run tests and lint with a single version of Python 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python 3 | 4 | name: Python application 5 | 6 | on: 7 | push: 8 | branches: [ "main" ] 9 | pull_request: 10 | branches: [ "main" ] 11 | 12 | permissions: 13 | contents: read 14 | 15 | jobs: 16 | build: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Python 3.11 23 | uses: actions/setup-python@v3 24 | with: 25 | python-version: "3.11" 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install flake8 pytest 30 | if [ -f requirements.txt ]; then pip install -r requirements.txt; fi 31 | - name: Lint with flake8 32 | run: | 33 | # stop the build if there are Python syntax errors or undefined names 34 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 35 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 36 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 37 | 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | Chia-Py-RPC.code-workspace 131 | TransMulti.py 132 | .vscode/launch.json 133 | .pypirc 134 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | via email using king@the300.net. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 King Leonidas 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chia-Py-RPC 2 | 3 | Chia-Py-RPC is a Python library that provides a convenient way to interact with the Chia blockchain using the Chia RPC (Remote Procedure Call) protocol. It allows you to send transactions, check balances, and perform other Chia-related operations programmatically from Python. 4 | 5 | ## Features 6 | 7 | - Send transactions to multiple recipients in a single transaction 8 | - Check wallet balances and transaction history 9 | - Get information about Chia blocks, coins, and transactions 10 | - Create and manage Chia wallets 11 | - Simple and easy-to-use 12 | - Plus every RPC method avaliable in Chia Client 1.7.0 or previous. 13 | 14 | ## Installation 15 | 16 | To install Chia-Py-RPC, you can use `pip`, the Python package manager. Open a terminal and run the following command: 17 | 18 | ```bash 19 | pip install chia-py-rpc 20 | ``` 21 | 22 | ## Usage 23 | Here's an example of how you can use Chia-Py-RPC to send transactions to multiple recipients in a single transaction: 24 | 25 | ``` 26 | from chia_py_rpc.wallet import Wallet 27 | 28 | # Create an instance of Wallet 29 | chia_wallet = Wallet() 30 | 31 | # Specify the wallet ID, additions (recipients), fee, and optional parameters 32 | wallet_id = 1 33 | additions = [ 34 | {'amount': 1000000000000, 'puzzle_hash': '0x...'}, # Recipient 1 35 | {'amount': 500000000000, 'puzzle_hash': '0x...'}, # Recipient 2 36 | ] 37 | fee = 0.00001 38 | 39 | # Call the send_transaction_multi method to send the transaction 40 | result = chia_wallet.send_transaction_multi(wallet_id, additions, fee) 41 | 42 | # Parse the result and handle the transaction ID and status 43 | transaction_id = result['transaction_id'] 44 | status = result['status'] 45 | print(f"Transaction ID: {transaction_id}") 46 | print(f"Status: {status}") 47 | ``` 48 | 49 | For more examples and documentation, please refer to the official documentation. 50 | 51 | ## Contributing 52 | If you would like to contribute to Chia-Py-RPC, please open an issue or submit a pull request on GitHub. We welcome any contributions, including bug fixes, feature enhancements, and documentation improvements. 53 | 54 | ## License 55 | Chia-Py-RPC is open-source software licensed under the MIT License. 56 | 57 | ## Acknowledgements 58 | Chia-Py-RPC is not affilated with the Chia Network in any way and it purely to provide a simple method of utlising Chia RPC in python. 59 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["hatchling"] 3 | build-backend = "hatchling.build" 4 | 5 | [project] 6 | name = "chia_py_rpc" 7 | version = "0.1.2" 8 | authors = [ 9 | { name="L4bb3rs", email="king@the300.net" }, 10 | ] 11 | description = "Chia-Py-RPC is a Python library that provides a convenient way to interact with the Chia blockchain using the Chia RPC (Remote Procedure Call) protocol." 12 | readme = "README.md" 13 | requires-python = ">=3.11" 14 | classifiers = [ 15 | "Programming Language :: Python :: 3", 16 | "License :: OSI Approved :: MIT License", 17 | "Operating System :: OS Independent", 18 | ] 19 | 20 | dependencies = [ 21 | "Requests>=2.31.0", 22 | "urllib3>=2.0.7", 23 | ] 24 | 25 | [project.urls] 26 | "Homepage" = "https://github.com/L4bb3rs/Chia-Py-RPC" 27 | "Bug Tracker" = "https://github.com/L4bb3rs/Chia-Py-RPC" -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Requests==2.31.0 2 | urllib3==2.0.7 3 | -------------------------------------------------------------------------------- /src/chia_py_rpc/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = ["wallet", "rpc_connect"] 2 | -------------------------------------------------------------------------------- /src/chia_py_rpc/rpc_connect.py: -------------------------------------------------------------------------------- 1 | import json 2 | import requests 3 | import urllib3 4 | import os 5 | 6 | from typing import Optional, Tuple 7 | 8 | 9 | class WalletRPCConnect: 10 | """ 11 | This module provides a class for connecting to a Chia Wallet RPC service. 12 | 13 | The `WalletRPCConnect` class provides methods for submitting Chia RPC calls and 14 | receiving JSON responses. 15 | 16 | Usage: 17 | wallet_rpc = WalletRPCConnect(url='https://localhost:9256/', 18 | cert=('path/to/cert', 'path/to/key')) 19 | response = wallet_rpc.submit('get_wallet_balance', '{}') 20 | 21 | Attributes: 22 | url (str): URL of the Chia RPC service. 23 | cert (tuple): Tuple containing paths to the SSL certificate and private key files. 24 | 25 | Methods: 26 | submit(chia_call: str, data: str) -> str: 27 | Submit a Chia RPC call to the specified URL with the given data. 28 | 29 | Args: 30 | chia_call (str): Name of the Chia RPC call to be made. 31 | data (str): Data to be sent in the request. 32 | 33 | Returns: 34 | str: JSON response as a string with indentation and sorted keys. 35 | """ 36 | 37 | def __init__( 38 | self, url: Optional[str] = None, cert: Optional[Tuple[str, str]] = None, disable_warnings: bool = True 39 | ) -> None: 40 | """ 41 | Initialize ChiaRPC instance with the provided URL and certificate. 42 | 43 | Args: 44 | url (str, optional): URL of the Chia RPC service. Defaults to None. 45 | cert (tuple, optional): Tuple containing paths to the SSL certificate and private key files. Defaults to None. 46 | """ 47 | default_url = "https://localhost:9256/" 48 | default_cert = ( 49 | os.path.expanduser( 50 | "~/.chia/mainnet/config/ssl/full_node/private_full_node.crt" 51 | ), 52 | os.path.expanduser( 53 | "~/.chia/mainnet/config/ssl/full_node/private_full_node.key" 54 | ), 55 | ) 56 | 57 | self.url = url or default_url 58 | self.cert = cert or default_cert 59 | self.headers = {"Content-Type": "application/json"} 60 | if disable_warnings: 61 | urllib3.disable_warnings() 62 | 63 | def submit(self, chia_call: str, data: str) -> str: 64 | """ 65 | Submit data to the specified URL. 66 | 67 | Args: 68 | chia_call (str): Chia RPC call to be made. 69 | data (str): Data to be sent in the request. 70 | 71 | Returns: 72 | str: JSON response as a string with indentation and sorted keys. 73 | """ 74 | response = requests.post( 75 | self.url + chia_call, 76 | data=data, 77 | headers=self.headers, 78 | cert=self.cert, 79 | verify=False, 80 | ) 81 | response_text = response.text 82 | response_json = json.loads(response_text) 83 | return json.dumps(response_json, indent=4, sort_keys=True) 84 | -------------------------------------------------------------------------------- /src/chia_py_rpc/wallet.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from chia_py_rpc.rpc_connect import WalletRPCConnect as WalletRPC 4 | from typing import Dict, Tuple, Union, List, Optional 5 | 6 | 7 | class SharedMethods: 8 | """Methods shared by all services.""" 9 | 10 | def __init__( 11 | self, url: Optional[str] = None, cert: Optional[Tuple[str, str]] = None, disable_warnings: bool = False 12 | ) -> None: 13 | """ 14 | Initialize SharedMethods instance. 15 | 16 | Args: 17 | url (str, optional): URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 18 | cert (str, optional): Certificate for ChiaRPC. Default Certificates unless specified. 19 | disable_warnings (bool, optional): Disable SSL warnings. Defaults to False. 20 | """ 21 | self.__url__ = url 22 | self.__cert__ = cert 23 | self.__chia_rpc__ = WalletRPC(url=url, cert=cert, disable_warnings=disable_warnings) 24 | 25 | def close_connection(self, node_id: str) -> dict: 26 | """ 27 | Close a connection in a shared wallet. 28 | 29 | Args: 30 | node_id (str): Node ID of the connection to be closed. 31 | 32 | Returns: 33 | dict: A dictionary containing the result of the operation. 34 | """ 35 | # Construct the request payload 36 | try: 37 | payload = {"node_id": node_id} 38 | result = self.__chia_rpc__.submit("close_connection", json.dumps(payload)) 39 | 40 | # Parse the JSON response and return the result 41 | return json.loads(result) 42 | except Exception as e: 43 | return {"error": str(e)} 44 | 45 | def get_connections(self) -> dict: 46 | """ 47 | Retrieve the list of connections in a shared wallet. 48 | 49 | Returns: 50 | dict: A dictionary containing the list of connections. 51 | """ 52 | try: 53 | # Prepare the payload as a dictionary 54 | payload = {} 55 | 56 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 57 | result = self.__chia_rpc__.submit("get_connections", json.dumps(payload)) 58 | 59 | # Parse the JSON response and return the result 60 | return json.loads(result) 61 | except Exception as e: 62 | return {"error": str(e)} 63 | 64 | def get_routes(self) -> dict: 65 | """ 66 | Retrieve the list of routes/endpoints exposed by the shared wallet service. 67 | 68 | Returns: 69 | dict: A dictionary containing the list of routes/endpoints. 70 | """ 71 | try: 72 | # Prepare the payload as a dictionary 73 | payload = {} 74 | 75 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 76 | result = self.__chia_rpc__.submit("get_routes", json.dumps(payload)) 77 | 78 | # Parse the JSON response and return the result 79 | return json.loads(result) 80 | except Exception as e: 81 | return {"error": str(e)} 82 | 83 | def check_healthz(self) -> dict: 84 | """ 85 | Check the health status of the shared wallet service. 86 | 87 | Returns: 88 | dict: Parsed JSON response from the shared wallet service. 89 | """ 90 | try: 91 | # Prepare the payload as a dictionary 92 | payload = {} 93 | 94 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 95 | result = self.__chia_rpc__.submit("healthz", json.dumps(payload)) 96 | 97 | # Parse the JSON response and return it 98 | return json.loads(result) 99 | except Exception as e: 100 | return {"error": str(e)} 101 | 102 | def open_connection(self, ip: str, port: int) -> dict: 103 | """ 104 | Add a connection to another node. 105 | 106 | Args: 107 | ip (str): IP address of the node to connect to. 108 | port (int): Port number of the node to connect to. 109 | 110 | Returns: 111 | dict: Parsed JSON response from the shared wallet service. 112 | """ 113 | try: 114 | # Prepare the payload as a dictionary 115 | payload = {"ip": ip, "port": port} 116 | 117 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 118 | result = self.__chia_rpc__.submit("open_connection", json.dumps(payload)) 119 | 120 | # Parse the JSON response and return it 121 | return json.loads(result) 122 | except Exception as e: 123 | return {"error": str(e)} 124 | 125 | def stop_node(self) -> dict: 126 | """ 127 | Stop the Chia node. 128 | 129 | Returns: 130 | dict: Parsed JSON response from the shared wallet service. 131 | """ 132 | try: 133 | # Prepare the payload as a dictionary 134 | payload = {} 135 | 136 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 137 | result = self.__chia_rpc__.submit("stop_node", json.dumps(payload)) 138 | 139 | # Parse the JSON response and return it 140 | return json.loads(result) 141 | except Exception as e: 142 | return {"error": str(e)} 143 | 144 | 145 | class CatWallet: 146 | """CATs, trades, and offers.""" 147 | 148 | def __init__(self, url: str = None, cert: str = None): 149 | """ 150 | Initialize CatWallet instance. 151 | 152 | Args: 153 | url (str, optional): URL for ChiaRPC. Defaults to None, will use https://localhost:9256/ unless specified. 154 | cert (str, optional): Certificate for ChiaRPC. Defaults to None, will use default certificates unless specified. 155 | """ 156 | try: 157 | self.__url__ = url 158 | self.__cert__ = cert 159 | self.__chia_rpc__ = WalletRPC(url, cert) 160 | except Exception as e: 161 | print(f"Initialization error: {str(e)}") 162 | 163 | def cancel_offers( 164 | self, 165 | secure: bool, 166 | batch_fee: int = 0, 167 | batch_size: int = 5, 168 | cancel_all: bool = False, 169 | asset_id: str = "xch", 170 | ) -> dict: 171 | """ 172 | Cancel offers category. 173 | 174 | Args: 175 | secure (bool): Set to true to cancel on the blockchain by spending the coin(s) being offered; 176 | set to false to cancel in the wallet only. This parameter is required. 177 | batch_fee (int, optional): The fee, in mojos, to add to each batch cancellation. Defaults to 0. 178 | batch_size (int, optional): The number of offers to cancel in each batch. Defaults to 5. 179 | cancel_all (bool, optional): Set to true to cancel all offers for all assets. Defaults to False. 180 | asset_id (str, optional): If cancel_all is false, then only cancel the specified type of asset. Defaults to "xch". 181 | 182 | Returns: 183 | dict: Response from the RPC. 184 | """ 185 | try: 186 | data = { 187 | "secure": secure, 188 | "batch_fee": batch_fee, 189 | "batch_size": batch_size, 190 | "cancel_all": cancel_all, 191 | "asset_id": asset_id.lower(), 192 | } 193 | result = self.__chia_rpc__.submit("cancel_offers", json.dumps(data)) 194 | return json.loads(result) 195 | except Exception as e: 196 | return {"error": str(e)} 197 | 198 | def cat_asset_id_to_name(self, asset_id: str) -> dict: 199 | """ 200 | Retrieve asset name by asset ID. 201 | 202 | Args: 203 | asset_id (str): The ID of the CAT whose name you would like to retrieve. 204 | This CAT must be listed in your DEFAULT_CATS, i.e., the CATs your wallet recognizes. 205 | 206 | Returns: 207 | dict: Response from the RPC. 208 | """ 209 | try: 210 | data = {"asset_id": asset_id} 211 | result = self.__chia_rpc__.submit("cat_asset_id_to_name", json.dumps(data)) 212 | return json.loads(result) 213 | except Exception as e: 214 | return {"error": str(e)} 215 | 216 | def cancel_offer(self, secure: bool, trade_id: str, fee: int = None) -> dict: 217 | """ 218 | Cancel an offer. 219 | 220 | Args: 221 | secure (bool): Set to true to cancel on the blockchain by spending the coin(s) being offered; 222 | set to false to cancel in the wallet only. This parameter is required. 223 | trade_id (str): The ID of the offer to cancel. This parameter is required. 224 | fee (int, optional): An optional blockchain fee, in mojos. 225 | 226 | Returns: 227 | dict: Response from the RPC. 228 | """ 229 | try: 230 | data = { 231 | "secure": secure, 232 | "trade_id": trade_id, 233 | } 234 | if fee is not None: 235 | data["fee"] = fee 236 | 237 | result = self.__chia_rpc__.submit("cancel_offer", json.dumps(data)) 238 | return json.loads(result) 239 | except Exception as e: 240 | return {"error": str(e)} 241 | 242 | def cat_get_asset_id(self, wallet_id: int) -> dict: 243 | """ 244 | Retrieve the asset ID from a CAT wallet. 245 | 246 | Args: 247 | wallet_id (int): The wallet ID of the CAT whose ID you would like to retrieve. This parameter is required. 248 | 249 | Returns: 250 | dict: Response from the RPC. 251 | """ 252 | try: 253 | data = {"wallet_id": wallet_id} 254 | result = self.__chia_rpc__.submit("cat_get_asset_id", json.dumps(data)) 255 | return json.loads(result) 256 | except Exception as e: 257 | return {"error": str(e)} 258 | 259 | def cat_get_name(self, wallet_id: int) -> dict: 260 | """ 261 | Get the name of a CAT associated with a wallet ID. 262 | 263 | Args: 264 | wallet_id (int): The wallet ID of the CAT whose name you would like to retrieve. This parameter is required. 265 | 266 | Returns: 267 | dict: Response from the RPC. 268 | """ 269 | try: 270 | data = {"wallet_id": wallet_id} 271 | result = self.__chia_rpc__.submit("cat_get_name", json.dumps(data)) 272 | return json.loads(result) 273 | except Exception as e: 274 | return {"error": str(e)} 275 | 276 | def cat_set_name(self, wallet_id: int, name: str) -> dict: 277 | """ 278 | Rename a CAT wallet. 279 | 280 | Args: 281 | wallet_id (int): The ID of the wallet whose name you would like to change. This parameter is required. 282 | name (str): The new name for the wallet. This parameter is required. 283 | 284 | Returns: 285 | dict: Response from the RPC. 286 | """ 287 | try: 288 | data = {"wallet_id": wallet_id, "name": name} 289 | result = self.__chia_rpc__.submit("cat_set_name", json.dumps(data)) 290 | return json.loads(result) 291 | except Exception as e: 292 | return {"error": str(e)} 293 | 294 | def cat_spend( 295 | self, 296 | wallet_id: str, 297 | inner_address: str, 298 | coins: list = None, 299 | amount: int = None, 300 | fee: int = None, 301 | memos: list = None, 302 | min_coin_amount: int = 0, 303 | max_coin_amount: int = 0, 304 | exclude_coin_amounts: list = None, 305 | exclude_coin_ids: list = None, 306 | reuse_puzhash: bool = False, 307 | ) -> dict: 308 | """ 309 | Send CAT funds to another wallet. 310 | 311 | Args: 312 | wallet_id (str): The wallet ID for the origin of the transaction. 313 | inner_address (str): The destination address. 314 | coins (list, optional): A list of coins to include in the spend. 315 | amount (int, optional): The number of mojos to send. 316 | fee (int, optional): An optional blockchain fee, in mojos. 317 | memos (list, optional): An optional array of memos to be sent with the transaction. 318 | min_coin_amount (int, optional): The minimum coin amount to send. Defaults to 0. 319 | max_coin_amount (int, optional): The maximum coin amount to send. Defaults to 0. 320 | exclude_coin_amounts (list, optional): A list of coin amounts to exclude. 321 | exclude_coin_ids (list, optional): A list of coin IDs to exclude. 322 | reuse_puzhash (bool, optional): If true, will not generate a new puzzle hash / address for this transaction only. 323 | 324 | Returns: 325 | dict: Response from the RPC. 326 | """ 327 | try: 328 | data = { 329 | "wallet_id": wallet_id, 330 | "inner_address": inner_address, 331 | } 332 | if coins is not None: 333 | data["coins"] = coins 334 | if amount is not None: 335 | data["amount"] = amount 336 | if fee is not None: 337 | data["fee"] = fee 338 | if memos is not None: 339 | data["memos"] = memos 340 | if min_coin_amount != 0: 341 | data["min_coin_amount"] = min_coin_amount 342 | if max_coin_amount != 0: 343 | data["max_coin_amount"] = max_coin_amount 344 | if exclude_coin_amounts is not None: 345 | data["exclude_coin_amounts"] = exclude_coin_amounts 346 | if exclude_coin_ids is not None: 347 | data["exclude_coin_ids"] = exclude_coin_ids 348 | if reuse_puzhash: 349 | data["reuse_puzhash"] = reuse_puzhash 350 | 351 | result = self.__chia_rpc__.submit("cat_spend", json.dumps(data)) 352 | return json.loads(result) 353 | except Exception as e: 354 | return {"error": str(e)} 355 | 356 | def check_offer_validity(self, offer: str) -> dict: 357 | """ 358 | Check if an offer is valid. 359 | 360 | Args: 361 | offer (str): The contents of the offer to check. This parameter is required. 362 | 363 | Returns: 364 | dict: Response from the RPC. 365 | """ 366 | try: 367 | data = {"offer": offer} 368 | result = self.__chia_rpc__.submit("check_offer_validity", json.dumps(data)) 369 | return json.loads(result) 370 | except Exception as e: 371 | return {"error": str(e)} 372 | 373 | def create_offer_for_ids( 374 | self, 375 | offer: str, 376 | driver_dict: dict = None, 377 | fee: int = None, 378 | validate_only: bool = False, 379 | min_coin_amount: int = None, 380 | max_coin_amount: int = None, 381 | solver: str = None, 382 | reuse_puzhash: bool = False, 383 | min_height: int = None, 384 | min_time: int = None, 385 | max_height: int = None, 386 | max_time: int = None, 387 | ) -> dict: 388 | """ 389 | Create a new offer. 390 | 391 | Args: 392 | offer (str): The offer to create. This parameter is required. 393 | driver_dict (dict, optional): A dictionary of keys and values associated with the offer. Defaults to an empty dictionary. 394 | fee (int, optional): An optional blockchain fee, in mojos. 395 | validate_only (bool, optional): Only validate the offer instead of creating it. Defaults to False. 396 | min_coin_amount (int, optional): The minimum coin amount to select for the offer. 397 | max_coin_amount (int, optional): The maximum coin amount to select for the offer. 398 | solver (str, optional): A marshalled solver. 399 | reuse_puzhash (bool, optional): If true, will not generate a new puzzle hash / address for this transaction only. 400 | min_height (int, optional): Minimum block height. 401 | min_time (int, optional): Minimum UNIX timestamp. 402 | max_height (int, optional): Maximum block height. 403 | max_time (int, optional): Maximum UNIX timestamp. 404 | 405 | Returns: 406 | dict: Response from the RPC. 407 | """ 408 | try: 409 | if driver_dict is None: 410 | driver_dict = {} 411 | 412 | data = {"offer": offer, "driver_dict": driver_dict} 413 | 414 | optional_fields = { 415 | "fee": fee, 416 | "validate_only": validate_only, 417 | "min_coin_amount": min_coin_amount, 418 | "max_coin_amount": max_coin_amount, 419 | "solver": solver, 420 | "reuse_puzhash": reuse_puzhash, 421 | "min_height": min_height, 422 | "min_time": min_time, 423 | "max_height": max_height, 424 | "max_time": max_time, 425 | } 426 | 427 | for key, value in optional_fields.items(): 428 | if value is not None: 429 | data[key] = value 430 | 431 | result = self.__chia_rpc__.submit("create_offer_for_ids", json.dumps(data)) 432 | return json.loads(result) 433 | except Exception as e: 434 | return {"error": str(e)} 435 | 436 | def get_all_offers( 437 | self, 438 | start: Optional[int] = None, 439 | end: Optional[int] = None, 440 | exclude_my_offers: Optional[bool] = None, 441 | exclude_taken_offers: Optional[bool] = None, 442 | include_completed: Optional[bool] = None, 443 | reverse: Optional[bool] = None, 444 | file_contents: Optional[bool] = None, 445 | sort_key: Optional[str] = None, 446 | ) -> dict: 447 | """ 448 | Show the details of all offers for this wallet. 449 | 450 | Args: 451 | start (int, optional): The sequence number of the first offer to show. If None, it's excluded from the call. 452 | end (int, optional): The sequence number of the last offer to show. If None, it's excluded from the call. 453 | exclude_my_offers (bool, optional): Set to true to exclude offers you originated. If None, it's excluded from the call. 454 | exclude_taken_offers (bool, optional): Set to true to exclude offers that have already been taken. If None, it's excluded from the call. 455 | include_completed (bool, optional): Set to true to include offers that have been taken. If None, it's excluded from the call. 456 | reverse (bool, optional): Set to true to sort the results in reverse order. If None, it's excluded from the call. 457 | file_contents (bool, optional): Set to true to display the contents of each offer. If None, it's excluded from the call. 458 | sort_key (str, optional): Specify the key for sorting. If None, it's excluded from the call. 459 | 460 | Returns: 461 | dict: Response from the RPC. 462 | """ 463 | try: 464 | data = {} 465 | 466 | optional_fields = { 467 | "start": start, 468 | "end": end, 469 | "exclude_my_offers": exclude_my_offers, 470 | "exclude_taken_offers": exclude_taken_offers, 471 | "include_completed": include_completed, 472 | "reverse": reverse, 473 | "file_contents": file_contents, 474 | "sort_key": sort_key, 475 | } 476 | 477 | for key, value in optional_fields.items(): 478 | if value is not None: 479 | data[key] = value 480 | 481 | result = self.__chia_rpc__.submit("get_all_offers", json.dumps(data)) 482 | return json.loads(result) 483 | except Exception as e: 484 | return {"error": str(e)} 485 | 486 | def get_offer(self, trade_id: str, file_contents: Optional[bool] = True) -> dict: 487 | """ 488 | Retrieves an offer by trade_id in CAT Wallet. 489 | 490 | Args: 491 | trade_id (str): Trade ID of the offer to retrieve. This parameter is required. 492 | file_contents (bool, optional): Whether to include file contents or not. Defaults to True. 493 | 494 | Returns: 495 | dict: Response from the RPC. 496 | """ 497 | try: 498 | data = {"trade_id": trade_id, "file_contents": file_contents} 499 | result = self.__chia_rpc__.submit("get_offer", json.dumps(data)) 500 | return json.loads(result) 501 | except Exception as e: 502 | return {"error": str(e)} 503 | 504 | def get_offer_summary(self, offer: str, advanced: Optional[bool] = False) -> dict: 505 | """ 506 | Retrieves a summary of an offer in CAT Wallet. 507 | 508 | Args: 509 | offer (str): Offer ID or Trade ID of the offer to retrieve. This parameter is required. 510 | advanced (bool, optional): Whether to include advanced details in the summary. Defaults to False. 511 | 512 | Returns: 513 | dict: Response from the RPC. 514 | """ 515 | try: 516 | data = {"offer": offer, "advanced": advanced} 517 | result = self.__chia_rpc__.submit("get_offer_summary", json.dumps(data)) 518 | return json.loads(result) 519 | except Exception as e: 520 | return {"error": str(e)} 521 | 522 | def get_offers_count(self) -> dict: 523 | """ 524 | Retrieves the count of all offers in CAT Wallet. 525 | 526 | Returns: 527 | dict: Response from the RPC. 528 | """ 529 | try: 530 | data = {} 531 | result = self.__chia_rpc__.submit("get_offers_count", json.dumps(data)) 532 | return json.loads(result) 533 | except Exception as e: 534 | return {"error": str(e)} 535 | 536 | def get_stray_cats(self) -> dict: 537 | """ 538 | Get a list of all unacknowledged CATs. 539 | 540 | Returns: 541 | dict: Response from the RPC call. 542 | """ 543 | try: 544 | data = {} 545 | result = self.__chia_rpc__.submit("get_stray_cats", json.dumps(data)) 546 | return json.loads(result) 547 | except Exception as e: 548 | return {"error": str(e)} 549 | 550 | def select_coins( 551 | self, 552 | wallet_id: int, 553 | amount: int, 554 | min_coin_amount: int, 555 | excluded_coins: Optional[List[Dict]] = None, 556 | max_coin_amount: Optional[int] = None, 557 | exclude_coin_amounts: Optional[List[int]] = None, 558 | ) -> dict: 559 | """ 560 | Selects coins in CAT Wallet for creating an offer using RPC. 561 | 562 | Args: 563 | wallet_id (int): ID of the wallet from which to select coins. This parameter is required. 564 | amount (int): Amount of coins to select. This parameter is required. 565 | min_coin_amount (int): Minimum amount of coins to select. This parameter is required. 566 | excluded_coins (List[Dict], optional): List of dictionaries containing excluded coin details. 567 | max_coin_amount (int, optional): Maximum amount of coins to select. 568 | exclude_coin_amounts (List[int], optional): List of coin amounts to exclude from selection. 569 | 570 | Returns: 571 | dict: Response from the RPC call. 572 | """ 573 | try: 574 | data = { 575 | "wallet_id": wallet_id, 576 | "amount": amount, 577 | "min_coin_amount": min_coin_amount, 578 | "excluded_coins": excluded_coins, 579 | "max_coin_amount": max_coin_amount, 580 | "exclude_coin_amounts": exclude_coin_amounts, 581 | } 582 | result = self.__chia_rpc__.submit("select_coins", json.dumps(data)) 583 | return json.loads(result) 584 | except Exception as e: 585 | return {"error": str(e)} 586 | 587 | def take_offer( 588 | self, 589 | offer: str, 590 | fee: int = None, 591 | min_coin_amount: int = None, 592 | max_coin_amount: Optional[int] = None, 593 | solver: Optional[Dict] = None, 594 | reuse_puzhash: Optional[bool] = True, 595 | ) -> dict: 596 | """ 597 | Takes an offer in CAT Wallet using RPC. 598 | 599 | Args: 600 | offer (str): Trade ID of the offer to take. This parameter is required. 601 | fee (int): Fee to offer in addition to the original offer. This parameter is required. 602 | min_coin_amount (int, optional): Minimum amount of coins to use for solving the puzzle. Defaults to 0. 603 | max_coin_amount (int, optional): Maximum amount of coins to use for solving the puzzle. 604 | solver (Dict, optional): Dictionary containing solver options. 605 | reuse_puzhash (bool, optional): Whether to reuse the puzzle hash from the original offer. Defaults to True. 606 | 607 | Returns: 608 | dict: Response from the RPC call. 609 | """ 610 | try: 611 | data = { 612 | "offer": offer, 613 | "fee": fee, 614 | "min_coin_amount": min_coin_amount, 615 | "max_coin_amount": max_coin_amount, 616 | "solver": solver, 617 | "reuse_puzhash": reuse_puzhash, 618 | } 619 | result = self.__chia_rpc__.submit("take_offer", json.dumps(data)) 620 | return json.loads(result) 621 | except Exception as e: 622 | return {"error": str(e)} 623 | 624 | 625 | class DidWallet: 626 | # TODO Type Hints Doc Strings 627 | def __init__(self, url: str = None, cert: str = None): 628 | """ 629 | Initialize DidWallet instance. 630 | 631 | Args: 632 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 633 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 634 | """ 635 | self.__url__ = url 636 | self.__cert__ = cert 637 | self.__chia_rpc__ = WalletRPC(url, cert) 638 | 639 | def did_create_attest(self, wallet_id, coin_name, pubkey, puzhash): 640 | """ 641 | Create a DID attest for a specific DID wallet. 642 | 643 | Args: 644 | wallet_id (int): ID of the DID wallet to create the attest from. 645 | coin_name (str): Name of the coin to create the attest for. 646 | pubkey (str): Public key for the attest. 647 | puzhash (str): Puzhash for the attest. 648 | 649 | Returns: 650 | dict: A dictionary containing the result of the operation. 651 | """ 652 | # Construct the request payload 653 | payload = { 654 | "wallet_id": wallet_id, 655 | "coin_name": coin_name, 656 | "pubkey": pubkey, 657 | "puzhash": puzhash, 658 | } 659 | 660 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 661 | result = self.__chia_rpc__.submit("did_create_attest", json.dumps(payload)) 662 | 663 | # Parse the JSON response and return the result 664 | return json.loads(result) 665 | 666 | def did_create_backup_file(self, wallet_id): 667 | """ 668 | Create a backup file for a specific DID wallet. 669 | 670 | Args: 671 | wallet_id (int): ID of the DID wallet to create the backup file. 672 | 673 | Returns: 674 | dict: A dictionary containing the result of the operation. 675 | """ 676 | # Construct the request payload 677 | payload = {"wallet_id": wallet_id} 678 | 679 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 680 | result = self.__chia_rpc__.submit("did_create_backup_file", json.dumps(payload)) 681 | 682 | # Parse the JSON response and return the result 683 | return json.loads(result) 684 | 685 | def did_find_lost_did(self, coin_id): 686 | """ 687 | Find a lost DID for a specific coin ID. 688 | 689 | Args: 690 | coin_id (str): Coin ID to search for the lost DID. 691 | 692 | Returns: 693 | dict: A dictionary containing the result of the operation. 694 | """ 695 | # Construct the request payload 696 | payload = {"coin_id": coin_id} 697 | 698 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 699 | result = self.__chia_rpc__.submit("did_find_lost_did", json.dumps(payload)) 700 | 701 | # Parse the JSON response and return the result 702 | return json.loads(result) 703 | 704 | def did_get_current_coin_info(self, wallet_id): 705 | """ 706 | Get the current coin info for a specific DID wallet. 707 | 708 | Args: 709 | wallet_id (int): ID of the DID wallet to retrieve coin info from. 710 | 711 | Returns: 712 | dict: A dictionary containing the result of the operation. 713 | """ 714 | # Construct the request payload 715 | payload = {"wallet_id": wallet_id} 716 | 717 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 718 | result = self.__chia_rpc__.submit( 719 | "did_get_current_coin_info", json.dumps(payload) 720 | ) 721 | 722 | # Parse the JSON response and return the result 723 | return json.loads(result) 724 | 725 | def did_get_did(self, wallet_id): 726 | """ 727 | Retrieve the distributed identity (DID) associated with a specific DID wallet. 728 | 729 | Args: 730 | wallet_id (int): ID of the DID wallet to retrieve the associated DID from. 731 | 732 | Returns: 733 | dict: A dictionary containing the result of the operation. 734 | """ 735 | # Construct the request payload 736 | payload = {"wallet_id": wallet_id} 737 | 738 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 739 | result = self.__chia_rpc__.submit("did_get_did", json.dumps(payload)) 740 | 741 | # Parse the JSON response and return the result 742 | return json.loads(result) 743 | 744 | def did_get_info(self, coin_id, latest=True): 745 | """ 746 | Retrieve information about a specific distributed identity (DID) associated with a given coin ID. 747 | 748 | Args: 749 | coin_id (str): Coin ID of the DID to retrieve information for. 750 | latest (bool): Flag indicating whether to retrieve the latest information (default is True). 751 | 752 | Returns: 753 | dict: A dictionary containing the result of the operation. 754 | """ 755 | # Construct the request payload 756 | payload = {"coin_id": coin_id, "latest": latest} 757 | 758 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 759 | result = self.__chia_rpc__.submit("did_get_info", json.dumps(payload)) 760 | 761 | # Parse the JSON response and return the result 762 | return json.loads(result) 763 | 764 | def did_get_information_needed_for_recovery(self, wallet_id): 765 | """ 766 | Retrieve recovery information needed for a specific distributed identity (DID) wallet. 767 | 768 | Args: 769 | wallet_id (int): Wallet ID of the DID wallet to retrieve recovery information for. 770 | 771 | Returns: 772 | dict: A dictionary containing the result of the operation. 773 | """ 774 | # Construct the request payload 775 | payload = {"wallet_id": wallet_id} 776 | 777 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 778 | result = self.__chia_rpc__.submit( 779 | "did_get_information_needed_for_recovery", json.dumps(payload) 780 | ) 781 | 782 | # Parse the JSON response and return the result 783 | return json.loads(result) 784 | 785 | def did_get_metadata(self, wallet_id): 786 | """ 787 | Retrieve metadata of a specific distributed identity (DID) wallet. 788 | 789 | Args: 790 | wallet_id (int): Wallet ID of the DID wallet to retrieve metadata for. 791 | 792 | Returns: 793 | dict: A dictionary containing the result of the operation. 794 | """ 795 | # Construct the request payload 796 | payload = {"wallet_id": wallet_id} 797 | 798 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 799 | result = self.__chia_rpc__.submit("did_get_metadata", json.dumps(payload)) 800 | 801 | # Parse the JSON response and return the result 802 | return json.loads(result) 803 | 804 | def did_get_pubkey(self, wallet_id): 805 | """ 806 | Retrieve the public key of a specific distributed identity (DID) wallet. 807 | 808 | Args: 809 | wallet_id (int): Wallet ID of the DID wallet to retrieve the public key for. 810 | 811 | Returns: 812 | dict: A dictionary containing the result of the operation. 813 | """ 814 | # Construct the request payload 815 | payload = {"wallet_id": wallet_id} 816 | 817 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 818 | result = self.__chia_rpc__.submit("did_get_pubkey", json.dumps(payload)) 819 | 820 | # Parse the JSON response and return the result 821 | return json.loads(result) 822 | 823 | def did_get_recovery_list(self, wallet_id): 824 | """ 825 | Retrieve the recovery list for a specific distributed identity (DID) wallet. 826 | 827 | Args: 828 | wallet_id (int): Wallet ID of the DID wallet to retrieve the recovery list for. 829 | 830 | Returns: 831 | dict: A dictionary containing the result of the operation. 832 | """ 833 | # Construct the request payload 834 | payload = {"wallet_id": wallet_id} 835 | 836 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 837 | result = self.__chia_rpc__.submit("did_get_recovery_list", json.dumps(payload)) 838 | 839 | # Parse the JSON response and return the result 840 | return json.loads(result) 841 | 842 | def did_get_wallet_name(self, wallet_id): 843 | """ 844 | Retrieve the name of a specific distributed identity (DID) wallet. 845 | 846 | Args: 847 | wallet_id (int): Wallet ID of the DID wallet to retrieve the name for. 848 | 849 | Returns: 850 | dict: A dictionary containing the result of the operation. 851 | """ 852 | # Construct the request payload 853 | payload = {"wallet_id": wallet_id} 854 | 855 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 856 | result = self.__chia_rpc__.submit("did_get_wallet_name", json.dumps(payload)) 857 | 858 | # Parse the JSON response and return the result 859 | return json.loads(result) 860 | 861 | def did_message_spend(self, wallet_id, coin_announcements, puzzle_announcements): 862 | """ 863 | Spend a distributed identity (DID) message from a specific DID wallet. 864 | 865 | Args: 866 | wallet_id (int): Wallet ID of the DID wallet to spend the message from. 867 | coin_announcements (list): List of coin announcements as strings. 868 | puzzle_announcements (list): List of puzzle announcements as strings. 869 | 870 | Returns: 871 | dict: A dictionary containing the result of the operation. 872 | """ 873 | # Construct the request payload 874 | payload = { 875 | "wallet_id": wallet_id, 876 | "coin_announcements": coin_announcements, 877 | "puzzle_announcements": puzzle_announcements, 878 | } 879 | 880 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 881 | result = self.__chia_rpc__.submit(chia_call="did_message_spend", data=json.dumps(obj=payload)) 882 | 883 | # Parse the JSON response and return the result 884 | return json.loads(s=result) 885 | 886 | def did_recovery_spend(self, wallet_id, attest_data, pubkey, puzhash): 887 | """ 888 | Spend from a distributed identity (DID) wallet using recovery data. 889 | 890 | Args: 891 | wallet_id (int): Wallet ID of the DID wallet to spend from. 892 | attest_data (list): List of attest data as strings. 893 | pubkey (str): Public key associated with the DID wallet. 894 | puzhash (str): Puzzled hash associated with the DID wallet. 895 | 896 | Returns: 897 | dict: A dictionary containing the result of the operation. 898 | """ 899 | # Construct the request payload 900 | payload = { 901 | "wallet_id": wallet_id, 902 | "attest_data": attest_data, 903 | "pubkey": pubkey, 904 | "puzhash": puzhash, 905 | } 906 | 907 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 908 | result = self.__chia_rpc__.submit(chia_call="did_recovery_spend", data=json.dumps(obj=payload)) 909 | 910 | # Parse the JSON response and return the result 911 | return json.loads(result) 912 | 913 | def did_set_wallet_name(self, wallet_id, name): 914 | """ 915 | Set the name of a distributed identity (DID) wallet. 916 | 917 | Args: 918 | wallet_id (int): Wallet ID of the DID wallet to set the name for. 919 | name (str): The new name for the DID wallet. 920 | 921 | Returns: 922 | dict: A dictionary containing the result of the operation. 923 | """ 924 | # Construct the request payload 925 | payload = {"wallet_id": wallet_id, "name": name} 926 | 927 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 928 | result = self.__chia_rpc__.submit(chia_call="did_set_wallet_name", data=json.dumps(obj=payload)) 929 | 930 | # Parse the JSON response and return the result 931 | return json.loads(s=result) 932 | 933 | def did_transfer_did( 934 | self, wallet_id, inner_address, fee, with_recovery_info, reuse_puzhash 935 | ): 936 | """ 937 | Transfer a distributed identity (DID) wallet to another owner. 938 | 939 | Args: 940 | wallet_id (int): Wallet ID of the DID wallet to transfer. 941 | inner_address (str): Inner address (Chia address) of the new owner. 942 | fee (float): Transaction fee to include in the transfer. 943 | with_recovery_info (bool): Whether to include recovery information in the transfer. 944 | reuse_puzhash (bool): Whether to reuse the puzzle hash of the DID wallet. 945 | 946 | Returns: 947 | dict: A dictionary containing the result of the operation. 948 | """ 949 | # Construct the request payload 950 | payload = { 951 | "wallet_id": wallet_id, 952 | "inner_address": inner_address, 953 | "fee": fee, 954 | "with_recovery_info": with_recovery_info, 955 | "reuse_puzhash": reuse_puzhash, 956 | } 957 | 958 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 959 | result = self.__chia_rpc__.submit(chia_call="did_transfer_did", data=json.dumps(obj=payload)) 960 | 961 | # Parse the JSON response and return the result 962 | return json.loads(s=result) 963 | 964 | def did_update_metadata(self, wallet_id, metadata, fee=0, reuse_puzhash=True): 965 | """ 966 | Update the metadata of a distributed identity (DID) wallet. 967 | 968 | Args: 969 | wallet_id (int): Wallet ID of the DID wallet to update. 970 | metadata (dict): Dictionary containing the updated metadata. 971 | fee (int, optional): Fee to be paid for the update transaction (default: 0). 972 | reuse_puzhash (bool, optional): Whether to reuse the previous puzzle hash for the update transaction 973 | (default: True). 974 | 975 | Returns: 976 | dict: A dictionary containing the result of the operation. 977 | """ 978 | # Construct the request payload 979 | payload = { 980 | "wallet_id": wallet_id, 981 | "metadata": metadata, 982 | "fee": fee, 983 | "reuse_puzhash": reuse_puzhash, 984 | } 985 | 986 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 987 | result = self.__chia_rpc__.submit(chia_call="did_update_metadata", data=json.dumps(obj=payload)) 988 | 989 | # Parse the JSON response and return the result 990 | return json.loads(result) 991 | 992 | def did_update_recovery_ids( 993 | self, wallet_id, new_list, num_verifications_required=0, reuse_puzhash=True 994 | ): 995 | """ 996 | Update the recovery IDs for a distributed identity (DID) wallet. 997 | 998 | Args: 999 | wallet_id (int): Wallet ID of the DID wallet to update. 1000 | new_list (list): List of new recovery IDs to set. 1001 | num_verifications_required (int, optional): Number of verifications required for recovery 1002 | (default: 0). 1003 | reuse_puzhash (bool, optional): Whether to reuse the previous puzzle hash for the update transaction 1004 | (default: True). 1005 | 1006 | Returns: 1007 | dict: A dictionary containing the result of the operation. 1008 | """ 1009 | # Construct the request payload 1010 | payload = { 1011 | "wallet_id": wallet_id, 1012 | "new_list": new_list, 1013 | "num_verifications_required": num_verifications_required, 1014 | "reuse_puzhash": reuse_puzhash, 1015 | } 1016 | 1017 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1018 | result = self.__chia_rpc__.submit( 1019 | "did_update_recovery_ids", json.dumps(payload) 1020 | ) 1021 | 1022 | # Parse the JSON response and return the result 1023 | return json.loads(result) 1024 | 1025 | 1026 | class KeyManagement: 1027 | def __init__(self, url: Optional[str] = None, cert = None) -> None: 1028 | """ 1029 | Initialize KeyManagement instance. 1030 | 1031 | Args: 1032 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1033 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1034 | """ 1035 | self.__url__ = url 1036 | self.__cert__ = cert 1037 | self.__chia_rpc__ = WalletRPC(url, cert) 1038 | 1039 | def add_key(self, mnemonic: List[str]) -> Dict[str, Union[str, int]]: 1040 | """ 1041 | Adds a new key to the wallet using the provided mnemonic phrase. 1042 | 1043 | Args: 1044 | mnemonic (list): A list of words representing the mnemonic phrase. 1045 | 1046 | Returns: 1047 | dict: A dictionary containing the result of the operation. 1048 | """ 1049 | # Construct the request payload 1050 | payload = {"mnemonic": mnemonic} 1051 | 1052 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1053 | result = self.__chia_rpc__.submit("add_key", json.dumps(payload)) 1054 | 1055 | # Parse the JSON response and return the result 1056 | return json.loads(result) 1057 | 1058 | def check_delete_key(self, fingerprint: int) -> Dict[str, Union[str, bool]]: 1059 | """ 1060 | Determines if it is safe to delete a private key. 1061 | 1062 | Args: 1063 | fingerprint (int): The fingerprint of the private key to check. 1064 | 1065 | Returns: 1066 | dict: A dictionary containing the result of the operation, including whether 1067 | the key is used for farming, pooling, or has a balance. 1068 | """ 1069 | # Construct the request payload 1070 | payload = {"fingerprint": fingerprint} 1071 | 1072 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1073 | result = self.__chia_rpc__.submit("check_delete_key", json.dumps(payload)) 1074 | 1075 | # Parse the JSON response and return the result 1076 | return json.loads(result) 1077 | 1078 | def wallet_delete_all_keys(self) -> Dict[str, str]: 1079 | """ 1080 | Deletes all keys from the keychain. 1081 | 1082 | Returns: 1083 | dict: A dictionary containing the result of the operation. 1084 | """ 1085 | # Construct the request payload 1086 | payload = {} 1087 | 1088 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1089 | result = self.__chia_rpc__.submit("wallet_delete_all_keys", json.dumps(payload)) 1090 | 1091 | # Parse the JSON response and return the result 1092 | return json.loads(result) 1093 | 1094 | def delete_key(self, fingerprint: int) -> Dict[str, Union[str, int]]: 1095 | """ 1096 | Deletes all keys which have the given public key fingerprint. 1097 | 1098 | Args: 1099 | fingerprint (int): The fingerprint of the public key to be deleted. 1100 | 1101 | Returns: 1102 | dict: A dictionary containing the result of the operation. 1103 | """ 1104 | # Construct the request payload 1105 | payload = {"fingerprint": fingerprint} 1106 | 1107 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1108 | result = self.__chia_rpc__.submit("delete_key", json.dumps(payload)) 1109 | 1110 | # Parse the JSON response and return the result 1111 | return json.loads(result) 1112 | 1113 | def generate_mnemonic(self) -> Dict[str, str]: 1114 | """ 1115 | Generates a new mnemonic phrase. 1116 | 1117 | Returns: 1118 | dict: A dictionary containing the result of the operation. 1119 | """ 1120 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1121 | result = self.__chia_rpc__.submit("generate_mnemonic", "{}") 1122 | 1123 | # Parse the JSON response and return the result 1124 | return json.loads(result) 1125 | 1126 | def get_logged_in_fingerprint(self) -> dict: 1127 | """ 1128 | Retrieves the logged in fingerprint. 1129 | 1130 | Returns: 1131 | dict: A dictionary containing the result of the operation. 1132 | """ 1133 | # Define the payload for the RPC call 1134 | payload = {} 1135 | 1136 | # Use the submit method of WalletRpcClient instance to make the Chia 1137 | # RPC call with the payload 1138 | result = self.__chia_rpc__.submit("get_logged_in_fingerprint", payload) 1139 | 1140 | # Parse the JSON response and return the result 1141 | return json.loads(result) 1142 | 1143 | def get_private_key(self, fingerprint: int) -> Dict[str, Union[str, int]]: 1144 | """ 1145 | Retrieves the private key by fingerprint. 1146 | 1147 | Args: 1148 | fingerprint (int): The fingerprint of the private key to retrieve. 1149 | 1150 | Returns: 1151 | dict: A dictionary containing the result of the operation. 1152 | """ 1153 | # Construct the request payload 1154 | payload = {"fingerprint": fingerprint} 1155 | 1156 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1157 | result = self.__chia_rpc__.submit("get_private_key", json.dumps(payload)) 1158 | 1159 | # Parse the JSON response and return the result 1160 | return json.loads(result) 1161 | 1162 | def get_public_keys(self) -> dict: 1163 | """ 1164 | Retrieves all public keys on the node. 1165 | 1166 | Returns: 1167 | dict: A dictionary containing the result of the operation. 1168 | """ 1169 | # Construct the request payload 1170 | payload = {} 1171 | 1172 | # Use the submit method of WalletRpcClient instance to make the Chia 1173 | # RPC call 1174 | result = self.__chia_rpc__.submit("get_public_keys", json.dumps(payload)) 1175 | 1176 | # Parse the JSON response and return the result 1177 | return json.loads(result) 1178 | 1179 | def log_in(self, fingerprint: int) -> dict: 1180 | """ 1181 | Logs in the wallet with a specific key. 1182 | 1183 | Args: 1184 | fingerprint (int): The fingerprint of the key to use for logging in. 1185 | 1186 | Returns: 1187 | dict: A dictionary containing the result of the operation. 1188 | """ 1189 | # Construct the request payload 1190 | payload = {"fingerprint": fingerprint} 1191 | 1192 | # Use the submit method of WalletRpcClient instance to make the Chia 1193 | # RPC call 1194 | result = self.__chia_rpc__.submit("log_in", json.dumps(payload)) 1195 | 1196 | # Parse the JSON response and return the result 1197 | return json.loads(result) 1198 | 1199 | def verify_signature( 1200 | self, pubkey: str, message: str, signature: str, address: str, signing_mode: str 1201 | ) -> dict: 1202 | """ 1203 | Verifies if a signature is valid with the given public key, message, signature, address, and signing mode. 1204 | 1205 | Args: 1206 | pubkey (str): The public key to use for verification. 1207 | message (str): The message to verify the signature against. 1208 | signature (str): The signature to verify. 1209 | address (str): The address associated with the public key. 1210 | signing_mode (str): The signing mode to use for verification. 1211 | 1212 | Returns: 1213 | dict: A dictionary containing the result of the signature verification operation. 1214 | """ 1215 | # Construct the request payload 1216 | payload = { 1217 | "pubkey": pubkey, 1218 | "message": message, 1219 | "signature": signature, 1220 | "address": address, 1221 | "signing_mode": signing_mode, 1222 | } 1223 | 1224 | # Use the submit method of WalletRpcClient instance to make the Chia 1225 | # RPC call 1226 | result = self.__chia_rpc__.submit("verify_signature", json.dumps(payload)) 1227 | 1228 | # Parse the JSON response and return the result 1229 | return json.loads(result) 1230 | 1231 | 1232 | class PoolWallet: 1233 | def __init__(self, url: str = None, cert: str = None): 1234 | """ 1235 | Initialize PoolWallet instance. 1236 | 1237 | Args: 1238 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1239 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1240 | """ 1241 | self.__url__ = url 1242 | self.__cert__ = cert 1243 | self.__chia_rpc__ = WalletRPC(url, cert) 1244 | 1245 | def pw_absorb_rewards(self, wallet_id: int, fee: int) -> dict: 1246 | """ 1247 | Perform a sweep of the p2_singleton rewards controlled by the pool wallet singleton. 1248 | 1249 | Args: 1250 | wallet_id (int): Wallet ID of the pool wallet. 1251 | fee (int): Fee to be paid for the sweep. 1252 | 1253 | Returns: 1254 | dict: A dictionary containing the result of the operation. 1255 | """ 1256 | # Define the payload for the RPC call 1257 | payload = {"wallet_id": wallet_id, "fee": fee} 1258 | 1259 | # Use the submit method of WalletRpcClient instance to make the Chia 1260 | # RPC call with the payload 1261 | result = self.__chia_rpc__.submit("pw_absorb_rewards", json.dumps(payload)) 1262 | 1263 | # Parse the JSON response and return the result 1264 | return json.loads(result) 1265 | 1266 | def pw_join_pool( 1267 | self, 1268 | wallet_id: int, 1269 | target_puzzlehash: str, 1270 | pool___url: str, 1271 | relative_lock_height: int, 1272 | fee: int, 1273 | ) -> dict: 1274 | """ 1275 | Joins the given wallet to a pool. 1276 | 1277 | Args: 1278 | wallet_id (int): Wallet ID of the pool wallet. 1279 | target_puzzlehash (str): Target puzzlehash of the pool. 1280 | pool___url (str): __URL of the pool to join. 1281 | relative_lock_height (int): Relative lock height for the join transaction. 1282 | fee (int): Fee to be paid for the join transaction. 1283 | 1284 | Returns: 1285 | dict: A dictionary containing the result of the operation. 1286 | """ 1287 | # Define the payload for the RPC call 1288 | payload = { 1289 | "wallet_id": wallet_id, 1290 | "target_puzzlehash": target_puzzlehash, 1291 | "pool___url": pool___url, 1292 | "relative_lock_height": relative_lock_height, 1293 | "fee": fee, 1294 | } 1295 | 1296 | # Use the submit method of WalletRpcClient instance to make the Chia 1297 | # RPC call with the payload 1298 | result = self.__chia_rpc__.submit("pw_join_pool", json.dumps(payload)) 1299 | 1300 | # Parse the JSON response and return the result 1301 | return json.loads(result) 1302 | 1303 | def pw_self_pool(self, wallet_id: int, fee: int) -> dict: 1304 | """ 1305 | Removes the given wallet from a pool. 1306 | 1307 | Args: 1308 | wallet_id (int): Wallet ID of the pool wallet. 1309 | fee (int): Fee to be paid for the pool removal transaction. 1310 | 1311 | Returns: 1312 | dict: A dictionary containing the result of the operation. 1313 | """ 1314 | # Define the payload for the RPC call 1315 | payload = {"wallet_id": wallet_id, "fee": fee} 1316 | 1317 | # Use the submit method of WalletRpcClient instance to make the Chia 1318 | # RPC call with the payload 1319 | result = self.__chia_rpc__.submit("pw_self_pool", json.dumps(payload)) 1320 | 1321 | # Parse the JSON response and return the result 1322 | return json.loads(result) 1323 | 1324 | def pw_status(self, wallet_id: int) -> dict: 1325 | """ 1326 | Returns the complete state of the given Pool wallet. 1327 | 1328 | Args: 1329 | wallet_id (int): Wallet ID of the pool wallet. 1330 | 1331 | Returns: 1332 | dict: A dictionary containing the result of the operation. 1333 | """ 1334 | # Define the payload for the RPC call 1335 | payload = {"wallet_id": wallet_id} 1336 | 1337 | # Use the submit method of WalletRpcClient instance to make the Chia 1338 | # RPC call with the payload 1339 | result = self.__chia_rpc__.submit("pw_status", json.dumps(payload)) 1340 | 1341 | # Parse the JSON response and return the result 1342 | return json.loads(result) 1343 | 1344 | 1345 | class Notifications: 1346 | def __init__(self, url: str = None, cert: str = None): 1347 | """ 1348 | Initialize Notifications instance. 1349 | 1350 | Args: 1351 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1352 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1353 | """ 1354 | self.__url__ = url 1355 | self.__cert__ = cert 1356 | self.__chia_rpc__ = WalletRPC(url, cert) 1357 | 1358 | def delete_notifications(self, ids: list) -> dict: 1359 | """ 1360 | Deletes notifications. 1361 | 1362 | Args: 1363 | ids (list): A list of notification IDs to be deleted. 1364 | 1365 | Returns: 1366 | dict: A dictionary containing the result of the operation. 1367 | """ 1368 | # Define the payload for the RPC call 1369 | payload = {"ids": ids} 1370 | 1371 | # Use the submit method of WalletRpcClient instance to make the Chia 1372 | # RPC call with the payload 1373 | result = self.__chia_rpc__.submit("delete_notifications", json.dumps(payload)) 1374 | 1375 | # Parse the JSON response and return the result 1376 | return json.loads(result) 1377 | 1378 | def get_notifications(self, ids: list, start: int, end: int) -> dict: 1379 | """ 1380 | Retrieves notifications. 1381 | 1382 | Args: 1383 | ids (list): A list of notification IDs to be retrieved. 1384 | start (int): The starting index of the notifications to retrieve. 1385 | end (int): The ending index of the notifications to retrieve. 1386 | 1387 | Returns: 1388 | dict: A dictionary containing the result of the operation. 1389 | """ 1390 | # Define the payload for the RPC call 1391 | payload = {"ids": ids, "start": start, "end": end} 1392 | 1393 | # Use the submit method of WalletRpcClient instance to make the Chia 1394 | # RPC call with the payload 1395 | result = self.__chia_rpc__.submit("get_notifications", json.dumps(payload)) 1396 | 1397 | # Parse the JSON response and return the result 1398 | return json.loads(result) 1399 | 1400 | def send_notification( 1401 | self, target: str, message: str, amount: int, fee: int 1402 | ) -> dict: 1403 | """ 1404 | Sends a notification. 1405 | 1406 | Args: 1407 | target (str): The target of the notification. 1408 | message (str): The message of the notification. 1409 | amount (int): The amount associated with the notification. 1410 | fee (int): The fee to be paid for the notification. 1411 | 1412 | Returns: 1413 | dict: A dictionary containing the result of the operation. 1414 | """ 1415 | # Define the payload for the RPC call 1416 | payload = {"target": target, "message": message, "amount": amount, "fee": fee} 1417 | 1418 | # Use the submit method of WalletRpcClient instance to make the Chia 1419 | # RPC call with the payload 1420 | result = self.__chia_rpc__.submit("send_notification", json.dumps(payload)) 1421 | 1422 | # Parse the JSON response and return the result 1423 | return json.loads(result) 1424 | 1425 | def sign_message_by_address( 1426 | self, address: str, message: str, is_hex: bool = False 1427 | ) -> dict: 1428 | """ 1429 | Given a derived P2 address, sign the message by its private key. 1430 | 1431 | Args: 1432 | address (str): The derived P2 address. 1433 | message (str): The message to be signed. 1434 | is_hex (bool, optional): Flag indicating if the message is in hexadecimal format. Defaults to False. 1435 | 1436 | Returns: 1437 | dict: A dictionary containing the result of the operation. 1438 | """ 1439 | # Define the payload for the RPC call 1440 | payload = {"address": address, "message": message, "is_hex": is_hex} 1441 | 1442 | # Use the submit method of WalletRpcClient instance to make the Chia 1443 | # RPC call with the payload 1444 | result = self.__chia_rpc__.submit( 1445 | "sign_message_by_address", json.dumps(payload) 1446 | ) 1447 | 1448 | # Parse the JSON response and return the result 1449 | return json.loads(result) 1450 | 1451 | def sign_message_by_id(self, id: str, message: str, is_hex: bool = False) -> dict: 1452 | """ 1453 | Given a NFT/DID ID, sign the message by the P2 private key. 1454 | 1455 | Args: 1456 | id (str): The NFT/DID ID. 1457 | message (str): The message to be signed. 1458 | is_hex (bool, optional): Flag indicating if the message is in hexadecimal format. Defaults to False. 1459 | 1460 | Returns: 1461 | dict: A dictionary containing the result of the operation. 1462 | """ 1463 | # Define the payload for the RPC call 1464 | payload = {"id": id, "message": message, "is_hex": is_hex} 1465 | 1466 | # Use the submit method of WalletRpcClient instance to make the Chia 1467 | # RPC call with the payload 1468 | result = self.__chia_rpc__.submit("sign_message_by_id", json.dumps(payload)) 1469 | 1470 | # Parse the JSON response and return the result 1471 | return json.loads(result) 1472 | 1473 | 1474 | class Wallet: 1475 | def __init__(self, url: str = None, cert: str = None): 1476 | """ 1477 | Initialize Wallet instance. 1478 | 1479 | Args: 1480 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1481 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1482 | """ 1483 | self.__url__ = url 1484 | self.__cert__ = cert 1485 | self.__chia_rpc__ = WalletRPC(url, cert) 1486 | 1487 | def create_signed_transaction( 1488 | self, 1489 | wallet_id, 1490 | additions, 1491 | fee, 1492 | coins, 1493 | coin_announcements=None, 1494 | puzzle_announcements=None, 1495 | min_coin_amount=0, 1496 | max_coin_amount=0, 1497 | excluded_coins=None, 1498 | excluded_coin_amounts=None, 1499 | ): 1500 | """ 1501 | Create a signed transaction for sending Chia coins. 1502 | 1503 | Args: 1504 | wallet_id (int): ID of the wallet to use for creating the transaction. 1505 | additions (list): List of dictionaries representing the recipients of the transaction. 1506 | Each dictionary should contain the following keys: 1507 | - 'amount' (int): The amount to send in mojos (1 XCH = 10^12 mojos). 1508 | - 'puzzle_hash' (str): The puzzle hash of the recipient's address. 1509 | - 'memos' (list): Optional list of memos to include in the transaction. 1510 | fee (float): The transaction fee to be paid in XCH. 1511 | coins (list): List of coin IDs to use for the transaction. 1512 | coin_announcements (list): Coin announcements for the transaction. Optional. 1513 | puzzle_announcements (list): Puzzle announcements for the transaction. Optional. 1514 | min_coin_amount (int): Minimum coin amount for coin selection. Default is 0. 1515 | max_coin_amount (int): Maximum coin amount for coin selection. Default is 0. 1516 | excluded_coins (list): List of dictionaries representing coins to be excluded from coin selection. 1517 | Each dictionary should contain the following keys: 1518 | - 'parent_coin_info' (str): The parent coin ID. 1519 | - 'puzzle_hash' (str): The puzzle hash of the coin. 1520 | - 'amount' (int): The amount of the coin in mojos. 1521 | excluded_coin_amounts (list): List of excluded coin amounts for coin selection. 1522 | 1523 | Returns: 1524 | dict: A dictionary containing the signed transaction data. 1525 | """ 1526 | # Construct the request payload 1527 | payload = { 1528 | "wallet_id": wallet_id, 1529 | "additions": additions, 1530 | "fee": fee, 1531 | "coins": coins, 1532 | "coin_announcements": coin_announcements, 1533 | "puzzle_announcements": puzzle_announcements, 1534 | "min_coin_amount": min_coin_amount, 1535 | "max_coin_amount": max_coin_amount, 1536 | "excluded_coins": excluded_coins, 1537 | "excluded_coin_amounts": excluded_coin_amounts, 1538 | } 1539 | 1540 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1541 | result = self.__chia_rpc__.submit( 1542 | "create_signed_transaction", json.dumps(payload) 1543 | ) 1544 | 1545 | # Parse the JSON response and return the result 1546 | return json.loads(result) 1547 | 1548 | def delete_unconfirmed_transactions(self, wallet_id): 1549 | """ 1550 | Delete unconfirmed transactions for a specific wallet. 1551 | 1552 | Args: 1553 | wallet_id (int): ID of the wallet for which to delete unconfirmed transactions. 1554 | 1555 | Returns: 1556 | dict: A dictionary containing the result of the operation. 1557 | """ 1558 | # Construct the request payload 1559 | payload = {"wallet_id": wallet_id} 1560 | 1561 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1562 | result = self.__chia_rpc__.submit( 1563 | "delete_unconfirmed_transactions", json.dumps(payload) 1564 | ) 1565 | 1566 | # Parse the JSON response and return the result 1567 | return json.loads(result) 1568 | 1569 | def extend_derivation_index(self, index): 1570 | """ 1571 | Extend the derivation index of a wallet. 1572 | 1573 | Args: 1574 | index (int): The derivation index to extend. 1575 | 1576 | Returns: 1577 | dict: A dictionary containing the result of the operation. 1578 | """ 1579 | # Construct the request payload 1580 | payload = {"index": index} 1581 | 1582 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1583 | result = self.__chia_rpc__.submit( 1584 | "extend_derivation_index", json.dumps(payload) 1585 | ) 1586 | 1587 | # Parse the JSON response and return the result 1588 | return json.loads(result) 1589 | 1590 | def get_current_derivation_index(self): 1591 | """ 1592 | Get the current derivation index for the default wallet. 1593 | 1594 | Returns: 1595 | dict: A dictionary containing the result of the operation. 1596 | """ 1597 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1598 | result = self.__chia_rpc__.submit( 1599 | "get_current_derivation_index", json.dumps({}) 1600 | ) 1601 | 1602 | # Parse the JSON response and return the result 1603 | return json.loads(result) 1604 | 1605 | def get_farmed_amount(self): 1606 | """ 1607 | Get the total amount of Chia farmed by the default wallet. 1608 | 1609 | Returns: 1610 | dict: A dictionary containing the result of the operation. 1611 | """ 1612 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1613 | result = self.__chia_rpc__.submit("get_farmed_amount", json.dumps({})) 1614 | 1615 | # Parse the JSON response and return the result 1616 | return json.loads(result) 1617 | 1618 | def get_next_address(self, wallet_id, new_address=True): 1619 | """ 1620 | Get the next address for receiving Chia payments for a specific wallet. 1621 | 1622 | Args: 1623 | wallet_id (int): ID of the wallet for which to retrieve the next address. 1624 | new_address (boolean): 1625 | 1626 | Returns: 1627 | dict: A dictionary containing the result of the operation. 1628 | """ 1629 | # Construct the request payload 1630 | payload = {"wallet_id": wallet_id, "new_address": new_address} 1631 | 1632 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1633 | result = self.__chia_rpc__.submit("get_next_address", json.dumps(payload)) 1634 | 1635 | # Parse the JSON response and return the result 1636 | return json.loads(result) 1637 | 1638 | def get_spendable_coins( 1639 | self, 1640 | wallet_id, 1641 | min_coin_amount=0, 1642 | max_coin_amount=0, 1643 | excluded_coin_amounts=None, 1644 | excluded_coins=None, 1645 | excluded_coin_ids=None, 1646 | ): 1647 | """ 1648 | Get the spendable coins for a specific wallet with optional filtering. 1649 | 1650 | Args: 1651 | wallet_id (int): ID of the wallet for which to retrieve spendable coins. 1652 | min_coin_amount (int, optional): Minimum amount of Chia coins to include in the result. Defaults to 0. 1653 | max_coin_amount (int, optional): Maximum amount of Chia coins to include in the result. Defaults to 0. 1654 | excluded_coin_amounts (list of int, optional): List of excluded coin amounts. Defaults to None. 1655 | excluded_coins (list of dict, optional): List of excluded coins in the format 1656 | [{'parent_coin_info': 'hex_string', 'puzzle_hash': 'hex_string', 'amount': int}, ...]. 1657 | Defaults to None. 1658 | excluded_coin_ids (list of str, optional): List of excluded coin IDs. Defaults to None. 1659 | 1660 | Returns: 1661 | dict: A dictionary containing the result of the operation. 1662 | """ 1663 | # Construct the request payload 1664 | payload = { 1665 | "wallet_id": wallet_id, 1666 | "min_coin_amount": min_coin_amount, 1667 | "max_coin_amount": max_coin_amount, 1668 | "excluded_coin_amounts": excluded_coin_amounts or [], 1669 | "excluded_coins": excluded_coins or [], 1670 | "excluded_coin_ids": excluded_coin_ids or [], 1671 | } 1672 | 1673 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1674 | result = self.__chia_rpc__.submit("get_spendable_coins", json.dumps(payload)) 1675 | 1676 | # Parse the JSON response and return the result 1677 | return json.loads(result) 1678 | 1679 | def get_transaction(self, transaction_id): 1680 | """ 1681 | Get information about a specific transaction. 1682 | 1683 | Args: 1684 | transaction_id (str): ID of the transaction to retrieve. 1685 | 1686 | Returns: 1687 | dict: A dictionary containing the result of the operation. 1688 | """ 1689 | # Construct the request payload 1690 | payload = {"transaction_id": transaction_id} 1691 | 1692 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1693 | result = self.__chia_rpc__.submit("get_transaction", json.dumps(payload)) 1694 | 1695 | # Parse the JSON response and return the result 1696 | return json.loads(result) 1697 | 1698 | def get_wallet_transaction_count(self, wallet_id): 1699 | """ 1700 | Get the transaction count for a specific wallet ID. 1701 | 1702 | Args: 1703 | wallet_id (int): ID of the wallet to retrieve transaction count for. 1704 | 1705 | Returns: 1706 | dict: A dictionary containing the result of the operation. 1707 | """ 1708 | # Construct the request payload 1709 | payload = {"wallet_id": wallet_id} 1710 | 1711 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1712 | result = self.__chia_rpc__.submit("get_transaction_count", json.dumps(payload)) 1713 | 1714 | # Parse the JSON response and return the result 1715 | return json.loads(result) 1716 | 1717 | def get_transaction_memo(self, transaction_id): 1718 | """ 1719 | Get the memo of a specific transaction. 1720 | transaction_id (str): ID of the transaction to retrieve memo for. 1721 | 1722 | Returns: 1723 | dict: A dictionary containing the result of the operation. 1724 | """ 1725 | # Construct the request payload 1726 | payload = {"transaction_id": transaction_id} 1727 | 1728 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1729 | result = self.__chia_rpc__.submit("get_transaction_memo", json.dumps(payload)) 1730 | 1731 | # Parse the JSON response and return the result 1732 | return json.loads(result) 1733 | 1734 | def get_transactions(self, wallet_id, start, end, sort_key, reverse): 1735 | """ 1736 | Get transactions for a specific wallet ID with pagination and sorting options. 1737 | 1738 | Args: 1739 | wallet_id (int): ID of the wallet to retrieve transactions for. 1740 | start (int): Starting index of the transactions to retrieve. 1741 | end (int): Ending index of the transactions to retrieve. 1742 | sort_key (str): Key to use for sorting the transactions. 1743 | reverse (bool): Whether to sort the transactions in reverse order. 1744 | 1745 | Returns: 1746 | dict: A dictionary containing the result of the operation. 1747 | """ 1748 | # Construct the request payload 1749 | payload = { 1750 | "wallet_id": wallet_id, 1751 | "start": start, 1752 | "end": end, 1753 | "sort_key": sort_key, 1754 | "reverse": reverse, 1755 | } 1756 | 1757 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1758 | result = self.__chia_rpc__.submit("get_transactions", json.dumps(payload)) 1759 | 1760 | # Parse the JSON response and return the result 1761 | return json.loads(result) 1762 | 1763 | def get_wallet_balance(self, wallet_id): 1764 | """ 1765 | Get the balance of a specific wallet ID. 1766 | 1767 | Args: 1768 | wallet_id (int): ID of the wallet to retrieve balance for. 1769 | 1770 | Returns: 1771 | dict: A dictionary containing the result of the operation. 1772 | """ 1773 | # Construct the request payload 1774 | payload = {"wallet_id": wallet_id} 1775 | 1776 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1777 | result = self.__chia_rpc__.submit("get_wallet_balance", json.dumps(payload)) 1778 | 1779 | # Parse the JSON response and return the result 1780 | return json.loads(result) 1781 | 1782 | def send_transaction( 1783 | self, 1784 | wallet_id, 1785 | amount, 1786 | address, 1787 | fee=None, 1788 | memos=None, 1789 | min_coin_amount=None, 1790 | max_coin_amount=None, 1791 | exclude_coin_amounts=None, 1792 | exclude_coin_ids=None, 1793 | reuse_puzhash=True, 1794 | ): 1795 | """ 1796 | Send a transaction from a specific wallet ID. 1797 | 1798 | Args: 1799 | wallet_id (int): ID of the wallet to send the transaction from. 1800 | amount (int): Amount of Chia to send in mojo. 1801 | address (str): Recipient address for the transaction. 1802 | fee (int): Fee to include in the transaction in mojo. 1803 | memos (list[str], optional): List of memos to include in the transaction. Defaults to None. 1804 | min_coin_amount (int, optional): Minimum coin amount to use for the transaction. Defaults to 0. 1805 | max_coin_amount (int, optional): Maximum coin amount to use for the transaction. Defaults to 0. 1806 | exclude_coin_amounts (list[int], optional): List of coin amounts to exclude from the transaction. 1807 | Defaults to None. 1808 | exclude_coin_ids (list[str], optional): List of coin IDs to exclude from the transaction. Defaults to None. 1809 | reuse_puzhash (bool, optional): Whether to reuse the puzhash of a previous transaction. Defaults to True. 1810 | 1811 | Returns: 1812 | dict: A dictionary containing the result of the operation. 1813 | """ 1814 | # Construct the request payload 1815 | payload = { 1816 | "wallet_id": wallet_id, 1817 | "amount": amount, 1818 | "address": address, 1819 | "reuse_puzhash": reuse_puzhash, 1820 | } 1821 | 1822 | # Include optional arguments only if they are not None 1823 | if fee is not None: 1824 | payload["fee"] = fee 1825 | if memos is not None: 1826 | payload["memos"] = memos 1827 | if min_coin_amount is not None: 1828 | payload["min_coin_amount"] = min_coin_amount 1829 | if max_coin_amount is not None: 1830 | payload["max_coin_amount"] = max_coin_amount 1831 | if exclude_coin_amounts is not None: 1832 | payload["exclude_coin_amounts"] = exclude_coin_amounts 1833 | if exclude_coin_ids is not None: 1834 | payload["exclude_coin_ids"] = exclude_coin_ids 1835 | 1836 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1837 | result = self.__chia_rpc__.submit("send_transaction", json.dumps(payload)) 1838 | 1839 | # Parse the JSON response and return the result 1840 | return json.loads(result) 1841 | 1842 | def send_transaction_multi( 1843 | self, 1844 | wallet_id, 1845 | additions, 1846 | fee=0, 1847 | coins=None, 1848 | coin_announcements=None, 1849 | puzzle_announcements=None, 1850 | ): 1851 | """ 1852 | Send transactions to multiple recipients in a single transaction. 1853 | 1854 | Args: 1855 | wallet_id (int): ID of the wallet to use for sending the transaction. 1856 | additions (list): List of dictionaries representing the recipients of the transaction. 1857 | Each dictionary should contain the following keys: 1858 | - 'amount' (int): The amount to send in mojos (1 XCH = 10^12 mojos). 1859 | - 'puzzle_hash' (str): The puzzle hash of the recipient's address. 1860 | fee (float): The transaction fee to be paid in XCH. 1861 | coins (list): List of coin IDs to use for the transaction. Optional. 1862 | coin_announcements (str): Coin announcements for the transaction. Optional. 1863 | puzzle_announcements (str): Puzzle announcements for the transaction. Optional. 1864 | 1865 | Returns: 1866 | dict: A dictionary containing the result of the transaction, including the transaction ID and status. 1867 | """ 1868 | # Construct the transaction object for send_transaction_multi 1869 | payload = { 1870 | "wallet_id": wallet_id, # Required 1871 | "additions": additions, # Required 1872 | "fee": fee, # Required 1873 | } 1874 | 1875 | # Include optional arguments only if they are not None 1876 | if coins is not None: 1877 | payload["coins"] = coins 1878 | if coin_announcements is not None: 1879 | payload["coin_announcements"] = coin_announcements 1880 | if puzzle_announcements is not None: 1881 | payload["puzzle_announcements"] = puzzle_announcements 1882 | 1883 | # Use the submit method of ChiaRPC instance to make the Chia RPC call 1884 | response = self.__chia_rpc__.submit( 1885 | "send_transaction_multi", json.dumps(payload) 1886 | ) 1887 | 1888 | # Parse the JSON response and return the result 1889 | return json.loads(response) 1890 | 1891 | 1892 | class WalletManagement: 1893 | def __init__(self, url: str = None, cert: str = None): 1894 | """ 1895 | Initialize WalletManagement instance. 1896 | 1897 | Args: 1898 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1899 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1900 | """ 1901 | self.__url__ = url 1902 | self.__cert__ = cert 1903 | self.__chia_rpc__ = WalletRPC(url, cert) 1904 | 1905 | def create_new_wallet( 1906 | self, 1907 | wallet_type: str, 1908 | name: str, 1909 | amount: float, 1910 | fee: float, 1911 | mode: str = "new", 1912 | asset_id: str = None, 1913 | ) -> dict: 1914 | """ 1915 | Creates a new wallet. 1916 | 1917 | Args: 1918 | wallet_type (str): The type of wallet to be created. 1919 | name (str): The name of the new wallet. 1920 | amount (float): The initial amount to be assigned to the new wallet. 1921 | fee (float): The fee to be paid for creating the new wallet. 1922 | mode (str, optional): The mode for creating the new wallet. Defaults to "new". 1923 | asset_id (str, optional): The asset ID for creating the new wallet. Defaults to None. 1924 | 1925 | Returns: 1926 | dict: A dictionary containing the result of the operation. 1927 | """ 1928 | # Define the payload for the RPC call 1929 | payload = { 1930 | "wallet_type": wallet_type, 1931 | "name": name, 1932 | "amount": amount, 1933 | "fee": fee, 1934 | "mode": mode, 1935 | "asset_id": asset_id, 1936 | } 1937 | 1938 | # Use the submit method of WalletRpcClient instance to make the Chia 1939 | # RPC call with the payload 1940 | result = self.__chia_rpc__.submit("create_new_wallet", json.dumps(payload)) 1941 | 1942 | # Parse the JSON response and return the result 1943 | return json.loads(result) 1944 | 1945 | def get_wallets(self, wallet_type: int = 0, include_data: bool = True) -> dict: 1946 | """ 1947 | Retrieves all of the wallets on the node. 1948 | 1949 | Args: 1950 | wallet_type (int, optional): The type of wallets to retrieve. Defaults to 0. 1951 | include_data (bool, optional): Whether to include wallet data in the response. Defaults to True. 1952 | 1953 | Returns: 1954 | dict: A dictionary containing the result of the operation. 1955 | """ 1956 | # Define the payload for the RPC call 1957 | payload = {"type": wallet_type, "include_data": include_data} 1958 | 1959 | # Use the submit method of WalletRpcClient instance to make the Chia 1960 | # RPC call with the payload 1961 | result = self.__chia_rpc__.submit("get_wallets", json.dumps(payload)) 1962 | 1963 | # Parse the JSON response and return the result 1964 | return json.loads(result) 1965 | 1966 | 1967 | class WalletNode: 1968 | def __init__(self, url: str = None, cert: str = None): 1969 | """ 1970 | Initialize WalletNode instance. 1971 | 1972 | Args: 1973 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 1974 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 1975 | """ 1976 | self.__url__ = url 1977 | self.__cert__ = cert 1978 | self.__chia_rpc__ = WalletRPC(url, cert) 1979 | 1980 | def get_height_info(self) -> dict: 1981 | """ 1982 | Retrieves the sync height of the wallet. 1983 | 1984 | Returns: 1985 | dict: A dictionary containing the result of the operation. 1986 | """ 1987 | # Define the payload for the RPC call 1988 | payload = {} 1989 | 1990 | # Use the submit method of WalletRpcClient instance to make the Chia 1991 | # RPC call with the payload 1992 | result = self.__chia_rpc__.submit("get_height_info", json.dumps(payload)) 1993 | 1994 | # Parse the JSON response and return the result 1995 | return json.loads(result) 1996 | 1997 | def get_network_info(self) -> dict: 1998 | """ 1999 | Retrieves some information about the current network. 2000 | 2001 | Returns: 2002 | dict: A dictionary containing the result of the operation. 2003 | """ 2004 | # Define the payload for the RPC call 2005 | payload = {} 2006 | 2007 | # Use the submit method of WalletRpcClient instance to make the Chia 2008 | # RPC call with the payload 2009 | result = self.__chia_rpc__.submit("get_network_info", json.dumps(payload)) 2010 | 2011 | # Parse the JSON response and return the result 2012 | return json.loads(result) 2013 | 2014 | def get_sync_status(self) -> dict: 2015 | """ 2016 | Retrieves the sync status of the wallet. 2017 | 2018 | Returns: 2019 | dict: A dictionary containing the result of the operation. 2020 | """ 2021 | # Define the payload for the RPC call 2022 | payload = {} 2023 | 2024 | # Use the submit method of WalletRpcClient instance to make the Chia 2025 | # RPC call with the payload 2026 | result = self.__chia_rpc__.submit("get_sync_status", json.dumps(payload)) 2027 | 2028 | # Parse the JSON response and return the result 2029 | return json.loads(result) 2030 | 2031 | def get_timestamp_for_height(self, height: int) -> dict: 2032 | """ 2033 | Retrieves the timestamp for a given block height. 2034 | 2035 | Args: 2036 | height (int): The block height to retrieve the timestamp for. 2037 | 2038 | Returns: 2039 | dict: A dictionary containing the result of the operation. 2040 | """ 2041 | # Define the payload for the RPC call 2042 | payload = {"height": height} 2043 | 2044 | # Use the submit method of WalletRpcClient instance to make the Chia 2045 | # RPC call with the payload 2046 | result = self.__chia_rpc__.submit( 2047 | "get_timestamp_for_height", json.dumps(payload) 2048 | ) 2049 | 2050 | # Parse the JSON response and return the result 2051 | return json.loads(result) 2052 | 2053 | def push_transactions(self): 2054 | # TODO Complete Function 2055 | pass 2056 | 2057 | def push_transaction(self, transactions): 2058 | # TODO Requires full review and testing 2059 | """ 2060 | Generates the payload dictionary for pushing multiple transactions to the Chia wallet using the Chia API. 2061 | 2062 | Args: 2063 | transactions (list): A list of transactions to be included in the payload. 2064 | 2065 | Returns: 2066 | dict: A dictionary containing the payload for pushing multiple transactions. 2067 | """ 2068 | payload = {"transactions": transactions} 2069 | 2070 | # Use the submit method of WalletRpcClient instance to make the Chia 2071 | # RPC call with the payload 2072 | result = self.__chia_rpc__.submit("push_tx", json.dumps(payload)) 2073 | 2074 | # Parse the JSON response and return the result 2075 | return json.loads(result) 2076 | 2077 | def set_wallet_resync_on_startup(self, enable: bool) -> dict: 2078 | """ 2079 | Sets the wallet resync on startup flag using the Chia API. 2080 | 2081 | Args: 2082 | enable (bool): Flag to enable or disable wallet resync on startup. 2083 | 2084 | Returns: 2085 | dict: A dictionary containing the result of the operation. 2086 | """ 2087 | # Define the payload for the RPC call 2088 | payload = {"enable": enable} 2089 | 2090 | # Use the submit method of WalletRpcClient instance to make the Chia 2091 | # RPC call with the payload 2092 | result = self.__chia_rpc__.submit( 2093 | "set_wallet_resync_on_startup", json.dumps(payload) 2094 | ) 2095 | 2096 | # Parse the JSON response and return the result 2097 | return json.loads(result) 2098 | 2099 | 2100 | class DataLayerWallet: 2101 | def __init__(self, url: str = None, cert: str = None): 2102 | """ 2103 | Initialize DataLayerManagement instance. 2104 | 2105 | Args: 2106 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 2107 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 2108 | """ 2109 | self.__url__ = url 2110 | self.__cert__ = cert 2111 | self.__chia_rpc__ = WalletRPC(url, cert) 2112 | 2113 | def create_new_dl(self, root: str, fee: int) -> dict: 2114 | """ 2115 | Initializes the DataLayer Wallet using the Chia API. 2116 | 2117 | Args: 2118 | root (str): The root directory of the DataLayer Wallet. 2119 | fee (int): The fee to set for the DataLayer Wallet. 2120 | 2121 | Returns: 2122 | dict: A dictionary containing the result of the operation. 2123 | """ 2124 | # Define the payload for the RPC call 2125 | payload = {"root": root, "fee": fee} 2126 | 2127 | # Use the submit method of WalletRpcClient instance to make the Chia 2128 | # RPC call with the payload 2129 | result = self.__chia_rpc__.submit("create_new_dl", json.dumps(payload)) 2130 | 2131 | # Parse the JSON response and return the result 2132 | return json.loads(result) 2133 | 2134 | def dl_delete_mirror(self, coin_id: str, fee: int) -> dict: 2135 | """ 2136 | Removes an existing mirror for a specific singleton using the Chia API. 2137 | 2138 | Args: 2139 | coin_id (str): The coin ID of the mirror to be removed. 2140 | fee (int): The fee associated with the removal. 2141 | 2142 | Returns: 2143 | dict: A dictionary containing the result of the operation. 2144 | """ 2145 | # Define the payload for the RPC call 2146 | payload = {"coin_id": coin_id, "fee": fee} 2147 | 2148 | # Use the submit method of WalletRpcClient instance to make the Chia 2149 | # RPC call with the payload 2150 | result = self.__chia_rpc__.submit("dl_delete_mirror", json.dumps(payload)) 2151 | 2152 | # Parse the JSON response and return the result 2153 | return json.loads(result) 2154 | 2155 | def dl_get_mirrors(self, launcher_id: str) -> dict: 2156 | """ 2157 | Retrieves all the mirrors for a specific singleton using the Chia API. 2158 | 2159 | Args: 2160 | launcher_id (str): The launcher ID of the singleton to retrieve mirrors for. 2161 | 2162 | Returns: 2163 | dict: A dictionary containing the result of the operation. 2164 | """ 2165 | # Define the payload for the RPC call 2166 | payload = {"launcher_id": launcher_id} 2167 | 2168 | # Use the submit method of WalletRpcClient instance to make the Chia 2169 | # RPC call with the payload 2170 | result = self.__chia_rpc__.submit("dl_get_mirrors", json.dumps(payload)) 2171 | 2172 | # Parse the JSON response and return the result 2173 | return json.loads(result) 2174 | 2175 | def dl_history( 2176 | self, 2177 | launcher_id: str, 2178 | min_generation: int, 2179 | max_generation: int, 2180 | num_results: int, 2181 | ) -> dict: 2182 | """ 2183 | Retrieves the singleton record for the latest singleton of a launcher ID using the Chia API. 2184 | 2185 | Args: 2186 | launcher_id (str): The launcher ID for which to retrieve the singleton history. 2187 | min_generation (int): The minimum generation to retrieve. 2188 | max_generation (int): The maximum generation to retrieve. 2189 | num_results (int): The number of results to retrieve. 2190 | 2191 | Returns: 2192 | dict: A dictionary containing the result of the operation. 2193 | """ 2194 | # Define the payload for the RPC call 2195 | payload = { 2196 | "launcher_id": launcher_id, 2197 | "min_generation": min_generation, 2198 | "max_generation": max_generation, 2199 | "num_results": num_results, 2200 | } 2201 | 2202 | # Use the submit method of WalletRpcClient instance to make the Chia 2203 | # RPC call with the payload 2204 | result = self.__chia_rpc__.submit("dl_history", json.dumps(payload)) 2205 | 2206 | # Parse the JSON response and return the result 2207 | return json.loads(result) 2208 | 2209 | 2210 | class NFTWallet: 2211 | def __init__(self, url: str = None, cert: str = None): 2212 | """ 2213 | Initialize NFTWallet instance. 2214 | 2215 | Args: 2216 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 2217 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 2218 | """ 2219 | self.__url__ = url 2220 | self.__cert__ = cert 2221 | self.__chia_rpc__ = WalletRPC(url, cert) 2222 | 2223 | def nft_add_uri( 2224 | self, 2225 | wallet_id: int, 2226 | uri: str, 2227 | key: str, 2228 | nft_coin_id: str, 2229 | fee: int, 2230 | reuse_puzhash: bool, 2231 | ) -> dict: 2232 | """ 2233 | Adds a URI to an NFT using the Chia API. 2234 | 2235 | Args: 2236 | wallet_id (int): The ID of the wallet to use. 2237 | uri (str): The URI to add. 2238 | key (str): The key to add. 2239 | nft_coin_id (str): The ID of the NFT coin. 2240 | fee (int): The fee to set. 2241 | reuse_puzhash (bool): Whether to reuse the puzhash or not. 2242 | 2243 | Returns: 2244 | dict: A dictionary containing the result of the operation. 2245 | """ 2246 | # Define the payload for the RPC call 2247 | payload = { 2248 | "wallet_id": wallet_id, 2249 | "uri": uri, 2250 | "key": key, 2251 | "nft_coin_id": nft_coin_id, 2252 | "fee": fee, 2253 | "reuse_puzhash": reuse_puzhash, 2254 | } 2255 | 2256 | # Use the submit method of WalletRPCConnect instance to make the Chia 2257 | # RPC call with the payload 2258 | result = self.__chia_rpc__.submit("nft_add_uri", json.dumps(payload)) 2259 | 2260 | # Parse the JSON response and return the result 2261 | return json.loads(result) 2262 | 2263 | 2264 | class Coins: 2265 | def __init__(self, url: str = None, cert: str = None): 2266 | """ 2267 | Initialize Coins instance. 2268 | 2269 | Args: 2270 | __url (str, optional): __URL for ChiaRPC. Defaults to https://localhost:9256/ unless specified. 2271 | __cert (str, optional): __Certificate for ChiaRPC. Default Ceritificates unless specified. 2272 | """ 2273 | self.__url__ = url 2274 | self.__cert__ = cert 2275 | self.__chia_rpc__ = WalletRPC(url, cert) 2276 | 2277 | def get_coin_records_by_names( 2278 | self, names: list, start_height: int, end_height: int, include_spent_coins: bool 2279 | ) -> dict: 2280 | """ 2281 | Retrieves the coins for given coin IDs using the Chia API. 2282 | 2283 | Args: 2284 | names (list): A list of coin IDs to retrieve. 2285 | start_height (int): The start height for coin retrieval. 2286 | end_height (int): The end height for coin retrieval. 2287 | include_spent_coins (bool): A boolean flag indicating whether to include spent coins in the results. 2288 | 2289 | Returns: 2290 | dict: A dictionary containing the result of the operation. 2291 | """ 2292 | # Define the payload for the RPC call 2293 | payload = { 2294 | "names": names, 2295 | "start_height": start_height, 2296 | "end_height": end_height, 2297 | "include_spent_coins": include_spent_coins, 2298 | } 2299 | 2300 | # Use the submit method of WalletRpcClient instance to make the Chia 2301 | # RPC call with the payload 2302 | result = self.__chia_rpc__.submit( 2303 | "get_coin_records_by_names", json.dumps(payload) 2304 | ) 2305 | 2306 | # Parse the JSON response and return the result 2307 | return json.loads(result) 2308 | --------------------------------------------------------------------------------