Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions chia/_tests/cmds/wallet/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
24 changes: 13 additions & 11 deletions chia/_tests/wallet/cat_wallet/test_trades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down
7 changes: 4 additions & 3 deletions chia/_tests/wallet/vc_wallet/test_vc_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from chia.wallet.wallet_request_types import (
Addition,
CATSpend,
CRCATApprovePending,
CreateSignedTransaction,
GetTransactions,
GetWallets,
Expand Down Expand Up @@ -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(
[
Expand Down
29 changes: 17 additions & 12 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
CATSpend,
CATSpendResponse,
ClawbackPuzzleDecoratorOverride,
CRCATApprovePending,
CreateNewWallet,
CreateNewWalletType,
CreateOfferForIDs,
Expand Down Expand Up @@ -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!")
Expand Down
13 changes: 13 additions & 0 deletions chia/wallet/wallet_request_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 11 additions & 17 deletions chia/wallet/wallet_rpc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,6 +129,8 @@
CheckOfferValidityResponse,
CombineCoins,
CombineCoinsResponse,
CRCATApprovePending,
CRCATApprovePendingResponse,
CreateNewDL,
CreateNewDLResponse,
CreateNewWallet,
Expand Down Expand Up @@ -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).
Expand All @@ -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(
Expand Down
28 changes: 10 additions & 18 deletions chia/wallet/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -37,6 +35,8 @@
CheckOfferValidityResponse,
CombineCoins,
CombineCoinsResponse,
CRCATApprovePending,
CRCATApprovePendingResponse,
CreateNewDL,
CreateNewDLResponse,
CreateNewWallet,
Expand Down Expand Up @@ -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,
Expand Down
Loading