|
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, |
48 | 50 | CATGetName,
|
49 | 51 | CATSetName,
|
50 | 52 | CATSpendResponse,
|
|
94 | 96 | )
|
95 | 97 | from chia.wallet.wallet_rpc_client import WalletRpcClient
|
96 | 98 |
|
97 |
| -CATNameResolver = Callable[[bytes32], Awaitable[Optional[tuple[Optional[uint32], str]]]] |
| 99 | +CATNameResolver = Callable[[CATAssetIDToName], Awaitable[CATAssetIDToNameResponse]] |
98 | 100 |
|
99 | 101 | transaction_type_descriptions = {
|
100 | 102 | TransactionType.INCOMING_TX: "received",
|
@@ -471,21 +473,19 @@ async def add_token(
|
471 | 473 | root_path: pathlib.Path, wallet_rpc_port: Optional[int], fp: Optional[int], asset_id: bytes32, token_name: str
|
472 | 474 | ) -> None:
|
473 | 475 | async with get_wallet_client(root_path, wallet_rpc_port, fp) as (wallet_client, fingerprint, _):
|
474 |
| - existing_info: Optional[tuple[Optional[uint32], str]] = await wallet_client.cat_asset_id_to_name(asset_id) |
475 |
| - if existing_info is None: |
476 |
| - wallet_id = None |
477 |
| - old_name = None |
478 |
| - else: |
479 |
| - wallet_id, old_name = existing_info |
| 476 | + existing_info = await wallet_client.cat_asset_id_to_name(CATAssetIDToName(asset_id)) |
480 | 477 |
|
481 |
| - if wallet_id is None: |
| 478 | + if existing_info.wallet_id is None: |
482 | 479 | response = await wallet_client.create_wallet_for_existing_cat(asset_id)
|
483 | 480 | wallet_id = response["wallet_id"]
|
484 | 481 | await wallet_client.set_cat_name(CATSetName(wallet_id, token_name))
|
485 | 482 | print(f"Successfully added {token_name} with wallet id {wallet_id} on key {fingerprint}")
|
486 | 483 | else:
|
487 |
| - await wallet_client.set_cat_name(CATSetName(wallet_id, token_name)) |
488 |
| - 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 | + ) |
489 | 489 |
|
490 | 490 |
|
491 | 491 | async def make_offer(
|
@@ -514,9 +514,9 @@ async def make_offer(
|
514 | 514 | try:
|
515 | 515 | b32_id = bytes32.from_hexstr(name)
|
516 | 516 | id: Union[uint32, str] = b32_id.hex()
|
517 |
| - result = await wallet_client.cat_asset_id_to_name(b32_id) |
518 |
| - if result is not None: |
519 |
| - 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 |
520 | 520 | else:
|
521 | 521 | name = "Unknown CAT"
|
522 | 522 | unit = units["cat"]
|
@@ -680,10 +680,10 @@ async def print_offer_summary(
|
680 | 680 | description = " [Typically represents change returned from the included fee]"
|
681 | 681 | else:
|
682 | 682 | unit = units["cat"]
|
683 |
| - result = await cat_name_resolver(bytes32.from_hexstr(asset_id)) |
684 |
| - if result is not None: |
685 |
| - wid = str(result[0]) |
686 |
| - 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 |
687 | 687 | output: str = f" - {name}"
|
688 | 688 | mojo_str: str = f"{mojo_amount} {'mojo' if mojo_amount == 1 else 'mojos'}"
|
689 | 689 | if len(wid) > 0:
|
@@ -846,9 +846,9 @@ async def take_offer(
|
846 | 846 | if fungible_asset_id is None:
|
847 | 847 | nft_royalty_currency = network_xch
|
848 | 848 | else:
|
849 |
| - result = await wallet_client.cat_asset_id_to_name(fungible_asset_id) |
850 |
| - if result is not None: |
851 |
| - 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 |
852 | 852 | fungible_assets.append(
|
853 | 853 | FungibleAsset(nft_royalty_currency, uint64(requested[fungible_asset_id_str]))
|
854 | 854 | )
|
|
0 commit comments