|
45 | 45 | from chia.wallet.vc_wallet.vc_store import VCProofs
|
46 | 46 | from chia.wallet.wallet_coin_store import GetCoinRecords
|
47 | 47 | from chia.wallet.wallet_request_types import (
|
| 48 | + CATAssetIDToName, |
| 49 | + CATAssetIDToNameResponse, |
| 50 | + CATGetName, |
| 51 | + CATSetName, |
48 | 52 | CATSpendResponse,
|
49 | 53 | ClawbackPuzzleDecoratorOverride,
|
50 | 54 | DeleteNotifications,
|
|
92 | 96 | )
|
93 | 97 | from chia.wallet.wallet_rpc_client import WalletRpcClient
|
94 | 98 |
|
95 |
| -CATNameResolver = Callable[[bytes32], Awaitable[Optional[tuple[Optional[uint32], str]]]] |
| 99 | +CATNameResolver = Callable[[CATAssetIDToName], Awaitable[CATAssetIDToNameResponse]] |
96 | 100 |
|
97 | 101 | transaction_type_descriptions = {
|
98 | 102 | TransactionType.INCOMING_TX: "received",
|
@@ -184,7 +188,7 @@ async def get_unit_name_for_wallet_id(
|
184 | 188 | }:
|
185 | 189 | name: str = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"].upper()
|
186 | 190 | elif wallet_type in {WalletType.CAT, WalletType.CRCAT, WalletType.RCAT}:
|
187 |
| - name = await wallet_client.get_cat_name(wallet_id=wallet_id) |
| 191 | + name = (await wallet_client.get_cat_name(CATGetName(wallet_id=uint32(wallet_id)))).name |
188 | 192 | else:
|
189 | 193 | raise LookupError(f"Operation is not supported for Wallet type {wallet_type.name}")
|
190 | 194 |
|
@@ -469,21 +473,19 @@ async def add_token(
|
469 | 473 | root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], asset_id: bytes32, token_name: str
|
470 | 474 | ) -> None:
|
471 | 475 | async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _):
|
472 |
| - existing_info: Optional[tuple[Optional[uint32], str]] = await wallet_client.cat_asset_id_to_name(asset_id) |
473 |
| - if existing_info is None: |
474 |
| - wallet_id = None |
475 |
| - old_name = None |
476 |
| - else: |
477 |
| - wallet_id, old_name = existing_info |
| 476 | + existing_info = await wallet_client.cat_asset_id_to_name(CATAssetIDToName(asset_id)) |
478 | 477 |
|
479 |
| - if wallet_id is None: |
| 478 | + if existing_info.wallet_id is None: |
480 | 479 | response = await wallet_client.create_wallet_for_existing_cat(asset_id)
|
481 | 480 | wallet_id = response["wallet_id"]
|
482 |
| - await wallet_client.set_cat_name(wallet_id, token_name) |
| 481 | + await wallet_client.set_cat_name(CATSetName(wallet_id, token_name)) |
483 | 482 | print(f"Successfully added {token_name} with wallet id {wallet_id} on key {fingerprint}")
|
484 | 483 | else:
|
485 |
| - await wallet_client.set_cat_name(wallet_id, token_name) |
486 |
| - print(f"Successfully renamed {old_name} with wallet_id {wallet_id} on key {fingerprint} to {token_name}") |
| 484 | + await wallet_client.set_cat_name(CATSetName(existing_info.wallet_id, token_name)) |
| 485 | + print( |
| 486 | + f"Successfully renamed {existing_info.name} with wallet_id {existing_info.wallet_id}" |
| 487 | + f" on key {fingerprint} to {token_name}" |
| 488 | + ) |
487 | 489 |
|
488 | 490 |
|
489 | 491 | async def make_offer(
|
@@ -512,9 +514,9 @@ async def make_offer(
|
512 | 514 | try:
|
513 | 515 | b32_id = bytes32.from_hexstr(name)
|
514 | 516 | id: Union[uint32, str] = b32_id.hex()
|
515 |
| - result = await wallet_client.cat_asset_id_to_name(b32_id) |
516 |
| - if result is not None: |
517 |
| - name = result[1] |
| 517 | + result = await wallet_client.cat_asset_id_to_name(CATAssetIDToName(b32_id)) |
| 518 | + if result.name is not None: |
| 519 | + name = result.name |
518 | 520 | else:
|
519 | 521 | name = "Unknown CAT"
|
520 | 522 | unit = units["cat"]
|
@@ -570,7 +572,7 @@ async def make_offer(
|
570 | 572 | name = "XCH"
|
571 | 573 | unit = units["chia"]
|
572 | 574 | else:
|
573 |
| - name = await wallet_client.get_cat_name(id) |
| 575 | + name = (await wallet_client.get_cat_name(CATGetName(id))).name |
574 | 576 | unit = units["cat"]
|
575 | 577 | if item in offers:
|
576 | 578 | fungible_assets.append(FungibleAsset(name, uint64(abs(int(Decimal(amount) * unit)))))
|
@@ -678,10 +680,10 @@ async def print_offer_summary(
|
678 | 680 | description = " [Typically represents change returned from the included fee]"
|
679 | 681 | else:
|
680 | 682 | unit = units["cat"]
|
681 |
| - result = await cat_name_resolver(bytes32.from_hexstr(asset_id)) |
682 |
| - if result is not None: |
683 |
| - wid = str(result[0]) |
684 |
| - name = result[1] |
| 683 | + result = await cat_name_resolver(CATAssetIDToName(bytes32.from_hexstr(asset_id))) |
| 684 | + if result.name is not None: |
| 685 | + wid = str(result.wallet_id) |
| 686 | + name = result.name |
685 | 687 | output: str = f" - {name}"
|
686 | 688 | mojo_str: str = f"{mojo_amount} {'mojo' if mojo_amount == 1 else 'mojos'}"
|
687 | 689 | if len(wid) > 0:
|
@@ -844,9 +846,9 @@ async def take_offer(
|
844 | 846 | if fungible_asset_id is None:
|
845 | 847 | nft_royalty_currency = network_xch
|
846 | 848 | else:
|
847 |
| - result = await wallet_client.cat_asset_id_to_name(fungible_asset_id) |
848 |
| - if result is not None: |
849 |
| - nft_royalty_currency = result[1] |
| 849 | + result = await wallet_client.cat_asset_id_to_name(CATAssetIDToName(fungible_asset_id)) |
| 850 | + if result.name is not None: |
| 851 | + nft_royalty_currency = result.name |
850 | 852 | fungible_assets.append(
|
851 | 853 | FungibleAsset(nft_royalty_currency, uint64(requested[fungible_asset_id_str]))
|
852 | 854 | )
|
|
0 commit comments