Skip to content

Commit f825503

Browse files
committed
Port cat_get_asset_id
1 parent 71b6971 commit f825503

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

chia/_tests/wallet/rpc/test_wallet_rpc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
from chia.wallet.wallet_protocol import WalletProtocol
105105
from chia.wallet.wallet_request_types import (
106106
AddKey,
107+
CATGetAssetID,
107108
CATGetName,
108109
CATSetName,
109110
CheckDeleteKey,
@@ -1205,7 +1206,7 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
12051206
env_0.wallet_states[uint32(env_0.wallet_aliases["cat0"])].balance.to_json_dict().items()
12061207
<= (await env_0.rpc_client.get_wallet_balance(GetWalletBalance(cat_0_id))).wallet_balance.to_json_dict().items()
12071208
)
1208-
asset_id = await env_0.rpc_client.get_cat_asset_id(cat_0_id)
1209+
asset_id = (await env_0.rpc_client.get_cat_asset_id(CATGetAssetID(cat_0_id))).asset_id
12091210
assert (
12101211
await env_0.rpc_client.get_cat_name(CATGetName(cat_0_id))
12111212
).name == wallet_type.default_wallet_name_for_unknown_cat(asset_id.hex())

chia/wallet/wallet_request_types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,19 @@ class GetStrayCATsResponse(Streamable):
635635
stray_cats: list[StrayCAT]
636636

637637

638+
@streamable
639+
@dataclass(frozen=True)
640+
class CATGetAssetID(Streamable):
641+
wallet_id: uint32
642+
643+
644+
@streamable
645+
@dataclass(frozen=True)
646+
class CATGetAssetIDResponse(Streamable):
647+
wallet_id: uint32
648+
asset_id: bytes32
649+
650+
638651
@streamable
639652
@dataclass(frozen=True)
640653
class DIDSetWalletName(Streamable):

chia/wallet/wallet_rpc_api.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
ApplySignatures,
113113
ApplySignaturesResponse,
114114
BalanceResponse,
115+
CATGetAssetID,
116+
CATGetAssetIDResponse,
115117
CATGetName,
116118
CATGetNameResponse,
117119
CATSetName,
@@ -2215,11 +2217,11 @@ async def cat_spend(
22152217
"transaction_id": None, # tx_endpoint wrapper will take care of this
22162218
}
22172219

2218-
async def cat_get_asset_id(self, request: dict[str, Any]) -> EndpointResult:
2219-
wallet_id = uint32(request["wallet_id"])
2220-
wallet = self.service.wallet_state_manager.get_wallet(id=wallet_id, required_type=CATWallet)
2220+
@marshal
2221+
async def cat_get_asset_id(self, request: CATGetAssetID) -> CATGetAssetIDResponse:
2222+
wallet = self.service.wallet_state_manager.get_wallet(id=request.wallet_id, required_type=CATWallet)
22212223
asset_id: str = wallet.get_asset_id()
2222-
return {"asset_id": asset_id, "wallet_id": wallet_id}
2224+
return CATGetAssetIDResponse(asset_id=bytes32.from_hexstr(asset_id), wallet_id=request.wallet_id)
22232225

22242226
async def cat_asset_id_to_name(self, request: dict[str, Any]) -> EndpointResult:
22252227
wallet = await self.service.wallet_state_manager.get_wallet_for_asset_id(request["asset_id"])

chia/wallet/wallet_rpc_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
ApplySignaturesResponse,
2525
CancelOfferResponse,
2626
CancelOffersResponse,
27+
CATGetAssetID,
28+
CATGetAssetIDResponse,
2729
CATGetName,
2830
CATGetNameResponse,
2931
CATSetName,
@@ -629,9 +631,8 @@ async def create_wallet_for_existing_cat(self, asset_id: bytes) -> dict[str, Any
629631
request = {"wallet_type": "cat_wallet", "asset_id": asset_id.hex(), "mode": "existing"}
630632
return await self.fetch("create_new_wallet", request)
631633

632-
async def get_cat_asset_id(self, wallet_id: int) -> bytes32:
633-
request = {"wallet_id": wallet_id}
634-
return bytes32.from_hexstr((await self.fetch("cat_get_asset_id", request))["asset_id"])
634+
async def get_cat_asset_id(self, request: CATGetAssetID) -> CATGetAssetIDResponse:
635+
return CATGetAssetIDResponse.from_json_dict(await self.fetch("cat_get_asset_id", request.to_json_dict()))
635636

636637
async def get_stray_cats(self) -> GetStrayCATsResponse:
637638
return GetStrayCATsResponse.from_json_dict(await self.fetch("get_stray_cats", {}))

0 commit comments

Comments
 (0)