Skip to content

Commit 0838b7d

Browse files
committed
Port get_stray_cats
1 parent 57b71c9 commit 0838b7d

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,8 +1397,8 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
13971397
await env_0.wallet_state_manager.interested_store.add_unacknowledged_token(
13981398
asset_id, "Unknown", uint32(10000), bytes32(b"\00" * 32)
13991399
)
1400-
cats = await env_0.rpc_client.get_stray_cats()
1401-
assert len(cats) == 1
1400+
stray_cats_response = await env_0.rpc_client.get_stray_cats()
1401+
assert len(stray_cats_response.stray_cats) == 1
14021402

14031403
# Test CAT coin selection
14041404
select_coins_response = await env_0.rpc_client.select_coins(

chia/wallet/wallet_request_types.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,21 @@ class CATGetNameResponse(Streamable):
620620
name: str
621621

622622

623+
@streamable
624+
@dataclass(frozen=True)
625+
class StrayCAT(Streamable):
626+
asset_id: bytes32
627+
name: str
628+
first_seen_height: uint32
629+
sender_puzzle_hash: bytes32
630+
631+
632+
@streamable
633+
@dataclass(frozen=True)
634+
class GetStrayCATsResponse(Streamable):
635+
stray_cats: list[StrayCAT]
636+
637+
623638
@streamable
624639
@dataclass(frozen=True)
625640
class DIDSetWalletName(Streamable):

chia/wallet/wallet_rpc_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
GetPublicKeysResponse,
194194
GetSpendableCoins,
195195
GetSpendableCoinsResponse,
196+
GetStrayCATsResponse,
196197
GetSyncStatusResponse,
197198
GetTimestampForHeight,
198199
GetTimestampForHeightResponse,
@@ -267,6 +268,7 @@
267268
SpendClawbackCoinsResponse,
268269
SplitCoins,
269270
SplitCoinsResponse,
271+
StrayCAT,
270272
SubmitTransactions,
271273
SubmitTransactionsResponse,
272274
TransactionRecordWithMetadata,
@@ -2117,14 +2119,15 @@ async def cat_get_name(self, request: CATGetName) -> CATGetNameResponse:
21172119
name: str = wallet.get_name()
21182120
return CATGetNameResponse(wallet_id=request.wallet_id, name=name)
21192121

2120-
async def get_stray_cats(self, request: dict[str, Any]) -> EndpointResult:
2122+
@marshal
2123+
async def get_stray_cats(self, request: Empty) -> GetStrayCATsResponse:
21212124
"""
21222125
Get a list of all unacknowledged CATs
21232126
:param request: RPC request
21242127
:return: A list of unacknowledged CATs
21252128
"""
21262129
cats = await self.service.wallet_state_manager.interested_store.get_unacknowledged_tokens()
2127-
return {"stray_cats": cats}
2130+
return GetStrayCATsResponse(stray_cats=[StrayCAT.from_json_dict(cat) for cat in cats])
21282131

21292132
@tx_endpoint(push=True)
21302133
async def cat_spend(

chia/wallet/wallet_rpc_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from typing import Any, Optional, Union, cast
3+
from typing import Any, Optional, Union
44

55
from chia_rs.sized_bytes import bytes32
66
from chia_rs.sized_ints import uint32, uint64
@@ -106,6 +106,7 @@
106106
GetPublicKeysResponse,
107107
GetSpendableCoins,
108108
GetSpendableCoinsResponse,
109+
GetStrayCATsResponse,
109110
GetSyncStatusResponse,
110111
GetTimestampForHeight,
111112
GetTimestampForHeightResponse,
@@ -632,10 +633,8 @@ async def get_cat_asset_id(self, wallet_id: int) -> bytes32:
632633
request = {"wallet_id": wallet_id}
633634
return bytes32.from_hexstr((await self.fetch("cat_get_asset_id", request))["asset_id"])
634635

635-
async def get_stray_cats(self) -> list[dict[str, Any]]:
636-
response = await self.fetch("get_stray_cats", {})
637-
# TODO: casting due to lack of type checked deserialization
638-
return cast(list[dict[str, Any]], response["stray_cats"])
636+
async def get_stray_cats(self) -> GetStrayCATsResponse:
637+
return GetStrayCATsResponse.from_json_dict(await self.fetch("get_stray_cats", {}))
639638

640639
async def cat_asset_id_to_name(self, asset_id: bytes32) -> Optional[tuple[Optional[uint32], str]]:
641640
request = {"asset_id": asset_id.hex()}

0 commit comments

Comments
 (0)