diff --git a/chia/_tests/cmds/wallet/test_vcs.py b/chia/_tests/cmds/wallet/test_vcs.py index 4389d515e0b7..1bec67dc20ba 100644 --- a/chia/_tests/cmds/wallet/test_vcs.py +++ b/chia/_tests/cmds/wallet/test_vcs.py @@ -9,13 +9,14 @@ from chia._tests.cmds.cmd_test_utils import TestRpcClients, TestWalletRpcClient, logType, run_cli_command_and_assert from chia._tests.cmds.wallet.test_consts import FINGERPRINT_ARG, STD_TX, STD_UTX, get_bytes32 from chia.util.bech32m import encode_puzzle_hash -from chia.wallet.conditions import ConditionValidTimes +from chia.wallet.conditions import Condition, ConditionValidTimes from chia.wallet.lineage_proof import LineageProof -from chia.wallet.transaction_record import TransactionRecord from chia.wallet.util.tx_config import DEFAULT_TX_CONFIG, TXConfig from chia.wallet.vc_wallet.vc_drivers import VCLineageProof, VerifiedCredential from chia.wallet.vc_wallet.vc_store import VCRecord from chia.wallet.wallet_request_types import ( + CRCATApprovePending, + CRCATApprovePendingResponse, GetWallets, VCAddProofs, VCGet, @@ -335,25 +336,23 @@ def test_vcs_approve_r_cats(capsys: object, get_test_cli_clients: tuple[TestRpcC class VcsApproveRCATSRpcClient(TestWalletRpcClient): async def crcat_approve_pending( self, - wallet_id: uint32, - min_amount_to_claim: uint64, + request: CRCATApprovePending, tx_config: TXConfig, - fee: uint64 = uint64(0), - push: bool = True, + extra_conditions: tuple[Condition, ...] = tuple(), timelock_info: ConditionValidTimes = ConditionValidTimes(), - ) -> list[TransactionRecord]: + ) -> CRCATApprovePendingResponse: self.add_to_log( "crcat_approve_pending", ( - wallet_id, - min_amount_to_claim, + request.wallet_id, + request.min_amount_to_claim, tx_config, - fee, - push, + request.fee, + request.push, timelock_info, ), ) - return [STD_TX] + return CRCATApprovePendingResponse([STD_UTX], [STD_TX]) inst_rpc_client = VcsApproveRCATSRpcClient() test_rpc_clients.wallet_rpc_client = inst_rpc_client diff --git a/chia/_tests/wallet/cat_wallet/test_trades.py b/chia/_tests/wallet/cat_wallet/test_trades.py index 3fce269718c7..c8bfad1cb3f1 100644 --- a/chia/_tests/wallet/cat_wallet/test_trades.py +++ b/chia/_tests/wallet/cat_wallet/test_trades.py @@ -36,7 +36,14 @@ from chia.wallet.vc_wallet.cr_cat_wallet import CRCATWallet from chia.wallet.vc_wallet.vc_store import VCProofs from chia.wallet.wallet_node import WalletNode -from chia.wallet.wallet_request_types import VCAddProofs, VCGetList, VCGetProofsForRoot, VCMint, VCSpend +from chia.wallet.wallet_request_types import ( + CRCATApprovePending, + VCAddProofs, + VCGetList, + VCGetProofsForRoot, + VCMint, + VCSpend, +) from chia.wallet.wallet_spend_bundle import WalletSpendBundle @@ -613,8 +620,7 @@ async def test_cat_trades( if credential_restricted: await client_maker.crcat_approve_pending( - new_cat_wallet_maker.id(), - uint64(2), + CRCATApprovePending(wallet_id=new_cat_wallet_maker.id(), min_amount_to_claim=uint64(2), push=True), wallet_environments.tx_config, ) @@ -953,8 +959,7 @@ async def assert_trade_tx_number(wallet_node: WalletNode, trade_id: bytes32, num if credential_restricted: await client_maker.crcat_approve_pending( - new_cat_wallet_maker.id(), - uint64(6), + CRCATApprovePending(wallet_id=new_cat_wallet_maker.id(), min_amount_to_claim=uint64(6), push=True), wallet_environments.tx_config, ) @@ -1191,8 +1196,7 @@ async def assert_trade_tx_number(wallet_node: WalletNode, trade_id: bytes32, num if credential_restricted: await client_maker.crcat_approve_pending( - cat_wallet_maker.id(), - uint64(8), + CRCATApprovePending(wallet_id=cat_wallet_maker.id(), min_amount_to_claim=uint64(8), push=True), wallet_environments.tx_config, ) @@ -1238,8 +1242,7 @@ async def assert_trade_tx_number(wallet_node: WalletNode, trade_id: bytes32, num ) await client_maker.crcat_approve_pending( - new_cat_wallet_maker.id(), - uint64(9), + CRCATApprovePending(wallet_id=new_cat_wallet_maker.id(), min_amount_to_claim=uint64(9), push=True), wallet_environments.tx_config, ) @@ -1561,8 +1564,7 @@ async def assert_trade_tx_number(wallet_node: WalletNode, trade_id: bytes32, num if credential_restricted: await client_maker.crcat_approve_pending( - new_cat_wallet_maker.id(), - uint64(15), + CRCATApprovePending(wallet_id=new_cat_wallet_maker.id(), min_amount_to_claim=uint64(15), push=True), wallet_environments.tx_config, ) diff --git a/chia/_tests/wallet/vc_wallet/test_vc_wallet.py b/chia/_tests/wallet/vc_wallet/test_vc_wallet.py index 5925de821feb..cdb30676027f 100644 --- a/chia/_tests/wallet/vc_wallet/test_vc_wallet.py +++ b/chia/_tests/wallet/vc_wallet/test_vc_wallet.py @@ -33,6 +33,7 @@ from chia.wallet.wallet_request_types import ( Addition, CATSpend, + CRCATApprovePending, CreateSignedTransaction, GetTransactions, GetWallets, @@ -509,10 +510,10 @@ async def test_vc_lifecycle(wallet_environments: WalletTestFramework) -> None: # Claim the pending approval to our wallet await client_1.crcat_approve_pending( - env_1.dealias_wallet_id("crcat"), - uint64(90), + CRCATApprovePending( + wallet_id=env_1.dealias_wallet_id("crcat"), min_amount_to_claim=uint64(90), fee=uint64(90), push=True + ), wallet_environments.tx_config, - fee=uint64(90), ) await wallet_environments.process_pending_states( [ diff --git a/chia/cmds/wallet_funcs.py b/chia/cmds/wallet_funcs.py index 666b0284c968..fbe7d3fcce7e 100644 --- a/chia/cmds/wallet_funcs.py +++ b/chia/cmds/wallet_funcs.py @@ -53,6 +53,7 @@ CATSpend, CATSpendResponse, ClawbackPuzzleDecoratorOverride, + CRCATApprovePending, CreateNewWallet, CreateNewWalletType, CreateOfferForIDs, @@ -1943,18 +1944,22 @@ async def approve_r_cats( async with get_wallet_client(root_path, wallet_rpc_port, fingerprint) as (wallet_client, fp, config): if wallet_client is None: return - txs = await wallet_client.crcat_approve_pending( - wallet_id=wallet_id, - min_amount_to_claim=min_amount_to_claim.convert_amount(units["cat"]), - fee=fee, - tx_config=CMDTXConfigLoader( - min_coin_amount=min_coin_amount, - max_coin_amount=max_coin_amount, - reuse_puzhash=reuse, - ).to_tx_config(units["cat"], config, fp), - push=push, - timelock_info=condition_valid_times, - ) + txs = ( + await wallet_client.crcat_approve_pending( + CRCATApprovePending( + wallet_id=wallet_id, + min_amount_to_claim=min_amount_to_claim.convert_amount(units["cat"]), + fee=fee, + push=push, + ), + tx_config=CMDTXConfigLoader( + min_coin_amount=min_coin_amount, + max_coin_amount=max_coin_amount, + reuse_puzhash=reuse, + ).to_tx_config(units["cat"], config, fp), + timelock_info=condition_valid_times, + ) + ).transactions if push: print("VC successfully approved R-CATs!") diff --git a/chia/wallet/wallet_request_types.py b/chia/wallet/wallet_request_types.py index 17febb666529..700155fa1c5c 100644 --- a/chia/wallet/wallet_request_types.py +++ b/chia/wallet/wallet_request_types.py @@ -2435,3 +2435,16 @@ def from_json_dict(cls, json_dict: dict[str, Any]) -> Self: ).to_json_dict() return super().from_json_dict(json_dict) + + +@streamable +@dataclass(frozen=True) +class CRCATApprovePending(TransactionEndpointRequest): + wallet_id: uint32 = field(default_factory=default_raise) + min_amount_to_claim: uint64 = field(default_factory=default_raise) + + +@streamable +@dataclass(frozen=True) +class CRCATApprovePendingResponse(TransactionEndpointResponse): + pass diff --git a/chia/wallet/wallet_rpc_api.py b/chia/wallet/wallet_rpc_api.py index 240906de6ea8..cc0836757ef3 100644 --- a/chia/wallet/wallet_rpc_api.py +++ b/chia/wallet/wallet_rpc_api.py @@ -30,7 +30,7 @@ from chia.util.errors import KeychainIsLocked from chia.util.keychain import bytes_to_mnemonic, generate_mnemonic from chia.util.path import path_from_root -from chia.util.streamable import Streamable, UInt32Range, streamable +from chia.util.streamable import UInt32Range from chia.util.ws_message import WsRpcMessage, create_payload_dict from chia.wallet.cat_wallet.cat_constants import DEFAULT_CATS from chia.wallet.cat_wallet.cat_info import CRCATInfo @@ -129,6 +129,8 @@ CheckOfferValidityResponse, CombineCoins, CombineCoinsResponse, + CRCATApprovePending, + CRCATApprovePendingResponse, CreateNewDL, CreateNewDLResponse, CreateNewWallet, @@ -4081,12 +4083,13 @@ async def vc_revoke( return VCRevokeResponse([], []) # tx_endpoint takes care of filling this out @tx_endpoint(push=True) + @marshal async def crcat_approve_pending( self, - request: dict[str, Any], + request: CRCATApprovePending, action_scope: WalletActionScope, extra_conditions: tuple[Condition, ...] = tuple(), - ) -> EndpointResult: + ) -> CRCATApprovePendingResponse: """ Moving any "pending approval" CR-CATs into the spendable balance of the wallet :param request: Required 'wallet_id'. Optional 'min_amount_to_claim' (default: full balance). @@ -4095,27 +4098,18 @@ async def crcat_approve_pending( (CRCAT TX + fee TX) """ - @streamable - @dataclasses.dataclass(frozen=True) - class CRCATApprovePending(Streamable): - wallet_id: uint32 - min_amount_to_claim: uint64 - fee: uint64 = uint64(0) - - parsed_request = CRCATApprovePending.from_json_dict(request) - cr_cat_wallet = self.service.wallet_state_manager.wallets[parsed_request.wallet_id] + cr_cat_wallet = self.service.wallet_state_manager.wallets[request.wallet_id] assert isinstance(cr_cat_wallet, CRCATWallet) await cr_cat_wallet.claim_pending_approval_balance( - parsed_request.min_amount_to_claim, + request.min_amount_to_claim, action_scope, - fee=parsed_request.fee, + fee=request.fee, extra_conditions=extra_conditions, ) - return { - "transactions": None, # tx_endpoint wrapper will take care of this - } + # tx_endpoint will take care of default values here + return CRCATApprovePendingResponse([], []) @marshal async def gather_signing_info( diff --git a/chia/wallet/wallet_rpc_client.py b/chia/wallet/wallet_rpc_client.py index 3cdaf075c5e7..0e3265c2d6ae 100644 --- a/chia/wallet/wallet_rpc_client.py +++ b/chia/wallet/wallet_rpc_client.py @@ -2,8 +2,6 @@ from typing import Any -from chia_rs.sized_ints import uint32, uint64 - from chia.data_layer.data_layer_util import DLProof, VerifyProofResponse from chia.rpc.rpc_client import RpcClient from chia.wallet.conditions import Condition, ConditionValidTimes @@ -37,6 +35,8 @@ CheckOfferValidityResponse, CombineCoins, CombineCoinsResponse, + CRCATApprovePending, + CRCATApprovePendingResponse, CreateNewDL, CreateNewDLResponse, CreateNewWallet, @@ -949,25 +949,17 @@ async def vc_revoke( async def crcat_approve_pending( self, - wallet_id: uint32, - min_amount_to_claim: uint64, + request: CRCATApprovePending, tx_config: TXConfig, - fee: uint64 = uint64(0), - push: bool = True, + extra_conditions: tuple[Condition, ...] = tuple(), timelock_info: ConditionValidTimes = ConditionValidTimes(), - ) -> list[TransactionRecord]: - response = await self.fetch( - "crcat_approve_pending", - { - "wallet_id": wallet_id, - "min_amount_to_claim": min_amount_to_claim, - "fee": fee, - "push": push, - **tx_config.to_json_dict(), - **timelock_info.to_json_dict(), - }, + ) -> CRCATApprovePendingResponse: + return CRCATApprovePendingResponse.from_json_dict( + await self.fetch( + "crcat_approve_pending", + request.json_serialize_for_transport(tx_config, extra_conditions, timelock_info), + ) ) - return [TransactionRecord.from_json_dict(tx) for tx in response["transactions"]] async def gather_signing_info( self,