From a32f5dcf6c816c5d1f85fbbf455e1eff68abab70 Mon Sep 17 00:00:00 2001 From: Kyle Altendorf Date: Tue, 17 Dec 2024 17:35:19 -0500 Subject: [PATCH] more --- chia/_tests/cmds/test_cmd_framework.py | 7 +- chia/_tests/pools/test_pool_cli_parsing.py | 4 +- chia/_tests/pools/test_pool_cmdline.py | 1 + chia/cmds/cmd_classes.py | 4 + chia/cmds/dao.py | 43 ++++++---- chia/cmds/farm.py | 14 +++- chia/cmds/keys.py | 22 ++--- chia/cmds/netspace.py | 4 +- chia/cmds/param_types.py | 16 +++- chia/cmds/rpc.py | 7 +- chia/cmds/sim.py | 1 + chia/cmds/wallet.py | 93 ++++++++++++---------- 12 files changed, 136 insertions(+), 80 deletions(-) diff --git a/chia/_tests/cmds/test_cmd_framework.py b/chia/_tests/cmds/test_cmd_framework.py index b3a6bf1034ec..2ed4c2341d53 100644 --- a/chia/_tests/cmds/test_cmd_framework.py +++ b/chia/_tests/cmds/test_cmd_framework.py @@ -32,7 +32,7 @@ from chia.wallet.util.tx_config import CoinSelectionConfig, TXConfig -def check_click_parsing(cmd: ChiaCommand, *args: str, obj: Optional[Any] = None) -> None: +def check_click_parsing(cmd: ChiaCommand, *args: str, context: Optional[ChiaCliContext] = None) -> None: @click.group() def _cmd() -> None: pass @@ -58,8 +58,11 @@ def new_run(self: Any) -> None: setattr(mock_type, "run", new_run) chia_command(group=_cmd, name="_", short_help="", help="")(mock_type) + if context is None: + context = ChiaCliContext() + runner = CliRunner() - result = runner.invoke(_cmd, ["_", *args], catch_exceptions=False, obj=obj) + result = runner.invoke(_cmd, ["_", *args], catch_exceptions=False, obj=context.to_click()) assert result.output == "" diff --git a/chia/_tests/pools/test_pool_cli_parsing.py b/chia/_tests/pools/test_pool_cli_parsing.py index ac7586bc6642..e4f58928ba1f 100644 --- a/chia/_tests/pools/test_pool_cli_parsing.py +++ b/chia/_tests/pools/test_pool_cli_parsing.py @@ -1,6 +1,7 @@ from __future__ import annotations from chia._tests.cmds.test_cmd_framework import check_click_parsing +from chia.cmds.cmd_classes import ChiaCliContext from chia.cmds.cmd_helpers import NeedsWalletRPC from chia.cmds.param_types import CliAddress from chia.cmds.plotnft import ( @@ -37,7 +38,8 @@ def test_plotnft_command_default_parsing() -> None: launcher_id.hex(), "--address", burn_address, - obj={"expected_prefix": "xch"}, # Needed for AddressParamType to work correctly without config + # Needed for AddressParamType to work correctly without config + context=ChiaCliContext(expected_prefix="xch"), ) check_click_parsing( diff --git a/chia/_tests/pools/test_pool_cmdline.py b/chia/_tests/pools/test_pool_cmdline.py index 48a0f7a633c0..e51cd2f417dd 100644 --- a/chia/_tests/pools/test_pool_cmdline.py +++ b/chia/_tests/pools/test_pool_cmdline.py @@ -879,6 +879,7 @@ async def test_plotnft_cli_change_payout( # This tests what happens when using None for root_path mocker.patch("chia.cmds.plotnft_funcs.DEFAULT_ROOT_PATH", root_path) await ChangePayoutInstructionsPlotNFTCMD( + context=ChiaCliContext(root_path=wallet_environments.environments[0].node.root_path), launcher_id=bytes32(32 * b"0"), address=CliAddress(burn_ph, burn_address, AddressType.XCH), ).run() diff --git a/chia/cmds/cmd_classes.py b/chia/cmds/cmd_classes.py index 43a13b9caae5..7fd6150db1e5 100644 --- a/chia/cmds/cmd_classes.py +++ b/chia/cmds/cmd_classes.py @@ -71,10 +71,14 @@ class ChiaCliContext: root_path: pathlib.Path = DEFAULT_ROOT_PATH expected_prefix: Optional[str] = None rpc_port: Optional[int] = None + keys_fingerprint: Optional[int] = None + keys_filename: Optional[str] = None + expected_currency_prefix: Optional[str] = None @classmethod def from_click(cls, ctx: click.Context) -> ChiaCliContext: if ctx.obj is None: + # TODO: should we set it up on the ctx here? return cls() existing = cast(Optional[ChiaCliContext], ctx.obj.get(cls.context_dict_key)) diff --git a/chia/cmds/dao.py b/chia/cmds/dao.py index d592380a1965..44309876f9fd 100644 --- a/chia/cmds/dao.py +++ b/chia/cmds/dao.py @@ -7,6 +7,7 @@ import click from chia.cmds import options +from chia.cmds.cmd_classes import ChiaCliContext from chia.cmds.cmds_util import CMDTXConfigLoader, tx_config_args, tx_out_cmd from chia.cmds.param_types import AmountParamType, Bytes32ParamType, CliAmount, TransactionFeeParamType, Uint64ParamType from chia.cmds.units import units @@ -62,7 +63,11 @@ def dao_add_cmd( ) -> None: from chia.cmds.dao_funcs import add_dao_wallet - asyncio.run(add_dao_wallet(ctx.obj["root_path"], wallet_rpc_port, fingerprint, name, treasury_id, filter_amount)) + asyncio.run( + add_dao_wallet( + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, name, treasury_id, filter_amount + ) + ) # ---------------------------------------------------------------------------------------- @@ -184,7 +189,7 @@ def dao_create_cmd( return asyncio.run( create_dao_wallet( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, fee, @@ -235,7 +240,7 @@ def dao_get_id_cmd( ) -> None: from chia.cmds.dao_funcs import get_treasury_id - asyncio.run(get_treasury_id(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_treasury_id(ChiaCliContext.from_click(ctx).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) @@ -286,7 +291,7 @@ def dao_add_funds_cmd( return asyncio.run( add_funds_to_treasury( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -325,7 +330,7 @@ def dao_get_balance_cmd( ) -> None: from chia.cmds.dao_funcs import get_treasury_balance - asyncio.run(get_treasury_balance(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_treasury_balance(ChiaCliContext.from_click(ctx).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) @@ -347,7 +352,7 @@ def dao_rules_cmd( ) -> None: from chia.cmds.dao_funcs import get_rules - asyncio.run(get_rules(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id)) + asyncio.run(get_rules(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id)) # ---------------------------------------------------------------------------------------- @@ -383,7 +388,11 @@ def dao_list_proposals_cmd( if not include_closed: include_closed = False - asyncio.run(list_proposals(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, include_closed)) + asyncio.run( + list_proposals( + ChiaCliContext.from_click(ctx).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) @@ -413,7 +422,9 @@ def dao_show_proposal_cmd( ) -> None: from chia.cmds.dao_funcs import show_proposal - asyncio.run(show_proposal(ctx.obj["root_path"], wallet_rpc_port, fingerprint, wallet_id, proposal_id)) + asyncio.run( + show_proposal(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, proposal_id) + ) # ---------------------------------------------------------------------------------------- @@ -477,7 +488,7 @@ def dao_vote_cmd( return asyncio.run( vote_on_proposal( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -550,7 +561,7 @@ def dao_close_proposal_cmd( return asyncio.run( close_proposal( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -614,7 +625,7 @@ def dao_lockup_coins_cmd( return asyncio.run( lockup_coins( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -665,7 +676,7 @@ def dao_release_coins_cmd( return asyncio.run( release_coins( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -715,7 +726,7 @@ def dao_exit_lockup_cmd( return asyncio.run( exit_lockup( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -819,7 +830,7 @@ def dao_create_spend_proposal_cmd( return asyncio.run( create_spend_proposal( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -931,7 +942,7 @@ def dao_create_update_proposal_cmd( return asyncio.run( create_update_proposal( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, @@ -1014,7 +1025,7 @@ def dao_create_mint_proposal_cmd( return asyncio.run( create_mint_proposal( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, wallet_id, diff --git a/chia/cmds/farm.py b/chia/cmds/farm.py index da79c10c4886..6d4a40aa68d5 100644 --- a/chia/cmds/farm.py +++ b/chia/cmds/farm.py @@ -4,6 +4,8 @@ import click +from chia.cmds.cmd_classes import ChiaCliContext + @click.group("farm", help="Manage your farm") def farm_cmd() -> None: @@ -61,7 +63,15 @@ def summary_cmd( from chia.cmds.farm_funcs import summary - asyncio.run(summary(rpc_port, wallet_rpc_port, harvester_rpc_port, farmer_rpc_port, root_path=ctx.obj["root_path"])) + asyncio.run( + summary( + rpc_port, + wallet_rpc_port, + harvester_rpc_port, + farmer_rpc_port, + root_path=ChiaCliContext.from_click(ctx).root_path, + ) + ) @farm_cmd.command("challenges", help="Show the latest challenges") @@ -87,4 +97,4 @@ def challenges_cmd(ctx: click.Context, farmer_rpc_port: Optional[int], limit: in from chia.cmds.farm_funcs import challenges - asyncio.run(challenges(ctx.obj["root_path"], farmer_rpc_port, limit)) + asyncio.run(challenges(ChiaCliContext.from_click(ctx).root_path, farmer_rpc_port, limit)) diff --git a/chia/cmds/keys.py b/chia/cmds/keys.py index 1d8bd43cad92..1856e92cb334 100644 --- a/chia/cmds/keys.py +++ b/chia/cmds/keys.py @@ -281,8 +281,9 @@ def verify_cmd(message: str, public_key: str, signature: str, as_bytes: bool, js ) @click.pass_context def derive_cmd(ctx: click.Context, fingerprint: Optional[int], filename: Optional[str]) -> None: - ctx.obj["fingerprint"] = fingerprint - ctx.obj["filename"] = filename + context = ChiaCliContext.from_click(ctx) + context.keys_fingerprint = fingerprint + context.keys_filename = filename @derive_cmd.command("search", help="Search the keyring for one or more matching derived keys or wallet addresses") @@ -338,8 +339,9 @@ def search_cmd( from chia.cmds.keys_funcs import resolve_derivation_master_key, search_derive - fingerprint: Optional[int] = ctx.obj.get("fingerprint", None) - filename: Optional[str] = ctx.obj.get("filename", None) + context = ChiaCliContext.from_click(ctx) + fingerprint: Optional[int] = context.keys_fingerprint + filename: Optional[str] = context.keys_filename # Specifying the master key is optional for the search command. If not specified, we'll search all keys. resolved_sk = None @@ -349,7 +351,7 @@ def search_cmd( print("Could not resolve private key from fingerprint/mnemonic file") found: bool = search_derive( - ChiaCliContext.from_click(ctx).root_path, + context.root_path, fingerprint, search_terms, limit, @@ -416,8 +418,9 @@ def wallet_address_cmd( ) -> None: from chia.cmds.keys_funcs import derive_wallet_address - fingerprint: Optional[int] = ctx.obj.get("fingerprint", None) - filename: Optional[str] = ctx.obj.get("filename", None) + context = ChiaCliContext.from_click(ctx) + fingerprint = context.keys_fingerprint + filename = context.keys_filename try: fingerprint, sk = _resolve_fingerprint_and_sk(filename, fingerprint, non_observer_derivation) @@ -501,8 +504,9 @@ def child_key_cmd( if key_type is None and derive_from_hd_path is None: ctx.fail("--type or --derive-from-hd-path is required") - fingerprint: Optional[int] = ctx.obj.get("fingerprint", None) - filename: Optional[str] = ctx.obj.get("filename", None) + context = ChiaCliContext.from_click(ctx) + fingerprint = context.keys_fingerprint + filename = context.keys_filename try: fingerprint, sk = _resolve_fingerprint_and_sk(filename, fingerprint, non_observer_derivation) diff --git a/chia/cmds/netspace.py b/chia/cmds/netspace.py index ff5dc3d6962d..010701bad13c 100644 --- a/chia/cmds/netspace.py +++ b/chia/cmds/netspace.py @@ -4,6 +4,8 @@ import click +from chia.cmds.cmd_classes import ChiaCliContext + @click.command("netspace", help="Estimate total farmed space on the network") @click.option( @@ -45,4 +47,4 @@ def netspace_cmd(ctx: click.Context, rpc_port: Optional[int], delta_block_height from chia.cmds.netspace_funcs import netstorge_async - asyncio.run(netstorge_async(ctx.obj["root_path"], rpc_port, delta_block_height, start)) + asyncio.run(netstorge_async(ChiaCliContext.from_click(ctx).root_path, rpc_port, delta_block_height, start)) diff --git a/chia/cmds/param_types.py b/chia/cmds/param_types.py index 30e9962f1144..021aefead1b7 100644 --- a/chia/cmds/param_types.py +++ b/chia/cmds/param_types.py @@ -174,15 +174,23 @@ def convert(self, value: Any, param: Optional[click.Parameter], ctx: Optional[cl hrp, _b32data = bech32_decode(value) if hrp in {"xch", "txch"}: # I hate having to load the config here addr_type: AddressType = AddressType.XCH + # attempt to get cached prefix - expected_prefix = ChiaCliContext.from_click(ctx).expected_prefix if ctx else None + expected_prefix: Optional[str] = None + root_path = DEFAULT_ROOT_PATH + + if ctx is not None: + context = ChiaCliContext.from_click(ctx) + root_path = context.root_path + expected_prefix = context.expected_prefix + if expected_prefix is None: - root_path = ChiaCliContext.from_click(ctx).root_path if ctx is not None else DEFAULT_ROOT_PATH config = load_config(root_path, "config.yaml") expected_prefix = selected_network_address_prefix(config) - if ctx is not None: - ctx.obj["expected_prefix"] = expected_prefix # cache prefix + if ctx is not None: + context.expected_prefix = expected_prefix # cache prefix + # now that we have the expected prefix, we can validate the address is for the right network if hrp != expected_prefix: self.fail(f"Unexpected Address Prefix: {hrp}, are you sure its for the right network?", param, ctx) diff --git a/chia/cmds/rpc.py b/chia/cmds/rpc.py index f5eed0b362a4..92cfd43ca41c 100644 --- a/chia/cmds/rpc.py +++ b/chia/cmds/rpc.py @@ -9,6 +9,7 @@ import click from aiohttp import ClientResponseError +from chia.cmds.cmd_classes import ChiaCliContext from chia.util.config import load_config from chia.util.ints import uint16 @@ -103,7 +104,7 @@ def rpc_cmd() -> None: @click.argument("service", type=click.Choice(services)) @click.pass_context def endpoints_cmd(ctx: click.Context, service: str) -> None: - root_path = ctx.obj["root_path"] + root_path = ChiaCliContext.from_click(ctx).root_path config = load_config(root_path, "config.yaml") try: routes = get_routes(service, config, root_path=root_path) @@ -119,7 +120,7 @@ def endpoints_cmd(ctx: click.Context, service: str) -> None: def status_cmd(ctx: click.Context, json_output: bool) -> None: import json - root_path = ctx.obj["root_path"] + root_path = ChiaCliContext.from_click(ctx).root_path config = load_config(root_path, "config.yaml") def print_row(c0: str, c1: str) -> None: @@ -177,7 +178,7 @@ def rpc_client_cmd( json_file: Optional[TextIO], service: str = service, ) -> None: - root_path: Path = ctx.obj["root_path"] + root_path: Path = ChiaCliContext.from_click(ctx).root_path config = load_config(root_path, "config.yaml") if request is not None and json_file is not None: sys.exit( diff --git a/chia/cmds/sim.py b/chia/cmds/sim.py index 8718426f194f..fd7390a6d544 100644 --- a/chia/cmds/sim.py +++ b/chia/cmds/sim.py @@ -36,6 +36,7 @@ @click.pass_context def sim_cmd(ctx: click.Context, rpc_port: Optional[int], root_path: str, simulator_name: str) -> None: ctx.ensure_object(dict) + # TODO: maybe update instead of replacing? ctx.obj.update( ChiaCliContext( root_path=Path(root_path) / simulator_name, diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index f4832ba192b2..6912d9a25528 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -61,7 +61,7 @@ def get_transaction_cmd( asyncio.run( get_transaction( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fingerprint=fingerprint, tx_id=tx_id, @@ -149,7 +149,7 @@ def get_transactions_cmd( asyncio.run( get_transactions( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -244,7 +244,7 @@ def send_cmd( return asyncio.run( send( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -286,7 +286,10 @@ def show_cmd(ctx: click.Context, wallet_rpc_port: Optional[int], fingerprint: in asyncio.run( print_balances( - ctx.obj["root_path"], wallet_rpc_port, fingerprint, WalletType[wallet_type.upper()] if wallet_type else None + ChiaCliContext.from_click(ctx).root_path, + wallet_rpc_port, + fingerprint, + WalletType[wallet_type.upper()] if wallet_type else None, ) ) @@ -317,7 +320,7 @@ def get_address_cmd( ) -> None: from chia.cmds.wallet_funcs import get_address - asyncio.run(get_address(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, new_address)) + asyncio.run(get_address(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, new_address)) @wallet_cmd.command( @@ -367,7 +370,7 @@ def clawback( return asyncio.run( spend_clawback( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=fee, @@ -395,7 +398,9 @@ def delete_unconfirmed_transactions_cmd( ) -> None: from chia.cmds.wallet_funcs import delete_unconfirmed_transactions - asyncio.run(delete_unconfirmed_transactions(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id)) + asyncio.run( + delete_unconfirmed_transactions(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id) + ) @wallet_cmd.command("get_derivation_index", help="Get the last puzzle hash derivation path index") @@ -411,7 +416,7 @@ def delete_unconfirmed_transactions_cmd( 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(ctx.obj["root_path"], wallet_rpc_port, fingerprint)) + asyncio.run(get_derivation_index(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint)) @wallet_cmd.command("sign_message", help="Sign a message by a derivation address") @@ -434,7 +439,7 @@ def address_sign_message( asyncio.run( sign_message( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.XCH, @@ -464,7 +469,7 @@ def update_derivation_index_cmd( ) -> None: from chia.cmds.wallet_funcs import update_derivation_index - asyncio.run(update_derivation_index(ctx.obj["root_path"], wallet_rpc_port, fingerprint, index)) + asyncio.run(update_derivation_index(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, index)) @wallet_cmd.command("add_token", help="Add/Rename a CAT to the wallet by its asset ID") @@ -494,7 +499,7 @@ def add_token_cmd( ) -> None: from chia.cmds.wallet_funcs import add_token - asyncio.run(add_token(ctx.obj["root_path"], wallet_rpc_port, fingerprint, asset_id, token_name)) + asyncio.run(add_token(ChiaCliContext.from_click(ctx).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") @@ -558,7 +563,7 @@ def make_offer_cmd( asyncio.run( make_offer( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=fee, @@ -610,7 +615,7 @@ def get_offers_cmd( asyncio.run( get_offers( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, offer_id=id, @@ -661,7 +666,7 @@ def take_offer_cmd( return asyncio.run( take_offer( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, fee, @@ -701,7 +706,7 @@ def cancel_offer_cmd( return asyncio.run( cancel_offer( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, fee, @@ -767,7 +772,7 @@ def did_create_wallet_cmd( return asyncio.run( create_did_wallet( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, fee, @@ -798,7 +803,7 @@ def did_sign_message( asyncio.run( sign_message( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.DID, @@ -825,7 +830,7 @@ def did_wallet_name_cmd( ) -> None: from chia.cmds.wallet_funcs import did_set_wallet_name - asyncio.run(did_set_wallet_name(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, name)) + asyncio.run(did_set_wallet_name(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, name)) @did_cmd.command("get_did", help="Get DID from wallet") @@ -842,7 +847,7 @@ def did_wallet_name_cmd( 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(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id)) + asyncio.run(get_did(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id)) @did_cmd.command("get_details", help="Get more details of any DID") @@ -862,7 +867,7 @@ def did_get_details_cmd( ) -> None: from chia.cmds.wallet_funcs import get_did_info - asyncio.run(get_did_info(ctx.obj["root_path"], wallet_rpc_port, fingerprint, coin_id, latest)) + asyncio.run(get_did_info(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, coin_id, latest)) @did_cmd.command("update_metadata", help="Update the metadata of a DID") @@ -898,7 +903,7 @@ def did_update_metadata_cmd( return asyncio.run( update_did_metadata( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, @@ -950,7 +955,7 @@ def did_find_lost_cmd( asyncio.run( find_lost_did( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, coin_id=coin_id, @@ -1022,7 +1027,7 @@ def did_message_spend_cmd( return asyncio.run( did_message_spend( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, @@ -1074,7 +1079,7 @@ def did_transfer_did( return asyncio.run( transfer_did( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, @@ -1115,7 +1120,7 @@ def nft_wallet_create_cmd( ) -> None: from chia.cmds.wallet_funcs import create_nft_wallet - asyncio.run(create_nft_wallet(ctx.obj["root_path"], wallet_rpc_port, fingerprint, did_id, name)) + asyncio.run(create_nft_wallet(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, did_id, name)) @nft_cmd.command("sign_message", help="Sign a message by a NFT") @@ -1137,7 +1142,7 @@ def nft_sign_message( asyncio.run( sign_message( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, addr_type=AddressType.NFT, @@ -1221,7 +1226,7 @@ def nft_mint_cmd( return asyncio.run( mint_nft( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1287,7 +1292,7 @@ def nft_add_uri_cmd( return asyncio.run( add_uri_to_nft( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1341,7 +1346,7 @@ def nft_transfer_cmd( return asyncio.run( transfer_nft( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1373,7 +1378,7 @@ def nft_list_cmd( ) -> None: from chia.cmds.wallet_funcs import list_nfts - asyncio.run(list_nfts(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, num, start_index)) + asyncio.run(list_nfts(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, num, start_index)) @nft_cmd.command("set_did", help="Set a DID on an NFT") @@ -1414,7 +1419,7 @@ def nft_set_did_cmd( return asyncio.run( set_nft_did( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, wallet_id=id, @@ -1448,7 +1453,7 @@ def nft_get_info_cmd( ) -> None: from chia.cmds.wallet_funcs import get_nft_info - asyncio.run(get_nft_info(ctx.obj["root_path"], wallet_rpc_port, fingerprint, nft_coin_id)) + asyncio.run(get_nft_info(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, nft_coin_id)) # Keep at bottom. @@ -1501,7 +1506,7 @@ def send_notification_cmd( message_bytes: bytes = bytes(message, "utf8") return asyncio.run( send_notification( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, fee, @@ -1537,7 +1542,9 @@ def get_notifications_cmd( ) -> None: from chia.cmds.wallet_funcs import get_notifications - asyncio.run(get_notifications(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, start, end)) + asyncio.run( + get_notifications(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, start, end) + ) @notification_cmd.command("delete", help="Delete notification(s) that are in your wallet") @@ -1561,7 +1568,7 @@ def delete_notifications_cmd( ) -> None: from chia.cmds.wallet_funcs import delete_notifications - asyncio.run(delete_notifications(ctx.obj["root_path"], wallet_rpc_port, fingerprint, id, all)) + asyncio.run(delete_notifications(ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, id, all)) @wallet_cmd.group("vcs", short_help="Verifiable Credential related actions") @@ -1603,7 +1610,7 @@ def mint_vc_cmd( return asyncio.run( mint_vc( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, did, @@ -1640,7 +1647,7 @@ def get_vcs_cmd( ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import get_vcs - asyncio.run(get_vcs(ctx.obj["root_path"], wallet_rpc_port, fingerprint, start, count)) + asyncio.run(get_vcs(ChiaCliContext.from_click(ctx).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") @@ -1692,7 +1699,7 @@ def spend_vc_cmd( return asyncio.run( spend_vc( - root_path=ctx.obj["root_path"], + root_path=ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port=wallet_rpc_port, fp=fingerprint, vc_id=vc_id, @@ -1727,7 +1734,9 @@ def add_proof_reveal_cmd( ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import add_proof_reveal - asyncio.run(add_proof_reveal(ctx.obj["root_path"], wallet_rpc_port, fingerprint, proof, root_only)) + asyncio.run( + add_proof_reveal(ChiaCliContext.from_click(ctx).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") @@ -1749,7 +1758,7 @@ def get_proofs_for_root_cmd( ) -> None: # pragma: no cover from chia.cmds.wallet_funcs import get_proofs_for_root - asyncio.run(get_proofs_for_root(ctx.obj["root_path"], wallet_rpc_port, fingerprint, proof_hash)) + asyncio.run(get_proofs_for_root(ChiaCliContext.from_click(ctx).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") @@ -1799,7 +1808,7 @@ def revoke_vc_cmd( return asyncio.run( revoke_vc( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, parent_coin_id, @@ -1869,7 +1878,7 @@ def approve_r_cats_cmd( return asyncio.run( approve_r_cats( - ctx.obj["root_path"], + ChiaCliContext.from_click(ctx).root_path, wallet_rpc_port, fingerprint, uint32(id),