From c23b890c32fc41b6a39ea178d160331623ed3c7b Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 26 Mar 2024 08:54:18 -0700 Subject: [PATCH] Port `chia wallet vcs ...` to @tx_out_cmd --- chia/_tests/cmds/wallet/test_vcs.py | 30 +++++++++++++++----- chia/cmds/wallet.py | 37 ++++++++++++++++++------ chia/cmds/wallet_funcs.py | 44 +++++++++++++++++++++-------- 3 files changed, 83 insertions(+), 28 deletions(-) diff --git a/chia/_tests/cmds/wallet/test_vcs.py b/chia/_tests/cmds/wallet/test_vcs.py index 398f2695472d..6f96b2f5bc1e 100644 --- a/chia/_tests/cmds/wallet/test_vcs.py +++ b/chia/_tests/cmds/wallet/test_vcs.py @@ -31,8 +31,9 @@ async def vc_mint( tx_config: TXConfig, target_address: Optional[bytes32] = None, fee: uint64 = uint64(0), + push: bool = True, ) -> VCMintResponse: - self.add_to_log("vc_mint", (did_id, tx_config, target_address, fee)) + self.add_to_log("vc_mint", (did_id, tx_config, target_address, fee, push)) return VCMintResponse( [STD_UTX], @@ -64,7 +65,7 @@ async def vc_mint( f"Transaction {get_bytes32(2).hex()}", ] run_cli_command_and_assert(capsys, root_dir, command_args, assert_list) - expected_calls: logType = {"vc_mint": [(did_bytes, DEFAULT_TX_CONFIG, target_bytes, 500000000000)]} + expected_calls: logType = {"vc_mint": [(did_bytes, DEFAULT_TX_CONFIG, target_bytes, 500000000000, True)]} test_rpc_clients.wallet_rpc_client.check_log(expected_calls) @@ -117,8 +118,11 @@ async def vc_spend( new_proof_hash: Optional[bytes32] = None, provider_inner_puzhash: Optional[bytes32] = None, fee: uint64 = uint64(0), + push: bool = True, ) -> VCSpendResponse: - self.add_to_log("vc_spend", (vc_id, tx_config, new_puzhash, new_proof_hash, provider_inner_puzhash, fee)) + self.add_to_log( + "vc_spend", (vc_id, tx_config, new_puzhash, new_proof_hash, provider_inner_puzhash, fee, push) + ) return VCSpendResponse([STD_UTX], [STD_TX]) inst_rpc_client = VcsUpdateProofsRpcClient() # pylint: disable=no-value-for-parameter @@ -145,7 +149,15 @@ async def vc_spend( run_cli_command_and_assert(capsys, root_dir, command_args, assert_list) expected_calls: logType = { "vc_spend": [ - (vc_bytes, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), target_ph, new_proof, None, uint64(500000000000)) + ( + vc_bytes, + DEFAULT_TX_CONFIG.override(reuse_puzhash=True), + target_ph, + new_proof, + None, + uint64(500000000000), + True, + ) ] } test_rpc_clients.wallet_rpc_client.check_log(expected_calls) @@ -219,8 +231,9 @@ async def vc_revoke( vc_parent_id: bytes32, tx_config: TXConfig, fee: uint64 = uint64(0), + push: bool = True, ) -> VCRevokeResponse: - self.add_to_log("vc_revoke", (vc_parent_id, tx_config, fee)) + self.add_to_log("vc_revoke", (vc_parent_id, tx_config, fee, push)) return VCRevokeResponse([STD_UTX], [STD_TX]) inst_rpc_client = VcsRevokeRpcClient() # pylint: disable=no-value-for-parameter @@ -242,8 +255,8 @@ async def vc_revoke( expected_calls: logType = { "vc_get": [(vc_id,)], "vc_revoke": [ - (parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000)), - (parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000)), + (parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000), True), + (parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000), True), ], } test_rpc_clients.wallet_rpc_client.check_log(expected_calls) @@ -260,6 +273,7 @@ async def crcat_approve_pending( min_amount_to_claim: uint64, tx_config: TXConfig, fee: uint64 = uint64(0), + push: bool = True, ) -> List[TransactionRecord]: self.add_to_log( "crcat_approve_pending", @@ -268,6 +282,7 @@ async def crcat_approve_pending( min_amount_to_claim, tx_config, fee, + push, ), ) return [STD_TX] @@ -305,6 +320,7 @@ async def crcat_approve_pending( reuse_puzhash=True, ), uint64(500000000000), + True, ) ], "get_wallets": [(None,)], diff --git a/chia/cmds/wallet.py b/chia/cmds/wallet.py index d5db3becea4c..f2cd4f8724b2 100644 --- a/chia/cmds/wallet.py +++ b/chia/cmds/wallet.py @@ -1386,16 +1386,18 @@ def vcs_cmd() -> None: # pragma: no cover @click.option("-d", "--did", help="The DID of the VC's proof provider", type=str, required=True) @click.option("-t", "--target-address", help="The address to send the VC to once it's minted", type=str, required=False) @click.option("-m", "--fee", help="Blockchain fee for mint transaction, in XCH", type=str, required=False, default="0") +@tx_out_cmd def mint_vc_cmd( wallet_rpc_port: Optional[int], fingerprint: int, did: str, target_address: Optional[str], fee: str, -) -> None: # pragma: no cover + push: bool, +) -> List[TransactionRecord]: from .wallet_funcs import mint_vc - asyncio.run(mint_vc(wallet_rpc_port, fingerprint, did, Decimal(fee), target_address)) + return asyncio.run(mint_vc(wallet_rpc_port, fingerprint, did, Decimal(fee), target_address, push=push)) @vcs_cmd.command("get", short_help="Get a list of existing VCs") @@ -1451,6 +1453,7 @@ def get_vcs_cmd( default=False, show_default=True, ) +@tx_out_cmd def spend_vc_cmd( wallet_rpc_port: Optional[int], fingerprint: int, @@ -1459,10 +1462,11 @@ def spend_vc_cmd( new_proof_hash: str, fee: str, reuse_puzhash: bool, -) -> None: # pragma: no cover + push: bool, +) -> List[TransactionRecord]: from .wallet_funcs import spend_vc - asyncio.run( + return asyncio.run( spend_vc( wallet_rpc_port=wallet_rpc_port, fp=fingerprint, @@ -1471,6 +1475,7 @@ def spend_vc_cmd( new_puzhash=new_puzhash, new_proof_hash=new_proof_hash, reuse_puzhash=reuse_puzhash, + push=push, ) ) @@ -1549,6 +1554,7 @@ def get_proofs_for_root_cmd( default=False, show_default=True, ) +@tx_out_cmd def revoke_vc_cmd( wallet_rpc_port: Optional[int], fingerprint: int, @@ -1556,10 +1562,13 @@ def revoke_vc_cmd( vc_id: Optional[str], fee: str, reuse_puzhash: bool, -) -> None: # pragma: no cover + push: bool, +) -> List[TransactionRecord]: from .wallet_funcs import revoke_vc - asyncio.run(revoke_vc(wallet_rpc_port, fingerprint, parent_coin_id, vc_id, Decimal(fee), reuse_puzhash)) + return asyncio.run( + revoke_vc(wallet_rpc_port, fingerprint, parent_coin_id, vc_id, Decimal(fee), reuse_puzhash, push=push) + ) @vcs_cmd.command("approve_r_cats", help="Claim any R-CATs that are currently pending VC approval") @@ -1586,6 +1595,7 @@ def revoke_vc_cmd( is_flag=True, default=False, ) +@tx_out_cmd def approve_r_cats_cmd( wallet_rpc_port: Optional[int], fingerprint: int, @@ -1595,11 +1605,20 @@ def approve_r_cats_cmd( min_coin_amount: Optional[Decimal], max_coin_amount: Optional[Decimal], reuse: bool, -) -> None: # pragma: no cover + push: bool, +) -> List[TransactionRecord]: from .wallet_funcs import approve_r_cats - asyncio.run( + return asyncio.run( approve_r_cats( - wallet_rpc_port, fingerprint, id, min_amount_to_claim, Decimal(fee), min_coin_amount, max_coin_amount, reuse + wallet_rpc_port, + fingerprint, + id, + min_amount_to_claim, + Decimal(fee), + min_coin_amount, + max_coin_amount, + reuse, + push, ) ) diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index 69723e10de16..a601c42f58e2 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -1530,8 +1530,13 @@ async def spend_clawback( async def mint_vc( - wallet_rpc_port: Optional[int], fp: Optional[int], did: str, d_fee: Decimal, target_address: Optional[str] -) -> None: # pragma: no cover + wallet_rpc_port: Optional[int], + fp: Optional[int], + did: str, + d_fee: Decimal, + target_address: Optional[str], + push: bool, +) -> List[TransactionRecord]: async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): res = await wallet_client.vc_mint( decode_puzzle_hash(ensure_valid_address(did, allowed_types={AddressType.DID}, config=config)), @@ -1544,9 +1549,11 @@ async def mint_vc( ) ), uint64(int(d_fee * units["chia"])), + push=push, ) - print(f"New VC with launcher ID minted: {res.vc_record.vc.launcher_id.hex()}") + if push: + print(f"New VC with launcher ID minted: {res.vc_record.vc.launcher_id.hex()}") print("Relevant TX records:") print("") for tx in res.transactions: @@ -1557,6 +1564,7 @@ async def mint_vc( address_prefix=selected_network_address_prefix(config), mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET), ) + return res.transactions async def get_vcs( @@ -1593,7 +1601,8 @@ async def spend_vc( new_puzhash: Optional[str], new_proof_hash: str, reuse_puzhash: bool, -) -> None: # pragma: no cover + push: bool = True, +) -> List[TransactionRecord]: async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config): txs = ( await wallet_client.vc_spend( @@ -1604,10 +1613,12 @@ async def spend_vc( tx_config=CMDTXConfigLoader( reuse_puzhash=reuse_puzhash, ).to_tx_config(units["chia"], config, fingerprint), + push=push, ) ).transactions - print("Proofs successfully updated!") + if push: + print("Proofs successfully updated!") print("Relevant TX records:") print("") for tx in txs: @@ -1618,6 +1629,7 @@ async def spend_vc( address_prefix=selected_network_address_prefix(config), mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET), ) + return txs async def add_proof_reveal( @@ -1655,16 +1667,17 @@ async def revoke_vc( vc_id: Optional[str], fee: Decimal, reuse_puzhash: bool, -) -> None: # pragma: no cover + push: bool, +) -> List[TransactionRecord]: async with get_wallet_client(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") - return + return [] record = await wallet_client.vc_get(bytes32.from_hexstr(vc_id)) if record is None: print(f"Cannot find a VC with ID {vc_id}") - return + return [] parent_id: bytes32 = bytes32(record.vc.coin.parent_coin_info) else: parent_id = bytes32.from_hexstr(parent_coin_id) @@ -1675,10 +1688,12 @@ async def revoke_vc( tx_config=CMDTXConfigLoader( reuse_puzhash=reuse_puzhash, ).to_tx_config(units["chia"], config, fingerprint), + push=push, ) ).transactions - print("VC successfully revoked!") + if push: + print("VC successfully revoked!") print("Relevant TX records:") print("") for tx in txs: @@ -1689,6 +1704,7 @@ async def revoke_vc( address_prefix=selected_network_address_prefix(config), mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET), ) + return txs async def approve_r_cats( @@ -1700,7 +1716,8 @@ async def approve_r_cats( min_coin_amount: Optional[Decimal], max_coin_amount: Optional[Decimal], reuse: bool, -) -> None: # pragma: no cover + push: bool = True, +) -> List[TransactionRecord]: async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config): if wallet_client is None: return @@ -1713,9 +1730,11 @@ async def approve_r_cats( max_coin_amount=None if max_coin_amount is None else str(max_coin_amount), reuse_puzhash=reuse, ).to_tx_config(units["cat"], config, fingerprint), + push=push, ) - print("VC successfully approved R-CATs!") + if push: + print("VC successfully approved R-CATs!") print("Relevant TX records:") print("") for tx in txs: @@ -1730,7 +1749,7 @@ async def approve_r_cats( ) except LookupError as e: print(e.args[0]) - return + return txs print_transaction( tx, @@ -1739,3 +1758,4 @@ async def approve_r_cats( address_prefix=selected_network_address_prefix(config), mojo_per_unit=mojo_per_unit, ) + return txs