diff --git a/chia/cmds/cmd_classes.py b/chia/cmds/cmd_classes.py index 0945fe3d781d..4e1d4076eea4 100644 --- a/chia/cmds/cmd_classes.py +++ b/chia/cmds/cmd_classes.py @@ -299,9 +299,8 @@ async def wallet_rpc(self, **kwargs: Any) -> AsyncIterator[WalletClientInfo]: if self.client_info is not None: yield self.client_info else: - if "root_path" not in kwargs: - kwargs["root_path"] = self.context["root_path"] - async with get_wallet_client(self.wallet_rpc_port, self.fingerprint, **kwargs) as ( + root_path = kwargs.get("root_path", self.context["root_path"]) + async with get_wallet_client(root_path, self.wallet_rpc_port, self.fingerprint, **kwargs) as ( wallet_client, fp, config, diff --git a/chia/cmds/cmds_util.py b/chia/cmds/cmds_util.py index e260d3460e85..e61d342eaf56 100644 --- a/chia/cmds/cmds_util.py +++ b/chia/cmds/cmds_util.py @@ -248,9 +248,9 @@ async def get_wallet(root_path: Path, wallet_client: WalletRpcClient, fingerprin @asynccontextmanager async def get_wallet_client( + root_path: Path, wallet_rpc_port: Optional[int] = None, fingerprint: Optional[int] = None, - root_path: Path = DEFAULT_ROOT_PATH, consume_errors: bool = True, ) -> AsyncIterator[tuple[WalletRpcClient, int, dict[str, Any]]]: async with get_any_service_client(WalletRpcClient, wallet_rpc_port, root_path, consume_errors) as ( diff --git a/chia/cmds/coin_funcs.py b/chia/cmds/coin_funcs.py index 7a03d6973d8d..1cc298719bcc 100644 --- a/chia/cmds/coin_funcs.py +++ b/chia/cmds/coin_funcs.py @@ -3,6 +3,7 @@ import dataclasses import sys from collections.abc import Sequence +from pathlib import Path from typing import Optional from chia.cmds.cmds_util import CMDCoinSelectionConfigLoader, CMDTXConfigLoader, cli_confirm, get_wallet_client @@ -21,6 +22,7 @@ async def async_list( *, + root_path: Path, wallet_rpc_port: Optional[int], fingerprint: Optional[int], wallet_id: int, @@ -31,7 +33,7 @@ async def async_list( show_unconfirmed: bool, paginate: Optional[bool], ) -> None: - async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, _, config): + async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, _, config): addr_prefix = selected_network_address_prefix(config) if paginate is None: paginate = sys.stdout.isatty() @@ -114,6 +116,7 @@ def print_coins( async def async_combine( *, + root_path: Path, wallet_rpc_port: Optional[int], fingerprint: Optional[int], wallet_id: int, @@ -131,7 +134,7 @@ async def async_combine( condition_valid_times: ConditionValidTimes, override: bool, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): try: wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client) mojo_per_unit = get_mojo_per_unit(wallet_type) @@ -194,6 +197,7 @@ async def async_combine( async def async_split( *, + root_path: Path, wallet_rpc_port: Optional[int], fingerprint: Optional[int], wallet_id: int, @@ -209,7 +213,7 @@ async def async_split( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): try: wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client) mojo_per_unit = get_mojo_per_unit(wallet_type) diff --git a/chia/cmds/coins.py b/chia/cmds/coins.py index 0adf9835481e..b1fc69e23648 100644 --- a/chia/cmds/coins.py +++ b/chia/cmds/coins.py @@ -55,6 +55,7 @@ def list_cmd( asyncio.run( async_list( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fingerprint=fingerprint, wallet_id=id, @@ -111,7 +112,9 @@ def list_cmd( ) @click.option("--override", help="Submits transaction without checking for unusual values", is_flag=True, default=False) @tx_out_cmd() +@click.pass_context def combine_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -133,6 +136,7 @@ def combine_cmd( return asyncio.run( async_combine( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fingerprint=fingerprint, wallet_id=id, @@ -183,7 +187,9 @@ def combine_cmd( ) @tx_config_args @tx_out_cmd() +@click.pass_context def split_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -203,6 +209,7 @@ def split_cmd( return asyncio.run( async_split( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fingerprint=fingerprint, wallet_id=id, diff --git a/chia/cmds/dao.py b/chia/cmds/dao.py index b59cc65ea2a4..d592380a1965 100644 --- a/chia/cmds/dao.py +++ b/chia/cmds/dao.py @@ -51,7 +51,9 @@ def dao_cmd(ctx: click.Context) -> None: default=uint64(1), show_default=True, ) +@click.pass_context def dao_add_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, treasury_id: bytes32, @@ -60,7 +62,7 @@ def dao_add_cmd( ) -> None: from chia.cmds.dao_funcs import add_dao_wallet - asyncio.run(add_dao_wallet(wallet_rpc_port, fingerprint, name, treasury_id, filter_amount)) + asyncio.run(add_dao_wallet(ctx.obj["root_path"], wallet_rpc_port, fingerprint, name, treasury_id, filter_amount)) # ---------------------------------------------------------------------------------------- @@ -148,7 +150,9 @@ def dao_add_cmd( ) @tx_config_args @tx_out_cmd() +@click.pass_context def dao_create_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, proposal_timelock: uint64, @@ -180,6 +184,7 @@ def dao_create_cmd( return asyncio.run( create_dao_wallet( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, fee, @@ -221,14 +226,16 @@ def dao_create_cmd( ) @click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int) @click.option("-i", "--wallet-id", help="DAO Wallet ID", type=int, required=True) +@click.pass_context def dao_get_id_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, ) -> None: from chia.cmds.dao_funcs import get_treasury_id - asyncio.run(get_treasury_id(wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_treasury_id(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) @dao_cmd.command("add_funds", short_help="Send funds to a DAO treasury", no_args_is_help=True) @@ -258,7 +265,9 @@ def dao_get_id_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_add_funds_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -277,6 +286,7 @@ def dao_add_funds_cmd( return asyncio.run( add_funds_to_treasury( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -306,14 +316,16 @@ def dao_add_funds_cmd( ) @click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int) @click.option("-i", "--wallet-id", help="Id of the wallet to use", type=int, required=True) +@click.pass_context def dao_get_balance_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, ) -> None: from chia.cmds.dao_funcs import get_treasury_balance - asyncio.run(get_treasury_balance(wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_treasury_balance(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) @dao_cmd.command("rules", short_help="Get the current rules governing the DAO", no_args_is_help=True) @@ -326,14 +338,16 @@ def dao_get_balance_cmd( ) @click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int) @click.option("-i", "--wallet-id", help="Id of the wallet to use", type=int, required=True) +@click.pass_context def dao_rules_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, ) -> None: from chia.cmds.dao_funcs import get_rules - asyncio.run(get_rules(wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_rules(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) # ---------------------------------------------------------------------------------------- @@ -356,7 +370,9 @@ def dao_rules_cmd( help="Include previously closed proposals", is_flag=True, ) +@click.pass_context def dao_list_proposals_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -367,7 +383,7 @@ def dao_list_proposals_cmd( if not include_closed: include_closed = False - asyncio.run(list_proposals(wallet_rpc_port, fingerprint, wallet_id, include_closed)) + asyncio.run(list_proposals(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, include_closed)) @dao_cmd.command("show_proposal", short_help="Show the details of a specific proposal", no_args_is_help=True) @@ -387,7 +403,9 @@ def dao_list_proposals_cmd( type=str, required=True, ) +@click.pass_context def dao_show_proposal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -395,7 +413,7 @@ def dao_show_proposal_cmd( ) -> None: from chia.cmds.dao_funcs import show_proposal - asyncio.run(show_proposal(wallet_rpc_port, fingerprint, wallet_id, proposal_id)) + asyncio.run(show_proposal(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, proposal_id)) # ---------------------------------------------------------------------------------------- @@ -435,7 +453,9 @@ def dao_show_proposal_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_vote_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -457,6 +477,7 @@ def dao_vote_cmd( return asyncio.run( vote_on_proposal( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -508,7 +529,9 @@ def dao_vote_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_close_proposal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -527,6 +550,7 @@ def dao_close_proposal_cmd( return asyncio.run( close_proposal( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -570,7 +594,9 @@ def dao_close_proposal_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_lockup_coins_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -588,6 +614,7 @@ def dao_lockup_coins_cmd( return asyncio.run( lockup_coins( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -619,7 +646,9 @@ def dao_lockup_coins_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_release_coins_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -636,6 +665,7 @@ def dao_release_coins_cmd( return asyncio.run( release_coins( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -666,7 +696,9 @@ def dao_release_coins_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_exit_lockup_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -683,6 +715,7 @@ def dao_exit_lockup_cmd( return asyncio.run( exit_lockup( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -762,7 +795,9 @@ def dao_proposal(ctx: click.Context) -> None: @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_create_spend_proposal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -784,6 +819,7 @@ def dao_create_spend_proposal_cmd( return asyncio.run( create_spend_proposal( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -869,7 +905,9 @@ def dao_create_spend_proposal_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_create_update_proposal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -893,6 +931,7 @@ def dao_create_update_proposal_cmd( return asyncio.run( create_update_proposal( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, @@ -953,7 +992,9 @@ def dao_create_update_proposal_cmd( @options.create_fee() @tx_config_args @tx_out_cmd() +@click.pass_context def dao_create_mint_proposal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int, @@ -973,6 +1014,7 @@ def dao_create_mint_proposal_cmd( return asyncio.run( create_mint_proposal( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, diff --git a/chia/cmds/dao_funcs.py b/chia/cmds/dao_funcs.py index 3712965c3aab..18015543979d 100644 --- a/chia/cmds/dao_funcs.py +++ b/chia/cmds/dao_funcs.py @@ -2,6 +2,7 @@ import asyncio import json +import pathlib import time from decimal import Decimal from typing import Optional @@ -21,12 +22,17 @@ async def add_dao_wallet( - wallet_rpc_port: Optional[int], fp: int, name: Optional[str], treasury_id: bytes32, filter_amount: uint64 + root_path: pathlib.Path, + wallet_rpc_port: Optional[int], + fp: int, + name: Optional[str], + treasury_id: bytes32, + filter_amount: uint64, ) -> None: print(f"Adding wallet for DAO: {treasury_id}") print("This may take awhile.") - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.create_new_dao_wallet( mode="existing", tx_config=CMDTXConfigLoader(reuse_puzhash=True).to_tx_config(units["chia"], config, fingerprint), @@ -45,6 +51,7 @@ async def add_dao_wallet( async def create_dao_wallet( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, fee: uint64, @@ -77,7 +84,7 @@ async def create_dao_wallet( "proposal_minimum_amount": proposal_minimum, } - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): conf_coins, _, _ = await wallet_client.get_spendable_coins( wallet_id=1, coin_selection_config=DEFAULT_COIN_SELECTION_CONFIG ) @@ -106,15 +113,15 @@ async def create_dao_wallet( return res.transactions -async def get_treasury_id(wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_treasury_id(root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.dao_get_treasury_id(wallet_id=wallet_id) treasury_id = res["treasury_id"] print(f"Treasury ID: {treasury_id}") -async def get_rules(wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_rules(root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.dao_get_rules(wallet_id=wallet_id) rules = res["rules"] for rule, val in rules.items(): @@ -122,6 +129,7 @@ async def get_rules(wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> async def add_funds_to_treasury( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -132,7 +140,7 @@ async def add_funds_to_treasury( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: typ = await get_wallet_type(wallet_id=funding_wallet_id, wallet_client=wallet_client) mojo_per_unit = get_mojo_per_unit(typ) @@ -165,8 +173,10 @@ async def add_funds_to_treasury( return res.transactions -async def get_treasury_balance(wallet_rpc_port: Optional[int], fp: int, wallet_id: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_treasury_balance( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.dao_get_treasury_balance(wallet_id=wallet_id) balances = res["balances"] @@ -183,8 +193,10 @@ async def get_treasury_balance(wallet_rpc_port: Optional[int], fp: int, wallet_i print(f"{asset_id}: {balance / cat_mojos}") -async def list_proposals(wallet_rpc_port: Optional[int], fp: int, wallet_id: int, include_closed: bool) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def list_proposals( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, include_closed: bool +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.dao_get_proposals(wallet_id=wallet_id, include_closed=include_closed) proposals = res["proposals"] soft_close_length = res["soft_close_length"] @@ -201,8 +213,10 @@ async def list_proposals(wallet_rpc_port: Optional[int], fp: int, wallet_id: int print("############################") -async def show_proposal(wallet_rpc_port: Optional[int], fp: int, wallet_id: int, proposal_id: str) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, config): +async def show_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, proposal_id: str +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, config): res = await wallet_client.dao_parse_proposal(wallet_id, proposal_id) pd = res["proposal_dictionary"] blocks_needed = pd["state"]["blocks_needed"] @@ -275,6 +289,7 @@ async def show_proposal(wallet_rpc_port: Optional[int], fp: int, wallet_id: int, async def vote_on_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -286,7 +301,7 @@ async def vote_on_proposal( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_vote_on_proposal( wallet_id=wallet_id, proposal_id=proposal_id, @@ -313,6 +328,7 @@ async def vote_on_proposal( async def close_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -323,7 +339,7 @@ async def close_proposal( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_close_proposal( wallet_id=wallet_id, proposal_id=proposal_id, @@ -350,6 +366,7 @@ async def close_proposal( async def lockup_coins( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -360,7 +377,7 @@ async def lockup_coins( condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: final_amount: uint64 = amount.convert_amount(units["cat"]) - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_send_to_lockup( wallet_id=wallet_id, amount=final_amount, @@ -386,6 +403,7 @@ async def lockup_coins( async def release_coins( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -394,7 +412,7 @@ async def release_coins( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_free_coins_from_finished_proposals( wallet_id=wallet_id, fee=fee, @@ -418,6 +436,7 @@ async def release_coins( async def exit_lockup( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -426,7 +445,7 @@ async def exit_lockup( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_exit_lockup( wallet_id=wallet_id, coins=[], @@ -452,6 +471,7 @@ async def exit_lockup( async def create_spend_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -477,7 +497,7 @@ async def create_spend_proposal( additions.append(addition) else: additions = None - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client) mojo_per_unit = get_mojo_per_unit(wallet_type=wallet_type) final_amount: Optional[uint64] = uint64(int(Decimal(amount) * mojo_per_unit)) if amount else None @@ -504,6 +524,7 @@ async def create_spend_proposal( async def create_update_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -527,7 +548,7 @@ async def create_update_proposal( "self_destruct_length": self_destruct_length, "oracle_spend_delay": oracle_spend_delay, } - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_create_proposal( wallet_id=wallet_id, proposal_type="update", @@ -546,6 +567,7 @@ async def create_update_proposal( async def create_mint_proposal( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: int, wallet_id: int, @@ -557,7 +579,7 @@ async def create_mint_proposal( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.dao_create_proposal( wallet_id=wallet_id, proposal_type="mint", diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index aef8f2a80029..3a26ed1abb2c 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -47,10 +47,21 @@ def wallet_cmd(ctx: click.Context) -> None: @click.option("-i", "--id", help="Id of the wallet to use", type=int, default=1, show_default=True, required=True) @click.option("-tx", "--tx_id", help="transaction id to search for", type=str, required=True) @click.option("--verbose", "-v", count=True, type=int) -def get_transaction_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, tx_id: str, verbose: int) -> None: +@click.pass_context +def get_transaction_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, tx_id: str, verbose: int +) -> None: from chia.cmds.wallet_funcs import get_transaction - asyncio.run(get_transaction(wallet_rpc_port=wallet_rpc_port, fingerprint=fingerprint, tx_id=tx_id, verbose=verbose)) + asyncio.run( + get_transaction( + root_path=ctx.obj["root_path"], + wallet_rpc_port=wallet_rpc_port, + fingerprint=fingerprint, + tx_id=tx_id, + verbose=verbose, + ) + ) @wallet_cmd.command("get_transactions", help="Get all transactions") @@ -114,7 +125,9 @@ def get_transaction_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: in default=False, help="Only show clawback transactions", ) +@click.pass_context def get_transactions_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -130,6 +143,7 @@ def get_transactions_cmd( asyncio.run( get_transactions( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -201,7 +215,9 @@ def get_transactions_cmd( default=0, ) @tx_out_cmd() +@click.pass_context def send_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -222,6 +238,7 @@ def send_cmd( return asyncio.run( send( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -257,10 +274,15 @@ def send_cmd( type=click.Choice([x.name.lower() for x in WalletType]), default=None, ) -def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Optional[str]) -> None: +@click.pass_context +def show_cmd(ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Optional[str]) -> None: from chia.cmds.wallet_funcs import print_balances - asyncio.run(print_balances(wallet_rpc_port, fingerprint, WalletType[wallet_type.upper()] if wallet_type else None)) + asyncio.run( + print_balances( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, WalletType[wallet_type.upper()] if wallet_type else None + ) + ) @wallet_cmd.command("get_address", help="Get a wallet receive address") @@ -283,10 +305,13 @@ def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Opti is_flag=True, default=False, ) -def get_address_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int, new_address: bool) -> None: +@click.pass_context +def get_address_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], id: int, fingerprint: int, new_address: bool +) -> None: from chia.cmds.wallet_funcs import get_address - asyncio.run(get_address(wallet_rpc_port, fingerprint, id, new_address)) + asyncio.run(get_address(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, new_address)) @wallet_cmd.command( @@ -320,7 +345,9 @@ def get_address_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int, n default=False, ) @tx_out_cmd() +@click.pass_context def clawback( + ctx: click.Context, wallet_rpc_port: Optional[int], id: int, fingerprint: int, @@ -334,6 +361,7 @@ def clawback( return asyncio.run( spend_clawback( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=fee, @@ -355,10 +383,13 @@ def clawback( ) @click.option("-i", "--id", help="Id of the wallet to use", type=int, default=1, show_default=True, required=True) @options.create_fingerprint() -def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int) -> None: +@click.pass_context +def delete_unconfirmed_transactions_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], id: int, fingerprint: int +) -> None: from chia.cmds.wallet_funcs import delete_unconfirmed_transactions - asyncio.run(delete_unconfirmed_transactions(wallet_rpc_port, fingerprint, id)) + asyncio.run(delete_unconfirmed_transactions(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id)) @wallet_cmd.command("get_derivation_index", help="Get the last puzzle hash derivation path index") @@ -370,10 +401,11 @@ def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id: int, default=None, ) @options.create_fingerprint() -def get_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int) -> None: +@click.pass_context +def get_derivation_index_cmd(ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int) -> None: from chia.cmds.wallet_funcs import get_derivation_index - asyncio.run(get_derivation_index(wallet_rpc_port, fingerprint)) + asyncio.run(get_derivation_index(ctx.obj["root_path"], wallet_rpc_port, fingerprint)) @wallet_cmd.command("sign_message", help="Sign a message by a derivation address") @@ -388,13 +420,15 @@ def get_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int) - # TODO: Change RPC's to use the puzzle hash instead of address @click.option("-a", "--address", help="The address you want to use for signing", type=AddressParamType(), required=True) @click.option("-m", "--hex_message", help="The hex message you want sign", type=str, required=True) +@click.pass_context def address_sign_message( - wallet_rpc_port: Optional[int], fingerprint: int, address: CliAddress, hex_message: str + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, address: CliAddress, hex_message: str ) -> None: from chia.cmds.wallet_funcs import sign_message asyncio.run( sign_message( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.XCH, @@ -418,10 +452,13 @@ def address_sign_message( @click.option( "-i", "--index", help="Index to set. Must be greater than the current derivation index", type=int, required=True ) -def update_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int, index: int) -> None: +@click.pass_context +def update_derivation_index_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, index: int +) -> None: from chia.cmds.wallet_funcs import update_derivation_index - asyncio.run(update_derivation_index(wallet_rpc_port, fingerprint, index)) + asyncio.run(update_derivation_index(ctx.obj["root_path"], wallet_rpc_port, fingerprint, index)) @wallet_cmd.command("add_token", help="Add/Rename a CAT to the wallet by its asset ID") @@ -445,10 +482,13 @@ def update_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int help="The name you wish to designate to the token", ) @options.create_fingerprint() -def add_token_cmd(wallet_rpc_port: Optional[int], asset_id: bytes32, token_name: str, fingerprint: int) -> None: +@click.pass_context +def add_token_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], asset_id: bytes32, token_name: str, fingerprint: int +) -> None: from chia.cmds.wallet_funcs import add_token - asyncio.run(add_token(wallet_rpc_port, fingerprint, asset_id, token_name)) + asyncio.run(add_token(ctx.obj["root_path"], wallet_rpc_port, fingerprint, asset_id, token_name)) @wallet_cmd.command("make_offer", help="Create an offer of XCH/CATs/NFTs for XCH/CATs/NFTs") @@ -489,9 +529,11 @@ def add_token_cmd(wallet_rpc_port: Optional[int], asset_id: bytes32, token_name: ) @click.option("--override", help="Creates offer without checking for unusual values", is_flag=True, default=False) @timelock_args(enable=True) +@click.pass_context # This command looks like a good candidate for @tx_out_cmd however, pushing an incomplete tx is nonsensical and # we already have a canonical offer file format which the idea of exporting a different transaction conflicts with def make_offer_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, offer: Sequence[str], @@ -510,6 +552,7 @@ def make_offer_cmd( asyncio.run( make_offer( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=fee, @@ -543,7 +586,9 @@ def make_offer_cmd( @click.option("-s", "--summaries", help="Show the assets being offered and requested for each offer", is_flag=True) @click.option("--sort-by-relevance/--sort-by-confirmed-height", help="Sort the offers one of two ways", is_flag=True) @click.option("-r", "--reverse", help="Reverse the order of the output", is_flag=True) +@click.pass_context def get_offers_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: Optional[bytes32], @@ -559,6 +604,7 @@ def get_offers_cmd( asyncio.run( get_offers( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, offer_id=id, @@ -593,7 +639,9 @@ def get_offers_cmd( default=False, ) @tx_out_cmd() +@click.pass_context def take_offer_cmd( + ctx: click.Context, path_or_hex: str, wallet_rpc_port: Optional[int], fingerprint: int, @@ -607,6 +655,7 @@ def take_offer_cmd( return asyncio.run( take_offer( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, fee, @@ -631,7 +680,9 @@ def take_offer_cmd( @click.option("--insecure", help="Don't make an on-chain transaction, simply mark the offer as cancelled", is_flag=True) @options.create_fee("The fee to use when cancelling the offer securely, in XCH") @tx_out_cmd() +@click.pass_context def cancel_offer_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: bytes32, @@ -644,6 +695,7 @@ def cancel_offer_cmd( return asyncio.run( cancel_offer( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, fee, @@ -694,7 +746,9 @@ def did_cmd() -> None: ) @options.create_fee() @tx_out_cmd() +@click.pass_context def did_create_wallet_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, name: Optional[str], @@ -707,6 +761,7 @@ def did_create_wallet_cmd( return asyncio.run( create_did_wallet( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, fee, @@ -729,11 +784,15 @@ def did_create_wallet_cmd( @options.create_fingerprint() @click.option("-i", "--did_id", help="DID ID you want to use for signing", type=AddressParamType(), required=True) @click.option("-m", "--hex_message", help="The hex message you want to sign", type=str, required=True) -def did_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, did_id: CliAddress, hex_message: str) -> None: +@click.pass_context +def did_sign_message( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, did_id: CliAddress, hex_message: str +) -> None: from chia.cmds.wallet_funcs import sign_message asyncio.run( sign_message( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.DID, @@ -754,10 +813,13 @@ def did_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, did_id: C @options.create_fingerprint() @click.option("-i", "--id", help="Id of the wallet to use", type=int, required=True) @click.option("-n", "--name", help="Set the DID wallet name", type=str, required=True) -def did_wallet_name_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, name: str) -> None: +@click.pass_context +def did_wallet_name_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, name: str +) -> None: from chia.cmds.wallet_funcs import did_set_wallet_name - asyncio.run(did_set_wallet_name(wallet_rpc_port, fingerprint, id, name)) + asyncio.run(did_set_wallet_name(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, name)) @did_cmd.command("get_did", help="Get DID from wallet") @@ -770,10 +832,11 @@ def did_wallet_name_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: in ) @options.create_fingerprint() @click.option("-i", "--id", help="Id of the wallet to use", type=int, required=True) -def did_get_did_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None: +@click.pass_context +def did_get_did_cmd(ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None: from chia.cmds.wallet_funcs import get_did - asyncio.run(get_did(wallet_rpc_port, fingerprint, id)) + asyncio.run(get_did(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id)) @did_cmd.command("get_details", help="Get more details of any DID") @@ -787,10 +850,13 @@ def did_get_did_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) - @options.create_fingerprint() @click.option("-id", "--coin_id", help="Id of the DID or any coin ID of the DID", type=str, required=True) @click.option("-l", "--latest", help="Return latest DID information", is_flag=True, default=True) -def did_get_details_cmd(wallet_rpc_port: Optional[int], fingerprint: int, coin_id: str, latest: bool) -> None: +@click.pass_context +def did_get_details_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, coin_id: str, latest: bool +) -> None: from chia.cmds.wallet_funcs import get_did_info - asyncio.run(get_did_info(wallet_rpc_port, fingerprint, coin_id, latest)) + asyncio.run(get_did_info(ctx.obj["root_path"], wallet_rpc_port, fingerprint, coin_id, latest)) @did_cmd.command("update_metadata", help="Update the metadata of a DID") @@ -811,7 +877,9 @@ def did_get_details_cmd(wallet_rpc_port: Optional[int], fingerprint: int, coin_i default=False, ) @tx_out_cmd() +@click.pass_context def did_update_metadata_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -824,6 +892,7 @@ def did_update_metadata_cmd( return asyncio.run( update_did_metadata( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, @@ -861,7 +930,9 @@ def did_update_metadata_cmd( type=int, required=False, ) +@click.pass_context def did_find_lost_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, coin_id: str, @@ -873,6 +944,7 @@ def did_find_lost_cmd( asyncio.run( find_lost_did( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, coin_id=coin_id, @@ -908,7 +980,9 @@ def did_find_lost_cmd( required=False, ) @tx_out_cmd() +@click.pass_context def did_message_spend_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -942,6 +1016,7 @@ def did_message_spend_cmd( return asyncio.run( did_message_spend( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, @@ -976,7 +1051,9 @@ def did_message_spend_cmd( default=False, ) @tx_out_cmd() +@click.pass_context def did_transfer_did( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -991,6 +1068,7 @@ def did_transfer_did( return asyncio.run( transfer_did( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, @@ -1021,12 +1099,17 @@ def nft_cmd() -> None: # TODO: Change RPC to use puzzlehash instead of address @click.option("-di", "--did-id", help="DID Id to use", type=AddressParamType()) @click.option("-n", "--name", help="Set the NFT wallet name", type=str) +@click.pass_context def nft_wallet_create_cmd( - wallet_rpc_port: Optional[int], fingerprint: int, did_id: Optional[CliAddress], name: Optional[str] + ctx: click.Context, + wallet_rpc_port: Optional[int], + fingerprint: int, + did_id: Optional[CliAddress], + name: Optional[str], ) -> None: from chia.cmds.wallet_funcs import create_nft_wallet - asyncio.run(create_nft_wallet(wallet_rpc_port, fingerprint, did_id, name)) + asyncio.run(create_nft_wallet(ctx.obj["root_path"], wallet_rpc_port, fingerprint, did_id, name)) @nft_cmd.command("sign_message", help="Sign a message by a NFT") @@ -1040,11 +1123,15 @@ def nft_wallet_create_cmd( @options.create_fingerprint() @click.option("-i", "--nft_id", help="NFT ID you want to use for signing", type=AddressParamType(), required=True) @click.option("-m", "--hex_message", help="The hex message you want to sign", type=str, required=True) -def nft_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, nft_id: CliAddress, hex_message: str) -> None: +@click.pass_context +def nft_sign_message( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, nft_id: CliAddress, hex_message: str +) -> None: from chia.cmds.wallet_funcs import sign_message asyncio.run( sign_message( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.NFT, @@ -1091,7 +1178,9 @@ def nft_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, nft_id: C default=False, ) @tx_out_cmd() +@click.pass_context def nft_mint_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -1126,6 +1215,7 @@ def nft_mint_cmd( return asyncio.run( mint_nft( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1172,7 +1262,9 @@ def nft_mint_cmd( default=False, ) @tx_out_cmd() +@click.pass_context def nft_add_uri_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -1189,6 +1281,7 @@ def nft_add_uri_cmd( return asyncio.run( add_uri_to_nft( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1225,7 +1318,9 @@ def nft_add_uri_cmd( default=False, ) @tx_out_cmd() +@click.pass_context def nft_transfer_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -1240,6 +1335,7 @@ def nft_transfer_cmd( return asyncio.run( transfer_nft( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1265,10 +1361,13 @@ def nft_transfer_cmd( @click.option("-i", "--id", help="Id of the NFT wallet to use", type=int, required=True) @click.option("--num", help="Number of NFTs to return", type=int, default=50) @click.option("--start-index", help="Which starting index to start listing NFTs from", type=int, default=0) -def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, num: int, start_index: int) -> None: +@click.pass_context +def nft_list_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, num: int, start_index: int +) -> None: from chia.cmds.wallet_funcs import list_nfts - asyncio.run(list_nfts(wallet_rpc_port, fingerprint, id, num, start_index)) + asyncio.run(list_nfts(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, num, start_index)) @nft_cmd.command("set_did", help="Set a DID on an NFT") @@ -1292,7 +1391,9 @@ def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, num: default=False, ) @tx_out_cmd() +@click.pass_context def nft_set_did_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -1307,6 +1408,7 @@ def nft_set_did_cmd( return asyncio.run( set_nft_did( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1331,14 +1433,16 @@ def nft_set_did_cmd( @options.create_fingerprint() # TODO: Change RPC to use bytes instead of hex string @click.option("-ni", "--nft-coin-id", help="Id of the NFT coin to get information on", type=str, required=True) +@click.pass_context def nft_get_info_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, nft_coin_id: str, ) -> None: from chia.cmds.wallet_funcs import get_nft_info - asyncio.run(get_nft_info(wallet_rpc_port, fingerprint, nft_coin_id)) + asyncio.run(get_nft_info(ctx.obj["root_path"], wallet_rpc_port, fingerprint, nft_coin_id)) # Keep at bottom. @@ -1374,7 +1478,9 @@ def notification_cmd() -> None: @click.option("-n", "--message", help="The message of the notification", type=str) @options.create_fee() @tx_out_cmd() +@click.pass_context def send_notification_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, to_address: CliAddress, @@ -1389,6 +1495,7 @@ def send_notification_cmd( message_bytes: bytes = bytes(message, "utf8") return asyncio.run( send_notification( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, fee, @@ -1413,7 +1520,9 @@ def send_notification_cmd( @click.option("-i", "--id", help="The specific notification ID to show", type=Bytes32ParamType(), multiple=True) @click.option("-s", "--start", help="The number of notifications to skip", type=int, default=None) @click.option("-e", "--end", help="The number of notifications to stop at", type=int, default=None) +@click.pass_context def get_notifications_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: Sequence[bytes32], @@ -1422,7 +1531,7 @@ def get_notifications_cmd( ) -> None: from chia.cmds.wallet_funcs import get_notifications - asyncio.run(get_notifications(wallet_rpc_port, fingerprint, id, start, end)) + asyncio.run(get_notifications(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, start, end)) @notification_cmd.command("delete", help="Delete notification(s) that are in your wallet") @@ -1436,7 +1545,9 @@ def get_notifications_cmd( @options.create_fingerprint() @click.option("-i", "--id", help="A specific notification ID to delete", type=Bytes32ParamType(), multiple=True) @click.option("--all", help="All notifications can be deleted (they will be recovered during resync)", is_flag=True) +@click.pass_context def delete_notifications_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: Sequence[bytes32], @@ -1444,7 +1555,7 @@ def delete_notifications_cmd( ) -> None: from chia.cmds.wallet_funcs import delete_notifications - asyncio.run(delete_notifications(wallet_rpc_port, fingerprint, id, all)) + asyncio.run(delete_notifications(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, all)) @wallet_cmd.group("vcs", short_help="Verifiable Credential related actions") @@ -1471,7 +1582,9 @@ def vcs_cmd() -> None: # pragma: no cover ) @options.create_fee("Blockchain fee for mint transaction, in XCH") @tx_out_cmd() +@click.pass_context def mint_vc_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, did: CliAddress, @@ -1484,6 +1597,7 @@ def mint_vc_cmd( return asyncio.run( mint_vc( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, did, @@ -1510,7 +1624,9 @@ def mint_vc_cmd( @click.option( "-c", "--count", help="How many results to return", type=int, required=False, default=50, show_default=True ) +@click.pass_context def get_vcs_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, start: int, @@ -1518,7 +1634,7 @@ def get_vcs_cmd( ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import get_vcs - asyncio.run(get_vcs(wallet_rpc_port, fingerprint, start, count)) + asyncio.run(get_vcs(ctx.obj["root_path"], wallet_rpc_port, fingerprint, start, count)) @vcs_cmd.command("update_proofs", short_help="Update a VC's proofs if you have the provider DID") @@ -1553,7 +1669,9 @@ def get_vcs_cmd( show_default=True, ) @tx_out_cmd() +@click.pass_context def spend_vc_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, vc_id: bytes32, @@ -1568,6 +1686,7 @@ def spend_vc_cmd( return asyncio.run( spend_vc( + root_path=ctx.obj["root_path"], wallet_rpc_port=wallet_rpc_port, fp=fingerprint, vc_id=vc_id, @@ -1592,7 +1711,9 @@ def spend_vc_cmd( @options.create_fingerprint() @click.option("-p", "--proof", help="A flag to add as a proof", type=str, multiple=True) @click.option("-r", "--root-only", help="Do not add the proofs to the DB, just output the root", is_flag=True) +@click.pass_context def add_proof_reveal_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, proof: Sequence[str], @@ -1600,7 +1721,7 @@ def add_proof_reveal_cmd( ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import add_proof_reveal - asyncio.run(add_proof_reveal(wallet_rpc_port, fingerprint, proof, root_only)) + asyncio.run(add_proof_reveal(ctx.obj["root_path"], wallet_rpc_port, fingerprint, proof, root_only)) @vcs_cmd.command("get_proofs_for_root", short_help="Get the stored proof flags for a given proof hash") @@ -1613,14 +1734,16 @@ def add_proof_reveal_cmd( ) @options.create_fingerprint() @click.option("-r", "--proof-hash", help="The root to search for", type=str, required=True) +@click.pass_context def get_proofs_for_root_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, proof_hash: str, ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import get_proofs_for_root - asyncio.run(get_proofs_for_root(wallet_rpc_port, fingerprint, proof_hash)) + asyncio.run(get_proofs_for_root(ctx.obj["root_path"], wallet_rpc_port, fingerprint, proof_hash)) @vcs_cmd.command("revoke", short_help="Revoke any VC if you have the proper DID and the VCs parent coin") @@ -1654,7 +1777,9 @@ def get_proofs_for_root_cmd( show_default=True, ) @tx_out_cmd() +@click.pass_context def revoke_vc_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, parent_coin_id: Optional[bytes32], @@ -1668,6 +1793,7 @@ def revoke_vc_cmd( return asyncio.run( revoke_vc( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, parent_coin_id, @@ -1719,7 +1845,9 @@ def revoke_vc_cmd( default=False, ) @tx_out_cmd() +@click.pass_context def approve_r_cats_cmd( + ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: int, id: int, @@ -1735,6 +1863,7 @@ def approve_r_cats_cmd( return asyncio.run( approve_r_cats( + ctx.obj["root_path"], wallet_rpc_port, fingerprint, uint32(id), diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index 31167b255959..cfb7c82e887f 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -146,9 +146,9 @@ async def get_unit_name_for_wallet_id( async def get_transaction( - *, wallet_rpc_port: Optional[int], fingerprint: Optional[int], tx_id: str, verbose: int + *, root_path: pathlib.Path, wallet_rpc_port: Optional[int], fingerprint: Optional[int], tx_id: str, verbose: int ) -> None: - async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): transaction_id = bytes32.from_hexstr(tx_id) address_prefix = selected_network_address_prefix(config) tx: TransactionRecord = await wallet_client.get_transaction(transaction_id=transaction_id) @@ -177,6 +177,7 @@ async def get_transaction( async def get_transactions( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -188,7 +189,7 @@ async def get_transactions( reverse: bool, clawback: bool, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, config): if paginate is None: paginate = sys.stdout.isatty() type_filter = ( @@ -261,6 +262,7 @@ def check_unusual_transaction(amount: uint64, fee: uint64) -> bool: async def send( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -277,7 +279,7 @@ async def send( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): if memo is None: memos = None else: @@ -366,34 +368,42 @@ async def send( return res.transactions # pragma: no cover -async def get_address(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, new_address: bool) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_address( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, new_address: bool +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.get_next_address(wallet_id, new_address) print(res) -async def delete_unconfirmed_transactions(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, _): +async def delete_unconfirmed_transactions( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _): await wallet_client.delete_unconfirmed_transactions(wallet_id) print(f"Successfully deleted all unconfirmed transactions for wallet id {wallet_id} on key {fingerprint}") -async def get_derivation_index(wallet_rpc_port: Optional[int], fp: Optional[int]) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_derivation_index(root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int]) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): res = await wallet_client.get_current_derivation_index() print(f"Last derivation index: {res}") -async def update_derivation_index(wallet_rpc_port: Optional[int], fp: Optional[int], index: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def update_derivation_index( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], index: int +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): print("Updating derivation index... This may take a while.") res = await wallet_client.extend_derivation_index(index) print(f"Updated derivation index: {res}") print("Your balances may take a while to update.") -async def add_token(wallet_rpc_port: Optional[int], fp: Optional[int], asset_id: bytes32, token_name: str) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, _): +async def add_token( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], asset_id: bytes32, token_name: str +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _): existing_info: Optional[tuple[Optional[uint32], str]] = await wallet_client.cat_asset_id_to_name(asset_id) if existing_info is None or existing_info[0] is None: response = await wallet_client.create_wallet_for_existing_cat(asset_id) @@ -408,6 +418,7 @@ async def add_token(wallet_rpc_port: Optional[int], fp: Optional[int], asset_id: async def make_offer( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -417,7 +428,7 @@ async def make_offer( reuse_puzhash: Optional[bool], condition_valid_times: ConditionValidTimes, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): if offers == [] or requests == []: print("Not creating offer: Must be offering and requesting at least one asset") else: @@ -650,6 +661,7 @@ async def print_trade_record(record: TradeRecord, wallet_client: WalletRpcClient async def get_offers( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], offer_id: Optional[bytes32], @@ -661,7 +673,7 @@ async def get_offers( reverse: bool = False, sort_by_relevance: bool = True, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): file_contents: bool = (filepath is not None) or summaries records: list[TradeRecord] = [] if offer_id is None: @@ -701,6 +713,7 @@ async def get_offers( async def take_offer( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -709,7 +722,7 @@ async def take_offer( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): if os.path.exists(file): filepath = pathlib.Path(file) with open(filepath) as ffile: @@ -806,6 +819,7 @@ async def take_offer( async def cancel_offer( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -814,7 +828,7 @@ async def cancel_offer( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): trade_record = await wallet_client.get_offer(offer_id, file_contents=True) await print_trade_record(trade_record, wallet_client, summaries=True) @@ -855,9 +869,9 @@ def print_balance(amount: int, scale: int, address_prefix: str, *, decimal_only: async def print_balances( - wallet_rpc_port: Optional[int], fp: Optional[int], wallet_type: Optional[WalletType] = None + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_type: Optional[WalletType] = None ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): summaries_response = await wallet_client.get_wallets(wallet_type) address_prefix = selected_network_address_prefix(config) @@ -933,6 +947,7 @@ async def print_balances( async def create_did_wallet( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -941,7 +956,7 @@ async def create_did_wallet( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: response = await wallet_client.create_new_did_wallet( amount, @@ -961,8 +976,10 @@ async def create_did_wallet( return [] -async def did_set_wallet_name(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, name: str) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def did_set_wallet_name( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, name: str +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): try: await wallet_client.did_set_wallet_name(wallet_id, name) print(f"Successfully set a new name for DID wallet with id {wallet_id}: {name}") @@ -970,8 +987,10 @@ async def did_set_wallet_name(wallet_rpc_port: Optional[int], fp: Optional[int], print(f"Failed to set DID wallet name: {e}") -async def get_did(wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_id: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_did( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_id: int +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): try: response = await wallet_client.get_did_id(did_wallet_id) my_did = response["my_did"] @@ -982,8 +1001,10 @@ async def get_did(wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_ print(f"Failed to get DID: {e}") -async def get_did_info(wallet_rpc_port: Optional[int], fp: Optional[int], coin_id: str, latest: bool) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_did_info( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], coin_id: str, latest: bool +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): did_padding_length = 23 try: response = await wallet_client.get_did_info(coin_id, latest) @@ -1004,6 +1025,7 @@ async def get_did_info(wallet_rpc_port: Optional[int], fp: Optional[int], coin_i async def update_did_metadata( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_id: int, @@ -1012,7 +1034,7 @@ async def update_did_metadata( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: response = await wallet_client.update_did_metadata( did_wallet_id, @@ -1035,6 +1057,7 @@ async def update_did_metadata( async def did_message_spend( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_id: int, @@ -1043,7 +1066,7 @@ async def did_message_spend( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: response = await wallet_client.did_message_spend( did_wallet_id, @@ -1063,6 +1086,7 @@ async def did_message_spend( async def transfer_did( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], did_wallet_id: int, @@ -1073,7 +1097,7 @@ async def transfer_did( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: target_address = target_cli_address.original_address response = await wallet_client.did_transfer_did( @@ -1099,6 +1123,7 @@ async def transfer_did( async def find_lost_did( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], coin_id: str, @@ -1106,7 +1131,7 @@ async def find_lost_did( recovery_list_hash: Optional[str], num_verification: Optional[int], ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): try: response = await wallet_client.find_lost_did( coin_id, @@ -1123,9 +1148,13 @@ async def find_lost_did( async def create_nft_wallet( - wallet_rpc_port: Optional[int], fp: Optional[int], did_id: Optional[CliAddress] = None, name: Optional[str] = None + root_path: pathlib.Path, + wallet_rpc_port: Optional[int], + fp: Optional[int], + did_id: Optional[CliAddress] = None, + name: Optional[str] = None, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _): try: response = await wallet_client.create_new_nft_wallet(did_id.original_address if did_id else None, name) wallet_id = response["wallet_id"] @@ -1136,6 +1165,7 @@ async def create_nft_wallet( async def mint_nft( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -1156,7 +1186,7 @@ async def mint_nft( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): royalty_address = royalty_cli_address.validate_address_type(AddressType.XCH) if royalty_cli_address else None target_address = target_cli_address.validate_address_type(AddressType.XCH) if target_cli_address else None try: @@ -1206,6 +1236,7 @@ async def mint_nft( async def add_uri_to_nft( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -1218,7 +1249,7 @@ async def add_uri_to_nft( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: if len([x for x in (uri, metadata_uri, license_uri) if x is not None]) > 1: raise ValueError("You must provide only one of the URI flags") @@ -1256,6 +1287,7 @@ async def add_uri_to_nft( async def transfer_nft( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -1266,7 +1298,7 @@ async def transfer_nft( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: target_address = target_cli_address.validate_address_type(AddressType.XCH) response = await wallet_client.transfer_nft( @@ -1328,9 +1360,14 @@ def print_nft_info(nft: NFTInfo, *, config: dict[str, Any]) -> None: async def list_nfts( - wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, num: int, start_index: int + root_path: pathlib.Path, + wallet_rpc_port: Optional[int], + fp: Optional[int], + wallet_id: int, + num: int, + start_index: int, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: response = await wallet_client.list_nfts(wallet_id, num, start_index) nft_list = response["nft_list"] @@ -1346,6 +1383,7 @@ async def list_nfts( async def set_nft_did( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id: int, @@ -1356,7 +1394,7 @@ async def set_nft_did( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): try: response = await wallet_client.set_nft_did( wallet_id, @@ -1377,8 +1415,10 @@ async def set_nft_did( return [] -async def get_nft_info(wallet_rpc_port: Optional[int], fp: Optional[int], nft_coin_id: str) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, config): +async def get_nft_info( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], nft_coin_id: str +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, config): try: response = await wallet_client.get_nft_info(nft_coin_id) nft_info = NFTInfo.from_json_dict(response["nft_info"]) @@ -1445,6 +1485,7 @@ def fungible_assets_from_offer(offer: Offer) -> list[Optional[bytes32]]: async def send_notification( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -1454,7 +1495,7 @@ async def send_notification( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _): amount: uint64 = cli_amount.convert_amount(units["chia"]) tx = await wallet_client.send_notification( @@ -1473,13 +1514,14 @@ async def send_notification( async def get_notifications( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], ids: Optional[Sequence[bytes32]], start: Optional[int], end: Optional[int], ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): if ids is not None: ids = None if len(ids) == 0 else list(ids) response = await wallet_client.get_notifications( @@ -1493,9 +1535,9 @@ async def get_notifications( async def delete_notifications( - wallet_rpc_port: Optional[int], fp: Optional[int], ids: Sequence[bytes32], delete_all: bool + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], ids: Sequence[bytes32], delete_all: bool ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): if delete_all: print(f"Success: {await wallet_client.delete_notifications()}") else: @@ -1504,6 +1546,7 @@ async def delete_notifications( async def sign_message( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], addr_type: AddressType, @@ -1512,7 +1555,7 @@ async def sign_message( did_id: Optional[CliAddress] = None, nft_id: Optional[CliAddress] = None, ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): if addr_type == AddressType.XCH: if address is None: print("Address is required for XCH address type.") @@ -1542,6 +1585,7 @@ async def sign_message( async def spend_clawback( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], fee: uint64, @@ -1550,7 +1594,7 @@ async def spend_clawback( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): tx_ids = [] for tid in tx_ids_str.split(","): tx_ids.append(bytes32.from_hexstr(tid)) @@ -1572,6 +1616,7 @@ async def spend_clawback( async def mint_vc( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], did: CliAddress, @@ -1580,7 +1625,7 @@ async def mint_vc( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.vc_mint( did.validate_address_type_get_ph(AddressType.DID), CMDTXConfigLoader().to_tx_config(units["chia"], config, fingerprint), @@ -1605,8 +1650,10 @@ async def mint_vc( return res.transactions -async def get_vcs(wallet_rpc_port: Optional[int], fp: Optional[int], start: int, count: int) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, config): +async def get_vcs( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], start: int, count: int +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, config): vc_records, proofs = await wallet_client.vc_get_list(start, count) print("Proofs:") for hash, proof_dict in proofs.items(): @@ -1630,6 +1677,7 @@ async def get_vcs(wallet_rpc_port: Optional[int], fp: Optional[int], start: int, async def spend_vc( *, + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], vc_id: bytes32, @@ -1640,7 +1688,7 @@ async def spend_vc( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): txs = ( await wallet_client.vc_spend( vc_id, @@ -1671,9 +1719,9 @@ async def spend_vc( async def add_proof_reveal( - wallet_rpc_port: Optional[int], fp: Optional[int], proofs: Sequence[str], root_only: bool + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], proofs: Sequence[str], root_only: bool ) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): if len(proofs) == 0: print("Must specify at least one proof") return @@ -1688,8 +1736,10 @@ async def add_proof_reveal( return -async def get_proofs_for_root(wallet_rpc_port: Optional[int], fp: Optional[int], proof_hash: str) -> None: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _): +async def get_proofs_for_root( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], proof_hash: str +) -> None: + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, _, _): proof_dict: dict[str, str] = await wallet_client.vc_get_proofs_for_root(bytes32.from_hexstr(proof_hash)) print("Proofs:") for proof in proof_dict: @@ -1697,6 +1747,7 @@ async def get_proofs_for_root(wallet_rpc_port: Optional[int], fp: Optional[int], async def revoke_vc( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], parent_coin_id: Optional[bytes32], @@ -1706,7 +1757,7 @@ async def revoke_vc( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, config): if parent_coin_id is None: if vc_id is None: print("Must specify either --parent-coin-id or --vc-id") @@ -1746,6 +1797,7 @@ async def revoke_vc( async def approve_r_cats( + root_path: pathlib.Path, wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: uint32, @@ -1757,7 +1809,7 @@ async def approve_r_cats( push: bool, condition_valid_times: ConditionValidTimes, ) -> list[TransactionRecord]: - async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): + async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): if wallet_client is None: return txs = await wallet_client.crcat_approve_pending(