Skip to content

Commit 0ab252e

Browse files
committed
Port cat_set_name
1 parent 6f0ce10 commit 0ab252e

File tree

6 files changed

+34
-16
lines changed

6 files changed

+34
-16
lines changed

chia/_tests/cmds/wallet/test_wallet.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
from chia.wallet.wallet_request_types import (
4444
BalanceResponse,
4545
CancelOfferResponse,
46+
CATSetName,
47+
CATSetNameResponse,
4648
CATSpendResponse,
4749
ClawbackPuzzleDecoratorOverride,
4850
CreateOfferForIDsResponse,
@@ -683,8 +685,9 @@ async def create_wallet_for_existing_cat(self, asset_id: bytes) -> dict[str, int
683685
self.add_to_log("create_wallet_for_existing_cat", (asset_id,))
684686
return {"wallet_id": 3}
685687

686-
async def set_cat_name(self, wallet_id: int, name: str) -> None:
687-
self.add_to_log("set_cat_name", (wallet_id, name))
688+
async def set_cat_name(self, request: CATSetName) -> CATSetNameResponse:
689+
self.add_to_log("set_cat_name", (request.wallet_id, request.name))
690+
return CATSetNameResponse(wallet_id=request.wallet_id)
688691

689692
inst_rpc_client = AddTokenRpcClient()
690693
test_rpc_clients.wallet_rpc_client = inst_rpc_client

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+
CATSetName,
107108
CheckDeleteKey,
108109
ClawbackPuzzleDecoratorOverride,
109110
CombineCoins,
@@ -1207,7 +1208,7 @@ async def test_cat_endpoints(wallet_environments: WalletTestFramework, wallet_ty
12071208
assert (await env_0.rpc_client.get_cat_name(cat_0_id)) == wallet_type.default_wallet_name_for_unknown_cat(
12081209
asset_id.hex()
12091210
)
1210-
await env_0.rpc_client.set_cat_name(cat_0_id, "My cat")
1211+
await env_0.rpc_client.set_cat_name(CATSetName(cat_0_id, "My cat"))
12111212
assert (await env_0.rpc_client.get_cat_name(cat_0_id)) == "My cat"
12121213
result = await env_0.rpc_client.cat_asset_id_to_name(asset_id)
12131214
assert result is not None

chia/cmds/wallet_funcs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from chia.wallet.vc_wallet.vc_store import VCProofs
4646
from chia.wallet.wallet_coin_store import GetCoinRecords
4747
from chia.wallet.wallet_request_types import (
48+
CATSetName,
4849
CATSpendResponse,
4950
ClawbackPuzzleDecoratorOverride,
5051
DeleteNotifications,
@@ -479,10 +480,10 @@ async def add_token(
479480
if wallet_id is None:
480481
response = await wallet_client.create_wallet_for_existing_cat(asset_id)
481482
wallet_id = response["wallet_id"]
482-
await wallet_client.set_cat_name(wallet_id, token_name)
483+
await wallet_client.set_cat_name(CATSetName(wallet_id, token_name))
483484
print(f"Successfully added {token_name} with wallet id {wallet_id} on key {fingerprint}")
484485
else:
485-
await wallet_client.set_cat_name(wallet_id, token_name)
486+
await wallet_client.set_cat_name(CATSetName(wallet_id, token_name))
486487
print(f"Successfully renamed {old_name} with wallet_id {wallet_id} on key {fingerprint} to {token_name}")
487488

488489

chia/wallet/wallet_request_types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,19 @@ class GetCATListResponse(Streamable):
594594
cat_list: list[DefaultCAT]
595595

596596

597+
@streamable
598+
@dataclass(frozen=True)
599+
class CATSetName(Streamable):
600+
wallet_id: uint32
601+
name: str
602+
603+
604+
@streamable
605+
@dataclass(frozen=True)
606+
class CATSetNameResponse(Streamable):
607+
wallet_id: uint32
608+
609+
597610
@streamable
598611
@dataclass(frozen=True)
599612
class DIDSetWalletName(Streamable):

chia/wallet/wallet_rpc_api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
ApplySignatures,
113113
ApplySignaturesResponse,
114114
BalanceResponse,
115+
CATSetName,
116+
CATSetNameResponse,
115117
CheckDeleteKey,
116118
CheckDeleteKeyResponse,
117119
CombineCoins,
@@ -2098,11 +2100,11 @@ async def sign_message_by_id(self, request: SignMessageByID) -> SignMessageByIDR
20982100
async def get_cat_list(self, request: Empty) -> GetCATListResponse:
20992101
return GetCATListResponse([DefaultCAT.from_json_dict(default_cat) for default_cat in DEFAULT_CATS.values()])
21002102

2101-
async def cat_set_name(self, request: dict[str, Any]) -> EndpointResult:
2102-
wallet_id = uint32(request["wallet_id"])
2103-
wallet = self.service.wallet_state_manager.get_wallet(id=wallet_id, required_type=CATWallet)
2104-
await wallet.set_name(str(request["name"]))
2105-
return {"wallet_id": wallet_id}
2103+
@marshal
2104+
async def cat_set_name(self, request: CATSetName) -> CATSetNameResponse:
2105+
wallet = self.service.wallet_state_manager.get_wallet(id=request.wallet_id, required_type=CATWallet)
2106+
await wallet.set_name(request.name)
2107+
return CATSetNameResponse(wallet_id=request.wallet_id)
21062108

21072109
async def cat_get_name(self, request: dict[str, Any]) -> EndpointResult:
21082110
wallet_id = uint32(request["wallet_id"])

chia/wallet/wallet_rpc_client.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
ApplySignaturesResponse,
2525
CancelOfferResponse,
2626
CancelOffersResponse,
27+
CATSetName,
28+
CATSetNameResponse,
2729
CATSpendResponse,
2830
CheckDeleteKey,
2931
CheckDeleteKeyResponse,
@@ -649,12 +651,8 @@ async def get_cat_name(self, wallet_id: int) -> str:
649651
# TODO: casting due to lack of type checked deserialization
650652
return cast(str, response["name"])
651653

652-
async def set_cat_name(self, wallet_id: int, name: str) -> None:
653-
request: dict[str, Any] = {
654-
"wallet_id": wallet_id,
655-
"name": name,
656-
}
657-
await self.fetch("cat_set_name", request)
654+
async def set_cat_name(self, request: CATSetName) -> CATSetNameResponse:
655+
return CATSetNameResponse.from_json_dict(await self.fetch("cat_set_name", request.to_json_dict()))
658656

659657
async def cat_spend(
660658
self,

0 commit comments

Comments
 (0)