Compare commits

...

8 Commits

Author SHA1 Message Date
Jack Nelson 063cc8ee99
Enable mypy on almost every cli file. 2023-07-03 22:57:41 -04:00
Jack Nelson c8ebdc4929
Merge branch 'main' into jn.finish-cli-changes
# Conflicts:
#	chia/cmds/wallet_funcs.py
2023-06-29 02:36:45 -04:00
Jack Nelson f729840202
remove execute_with_wallet func 2023-06-29 02:12:22 -04:00
Jack Nelson 516bb59c7e
change to 100% new async generator 2023-06-29 02:12:10 -04:00
Jack Nelson 237ae7292e
remove extra imports 2023-06-28 13:28:50 -04:00
Jack Nelson ff96d76bcb
change coin commands over to new generator 2023-06-28 13:28:49 -04:00
Jack Nelson 13b053bde4
switch plotnft code to new generator 2023-06-28 13:28:49 -04:00
Jack Nelson f9073eef92
add new get_wallet_client generator 2023-06-28 13:28:48 -04:00
11 changed files with 1860 additions and 1789 deletions

View File

@ -4,7 +4,7 @@ import logging
import traceback
from contextlib import asynccontextmanager
from pathlib import Path
from typing import Any, AsyncIterator, Awaitable, Callable, Dict, List, Optional, Tuple, Type, TypeVar
from typing import Any, AsyncIterator, Dict, List, Optional, Tuple, Type, TypeVar
from aiohttp import ClientConnectorError
@ -42,7 +42,6 @@ node_config_section_names: Dict[Type[RpcClient], str] = {
SimulatorFullNodeRpcClient: "full_node",
}
_T_RpcClient = TypeVar("_T_RpcClient", bound=RpcClient)
@ -207,18 +206,18 @@ async def get_wallet(root_path: Path, wallet_client: WalletRpcClient, fingerprin
return selected_fingerprint
async def execute_with_wallet(
@asynccontextmanager
async def get_wallet_client(
wallet_rpc_port: Optional[int],
fingerprint: int,
extra_params: Dict[str, Any],
function: Callable[[Dict[str, Any], WalletRpcClient, int], Awaitable[None]],
) -> None:
async with get_any_service_client(WalletRpcClient, wallet_rpc_port) as (wallet_client, _):
fingerprint: Optional[int] = None,
root_path: Path = DEFAULT_ROOT_PATH,
) -> AsyncIterator[Tuple[Optional[WalletRpcClient], int, Dict[str, Any]]]:
async with get_any_service_client(WalletRpcClient, wallet_rpc_port, root_path) as (wallet_client, config):
if wallet_client is None:
return
new_fp = await get_wallet(DEFAULT_ROOT_PATH, wallet_client, fingerprint)
if new_fp is None:
return
await function(extra_params, wallet_client, new_fp)
yield None, 0, config
else:
new_fp = await get_wallet(root_path, wallet_client, fingerprint)
if new_fp is None:
yield None, 0, config
else:
yield wallet_client, new_fp, config

View File

@ -2,79 +2,88 @@ from __future__ import annotations
import sys
from decimal import Decimal
from typing import Any, Dict, List, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union
from chia.cmds.cmds_util import get_wallet_client
from chia.cmds.units import units
from chia.cmds.wallet_funcs import get_mojo_per_unit, get_wallet_type, print_balance
from chia.rpc.wallet_rpc_client import WalletRpcClient
from chia.types.blockchain_format.coin import Coin
from chia.types.blockchain_format.sized_bytes import bytes32
from chia.types.coin_record import CoinRecord
from chia.util.bech32m import decode_puzzle_hash, encode_puzzle_hash
from chia.util.config import selected_network_address_prefix
from chia.util.ints import uint64, uint128
from chia.wallet.transaction_record import TransactionRecord
from chia.wallet.util.wallet_types import WalletType
async def async_list(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id: int = args["id"]
min_coin_amount = Decimal(args["min_coin_amount"])
max_coin_amount = Decimal(args["max_coin_amount"])
excluded_coin_ids = args["excluded_coin_ids"]
excluded_amounts = args["excluded_amounts"]
addr_prefix = args["addr_prefix"]
show_unconfirmed = args["show_unconfirmed"]
paginate = args["paginate"]
if paginate is None:
paginate = sys.stdout.isatty()
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
final_min_coin_amount: uint64 = uint64(int(min_coin_amount * mojo_per_unit))
final_max_coin_amount: uint64 = uint64(int(max_coin_amount * mojo_per_unit))
final_excluded_amounts: List[uint64] = [uint64(int(Decimal(amount) * mojo_per_unit)) for amount in excluded_amounts]
conf_coins, unconfirmed_removals, unconfirmed_additions = await wallet_client.get_spendable_coins(
wallet_id=wallet_id,
max_coin_amount=final_max_coin_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts,
excluded_coin_ids=excluded_coin_ids,
)
print(f"There are a total of {len(conf_coins) + len(unconfirmed_additions)} coins in wallet {wallet_id}.")
print(f"{len(conf_coins)} confirmed coins.")
print(f"{len(unconfirmed_additions)} unconfirmed additions.")
print(f"{len(unconfirmed_removals)} unconfirmed removals.")
print("Confirmed coins:")
print_coins(
"\tAddress: {} Amount: {}, Confirmed in block: {}\n",
[(cr.coin, str(cr.confirmed_block_index)) for cr in conf_coins],
mojo_per_unit,
addr_prefix,
paginate,
)
if show_unconfirmed:
print("\nUnconfirmed Removals:")
async def async_list(
wallet_rpc_port: Optional[int],
fingerprint: Optional[int],
wallet_id: int,
max_coin_amount: Decimal,
min_coin_amount: Decimal,
excluded_amounts: list[int],
excluded_coin_ids: List[str],
show_unconfirmed: bool,
paginate: Optional[bool],
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, _, config):
if wallet_client is None:
return
addr_prefix = selected_network_address_prefix(config)
if paginate is None:
paginate = sys.stdout.isatty()
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
final_min_coin_amount: uint64 = uint64(int(min_coin_amount * mojo_per_unit))
final_max_coin_amount: uint64 = uint64(int(max_coin_amount * mojo_per_unit))
final_excluded_amounts: List[uint64] = [
uint64(int(Decimal(amount) * mojo_per_unit)) for amount in excluded_amounts
]
conf_coins, unconfirmed_removals, unconfirmed_additions = await wallet_client.get_spendable_coins(
wallet_id=wallet_id,
max_coin_amount=final_max_coin_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts,
excluded_coin_ids=excluded_coin_ids,
)
print(f"There are a total of {len(conf_coins) + len(unconfirmed_additions)} coins in wallet {wallet_id}.")
print(f"{len(conf_coins)} confirmed coins.")
print(f"{len(unconfirmed_additions)} unconfirmed additions.")
print(f"{len(unconfirmed_removals)} unconfirmed removals.")
print("Confirmed coins:")
print_coins(
"\tPrevious Address: {} Amount: {}, Confirmed in block: {}\n",
[(cr.coin, str(cr.confirmed_block_index)) for cr in unconfirmed_removals],
mojo_per_unit,
addr_prefix,
paginate,
)
print("\nUnconfirmed Additions:")
print_coins(
"\tNew Address: {} Amount: {}, Not yet confirmed in a block.{}\n",
[(coin, "") for coin in unconfirmed_additions],
"\tAddress: {} Amount: {}, Confirmed in block: {}\n",
[(cr.coin, str(cr.confirmed_block_index)) for cr in conf_coins],
mojo_per_unit,
addr_prefix,
paginate,
)
if show_unconfirmed:
print("\nUnconfirmed Removals:")
print_coins(
"\tPrevious Address: {} Amount: {}, Confirmed in block: {}\n",
[(cr.coin, str(cr.confirmed_block_index)) for cr in unconfirmed_removals],
mojo_per_unit,
addr_prefix,
paginate,
)
print("\nUnconfirmed Additions:")
print_coins(
"\tNew Address: {} Amount: {}, Not yet confirmed in a block.{}\n",
[(coin, "") for coin in unconfirmed_additions],
mojo_per_unit,
addr_prefix,
paginate,
)
def print_coins(
@ -105,120 +114,138 @@ def print_coins(
break
async def async_combine(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id: int = args["id"]
min_coin_amount = Decimal(args["min_coin_amount"])
excluded_amounts = args["excluded_amounts"]
number_of_coins = args["number_of_coins"]
max_amount = Decimal(args["max_amount"])
target_coin_amount = Decimal(args["target_coin_amount"])
target_coin_ids: List[bytes32] = [bytes32.from_hexstr(coin_id) for coin_id in args["target_coin_ids"]]
largest = bool(args["largest"])
final_fee = uint64(int(Decimal(args["fee"]) * units["chia"]))
if number_of_coins > 500:
raise ValueError(f"{number_of_coins} coins is greater then the maximum limit of 500 coins.")
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
is_xch: bool = wallet_type == WalletType.STANDARD_WALLET # this lets us know if we are directly combining Chia
final_max_amount = uint64(int(max_amount * mojo_per_unit)) if not target_coin_ids else uint64(0)
final_min_coin_amount: uint64 = uint64(int(min_coin_amount * mojo_per_unit))
final_excluded_amounts: List[uint64] = [uint64(int(Decimal(amount) * mojo_per_unit)) for amount in excluded_amounts]
final_target_coin_amount = uint64(int(target_coin_amount * mojo_per_unit))
if final_target_coin_amount != 0: # if we have a set target, just use standard coin selection.
removals: List[Coin] = await wallet_client.select_coins(
amount=(final_target_coin_amount + final_fee) if is_xch else final_target_coin_amount,
wallet_id=wallet_id,
max_coin_amount=final_max_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts + [final_target_coin_amount], # dont reuse coins of same amount.
)
else:
conf_coins, _, _ = await wallet_client.get_spendable_coins(
wallet_id=wallet_id,
max_coin_amount=final_max_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts,
)
if len(target_coin_ids) > 0:
conf_coins = [cr for cr in conf_coins if cr.name in target_coin_ids]
if len(conf_coins) == 0:
print("No coins to combine.")
async def async_combine(
wallet_rpc_port: Optional[int],
fingerprint: Optional[int],
wallet_id: int,
fee: Decimal,
max_coin_amount: Decimal,
min_coin_amount: Decimal,
excluded_amounts: list[str],
number_of_coins: int,
target_coin_amount: Decimal,
target_coin_ids_str: List[str],
largest_first: bool,
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config):
if wallet_client is None:
return
if len(conf_coins) == 1:
print("Only one coin found, you need at least two coins to combine.")
target_coin_ids: List[bytes32] = [bytes32.from_hexstr(coin_id) for coin_id in target_coin_ids_str]
final_fee = uint64(int(fee * units["chia"]))
if number_of_coins > 500:
raise ValueError(f"{number_of_coins} coins is greater then the maximum limit of 500 coins.")
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if largest:
conf_coins.sort(key=lambda r: r.coin.amount, reverse=True)
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
is_xch: bool = wallet_type == WalletType.STANDARD_WALLET # this lets us know if we are directly combining Chia
final_max_amount = uint64(int(max_coin_amount * mojo_per_unit)) if not target_coin_ids else uint64(0)
final_min_coin_amount: uint64 = uint64(int(min_coin_amount * mojo_per_unit))
final_excluded_amounts: List[uint64] = [
uint64(int(Decimal(amount) * mojo_per_unit)) for amount in excluded_amounts
]
final_target_coin_amount = uint64(int(target_coin_amount * mojo_per_unit))
if final_target_coin_amount != 0: # if we have a set target, just use standard coin selection.
removals: List[Coin] = await wallet_client.select_coins(
amount=(final_target_coin_amount + final_fee) if is_xch else final_target_coin_amount,
wallet_id=wallet_id,
max_coin_amount=final_max_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts
+ [final_target_coin_amount], # dont reuse coins of same amount.
)
else:
conf_coins.sort(key=lambda r: r.coin.amount) # sort the smallest first
if number_of_coins < len(conf_coins):
conf_coins = conf_coins[:number_of_coins]
removals = [cr.coin for cr in conf_coins]
print(f"Combining {len(removals)} coins.")
if input("Would you like to Continue? (y/n): ") != "y":
return
total_amount: uint128 = uint128(sum(coin.amount for coin in removals))
if is_xch and total_amount - final_fee <= 0:
print("Total amount is less than 0 after fee, exiting.")
return
target_ph: bytes32 = decode_puzzle_hash(await wallet_client.get_next_address(wallet_id, False))
additions = [{"amount": (total_amount - final_fee) if is_xch else total_amount, "puzzle_hash": target_ph}]
transaction: TransactionRecord = await wallet_client.send_transaction_multi(
wallet_id, additions, removals, final_fee
)
tx_id = transaction.name.hex()
print(f"Transaction sent: {tx_id}")
print(f"To get status, use command: chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}")
async def async_split(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id: int = args["id"]
number_of_coins = args["number_of_coins"]
final_fee = uint64(int(Decimal(args["fee"]) * units["chia"]))
# new args
amount_per_coin = Decimal(args["amount_per_coin"])
target_coin_id: bytes32 = bytes32.from_hexstr(args["target_coin_id"])
if number_of_coins > 500:
print(f"{number_of_coins} coins is greater then the maximum limit of 500 coins.")
return
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
is_xch: bool = wallet_type == WalletType.STANDARD_WALLET # this lets us know if we are directly spitting Chia
final_amount_per_coin = uint64(int(amount_per_coin * mojo_per_unit))
total_amount = final_amount_per_coin * number_of_coins
if is_xch:
total_amount += final_fee
# get full coin record from name, and validate information about it.
removal_coin_record: CoinRecord = (await wallet_client.get_coin_records_by_names([target_coin_id]))[0]
if removal_coin_record.coin.amount < total_amount:
print(
f"Coin amount: {removal_coin_record.coin.amount/ mojo_per_unit} "
f"is less than the total amount of the split: {total_amount/mojo_per_unit}, exiting."
conf_coins, _, _ = await wallet_client.get_spendable_coins(
wallet_id=wallet_id,
max_coin_amount=final_max_amount,
min_coin_amount=final_min_coin_amount,
excluded_amounts=final_excluded_amounts,
)
if len(target_coin_ids) > 0:
conf_coins = [cr for cr in conf_coins if cr.name in target_coin_ids]
if len(conf_coins) == 0:
print("No coins to combine.")
return
if len(conf_coins) == 1:
print("Only one coin found, you need at least two coins to combine.")
return
if largest_first:
conf_coins.sort(key=lambda r: r.coin.amount, reverse=True)
else:
conf_coins.sort(key=lambda r: r.coin.amount) # sort the smallest first
if number_of_coins < len(conf_coins):
conf_coins = conf_coins[:number_of_coins]
removals = [cr.coin for cr in conf_coins]
print(f"Combining {len(removals)} coins.")
if input("Would you like to Continue? (y/n): ") != "y":
return
total_amount: uint128 = uint128(sum(coin.amount for coin in removals))
if is_xch and total_amount - final_fee <= 0:
print("Total amount is less than 0 after fee, exiting.")
return
target_ph: bytes32 = decode_puzzle_hash(await wallet_client.get_next_address(wallet_id, False))
additions = [{"amount": (total_amount - final_fee) if is_xch else total_amount, "puzzle_hash": target_ph}]
transaction: TransactionRecord = await wallet_client.send_transaction_multi(
wallet_id, additions, removals, final_fee
)
print("Try using a smaller fee or amount.")
return
additions: List[Dict[str, Union[uint64, bytes32]]] = []
for i in range(number_of_coins): # for readability.
# we always use new addresses
target_ph: bytes32 = decode_puzzle_hash(await wallet_client.get_next_address(wallet_id, new_address=True))
additions.append({"amount": final_amount_per_coin, "puzzle_hash": target_ph})
transaction: TransactionRecord = await wallet_client.send_transaction_multi(
wallet_id, additions, [removal_coin_record.coin], final_fee
)
tx_id = transaction.name.hex()
print(f"Transaction sent: {tx_id}")
print(f"To get status, use command: chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}")
tx_id = transaction.name.hex()
print(f"Transaction sent: {tx_id}")
print(f"To get status, use command: chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}")
async def async_split(
wallet_rpc_port: Optional[int],
fingerprint: Optional[int],
wallet_id: int,
fee: Decimal,
number_of_coins: int,
amount_per_coin: Decimal,
target_coin_id_str: str,
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config):
if wallet_client is None:
return
final_fee = uint64(int(fee * units["chia"]))
target_coin_id: bytes32 = bytes32.from_hexstr(target_coin_id_str)
if number_of_coins > 500:
print(f"{number_of_coins} coins is greater then the maximum limit of 500 coins.")
return
try:
wallet_type = await get_wallet_type(wallet_id=wallet_id, wallet_client=wallet_client)
mojo_per_unit = get_mojo_per_unit(wallet_type)
except LookupError:
print(f"Wallet id: {wallet_id} not found.")
return
if not await wallet_client.get_synced():
print("Wallet not synced. Please wait.")
return
is_xch: bool = wallet_type == WalletType.STANDARD_WALLET # this lets us know if we are directly spitting Chia
final_amount_per_coin = uint64(int(amount_per_coin * mojo_per_unit))
total_amount = final_amount_per_coin * number_of_coins
if is_xch:
total_amount += final_fee
# get full coin record from name, and validate information about it.
removal_coin_record: CoinRecord = (await wallet_client.get_coin_records_by_names([target_coin_id]))[0]
if removal_coin_record.coin.amount < total_amount:
print(
f"Coin amount: {removal_coin_record.coin.amount / mojo_per_unit} "
f"is less than the total amount of the split: {total_amount / mojo_per_unit}, exiting."
)
print("Try using a smaller fee or amount.")
return
additions: List[Dict[str, Union[uint64, bytes32]]] = []
for i in range(number_of_coins): # for readability.
# we always use new addresses
target_ph: bytes32 = decode_puzzle_hash(await wallet_client.get_next_address(wallet_id, new_address=True))
additions.append({"amount": final_amount_per_coin, "puzzle_hash": target_ph})
transaction: TransactionRecord = await wallet_client.send_transaction_multi(
wallet_id, additions, [removal_coin_record.coin], final_fee
)
tx_id = transaction.name.hex()
print(f"Transaction sent: {tx_id}")
print(f"To get status, use command: chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}")

View File

@ -1,13 +1,11 @@
from __future__ import annotations
import asyncio
from decimal import Decimal
from typing import List, Optional
import click
from chia.cmds.cmds_util import execute_with_wallet
from chia.util.config import load_config, selected_network_address_prefix
@click.group("coins", help="Manage your wallets coins")
@click.pass_context
@ -68,21 +66,21 @@ def list_cmd(
amounts_to_exclude: List[int],
paginate: Optional[bool],
) -> None:
config = load_config(ctx.obj["root_path"], "config.yaml", "wallet")
address_prefix = selected_network_address_prefix(config)
extra_params = {
"id": id,
"max_coin_amount": max_amount,
"min_coin_amount": min_amount,
"excluded_amounts": amounts_to_exclude,
"excluded_coin_ids": coins_to_exclude,
"addr_prefix": address_prefix,
"show_unconfirmed": show_unconfirmed,
"paginate": paginate,
}
from .coin_funcs import async_list
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, async_list))
asyncio.run(
async_list(
wallet_rpc_port,
fingerprint,
id,
Decimal(max_amount),
Decimal(min_amount),
amounts_to_exclude,
coins_to_exclude,
show_unconfirmed,
paginate,
)
)
@coins_cmd.command("combine", help="Combine dust coins")
@ -156,27 +154,30 @@ def combine_cmd(
id: int,
target_amount: str,
min_amount: str,
amounts_to_exclude: List[int],
amounts_to_exclude: List[str],
number_of_coins: int,
max_amount: str,
fee: str,
input_coins: List[str],
largest_first: bool,
) -> None:
extra_params = {
"id": id,
"target_coin_amount": target_amount,
"min_coin_amount": min_amount,
"excluded_amounts": amounts_to_exclude,
"number_of_coins": number_of_coins,
"max_amount": max_amount,
"fee": fee,
"target_coin_ids": list(input_coins),
"largest": largest_first,
}
from .coin_funcs import async_combine
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, async_combine))
asyncio.run(
async_combine(
wallet_rpc_port,
fingerprint,
id,
Decimal(fee),
Decimal(max_amount),
Decimal(min_amount),
amounts_to_exclude,
number_of_coins,
Decimal(target_amount),
list(input_coins),
largest_first,
)
)
@coins_cmd.command("split", help="Split up larger coins")
@ -222,13 +223,10 @@ def split_cmd(
amount_per_coin: str,
target_coin_id: str,
) -> None:
extra_params = {
"id": id,
"number_of_coins": number_of_coins,
"fee": fee,
"amount_per_coin": amount_per_coin,
"target_coin_id": target_coin_id,
}
from .coin_funcs import async_split
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, async_split))
asyncio.run(
async_split(
wallet_rpc_port, fingerprint, id, Decimal(fee), number_of_coins, Decimal(amount_per_coin), target_coin_id
)
)

View File

@ -5,8 +5,6 @@ from typing import Optional
import click
from chia.cmds.cmds_util import execute_with_wallet
MAX_CMDLINE_FEE = Decimal(0.5)
@ -40,7 +38,7 @@ def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
from .plotnft_funcs import show
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, {"id": id}, show))
asyncio.run(show(wallet_rpc_port, fingerprint, id))
@plotnft_cmd.command("get_login_link", help="Create a login link for a pool. To get the launcher id, use plotnft show.")
@ -80,7 +78,7 @@ def create_cmd(
fingerprint: int,
pool_url: str,
state: str,
fee: int,
fee: str,
yes: bool,
) -> None:
import asyncio
@ -94,13 +92,7 @@ def create_cmd(
print(" pool_url argument (-u) is required for pool starting state")
return
valid_initial_states = {"pool": "FARMING_TO_POOL", "local": "SELF_POOLING"}
extra_params = {
"pool_url": pool_url,
"state": valid_initial_states[state],
"fee": fee,
"yes": yes,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, create))
asyncio.run(create(wallet_rpc_port, fingerprint, pool_url, valid_initial_states[state], Decimal(fee), yes))
@plotnft_cmd.command("join", help="Join a plot NFT to a Pool")
@ -130,8 +122,7 @@ def join_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int
from .plotnft_funcs import join_pool
extra_params = {"pool_url": pool_url, "id": id, "fee": fee, "yes": yes}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, join_pool))
asyncio.run(join_pool(wallet_rpc_port, fingerprint, pool_url, Decimal(fee), id, yes))
@plotnft_cmd.command("leave", help="Leave a pool and return to self-farming")
@ -160,8 +151,7 @@ def self_pool_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee
from .plotnft_funcs import self_pool
extra_params = {"id": id, "fee": fee, "yes": yes}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, self_pool))
asyncio.run(self_pool(wallet_rpc_port, fingerprint, Decimal(fee), id, yes))
@plotnft_cmd.command("inspect", help="Get Detailed plotnft information as JSON")
@ -179,8 +169,7 @@ def inspect(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
from .plotnft_funcs import inspect_cmd
extra_params = {"id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, inspect_cmd))
asyncio.run(inspect_cmd(wallet_rpc_port, fingerprint, id))
@plotnft_cmd.command("claim", help="Claim rewards from a plot NFT")
@ -208,8 +197,7 @@ def claim(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int) -
from .plotnft_funcs import claim_cmd
extra_params = {"id": id, "fee": fee}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, claim_cmd))
asyncio.run(claim_cmd(wallet_rpc_port, fingerprint, Decimal(fee), id))
@plotnft_cmd.command(

View File

@ -11,7 +11,12 @@ from typing import Any, Awaitable, Callable, Dict, List, Optional
import aiohttp
from chia.cmds.cmds_util import get_any_service_client, transaction_status_msg, transaction_submitted_msg
from chia.cmds.cmds_util import (
get_any_service_client,
get_wallet_client,
transaction_status_msg,
transaction_submitted_msg,
)
from chia.cmds.units import units
from chia.cmds.wallet_funcs import print_balance, wallet_coin_unit
from chia.pools.pool_config import PoolWalletConfig, load_pool_config, update_pool_config
@ -54,60 +59,65 @@ async def create_pool_args(pool_url: str) -> Dict[str, Any]:
return json_dict
async def create(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
state = args["state"]
prompt = not args.get("yes", False)
fee = Decimal(args.get("fee", 0))
fee_mojos = uint64(int(fee * units["chia"]))
target_puzzle_hash: Optional[bytes32]
# Could use initial_pool_state_from_dict to simplify
if state == "SELF_POOLING":
pool_url: Optional[str] = None
relative_lock_height = uint32(0)
target_puzzle_hash = None # wallet will fill this in
elif state == "FARMING_TO_POOL":
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
enforce_https = config["full_node"]["selected_network"] == "mainnet"
pool_url = str(args["pool_url"])
if enforce_https and not pool_url.startswith("https://"):
print(f"Pool URLs must be HTTPS on mainnet {pool_url}. Aborting.")
async def create(
wallet_rpc_port: Optional[int], fingerprint: int, pool_url: Optional[str], state: str, fee: Decimal, prompt: bool
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, _):
if wallet_client is None:
return None
fee_mojos = uint64(int(fee * units["chia"]))
target_puzzle_hash: Optional[bytes32]
# Could use initial_pool_state_from_dict to simplify
if state == "SELF_POOLING":
pool_url = None
relative_lock_height = uint32(0)
target_puzzle_hash = None # wallet will fill this in
elif state == "FARMING_TO_POOL":
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
enforce_https = config["full_node"]["selected_network"] == "mainnet"
assert pool_url is not None
if enforce_https and not pool_url.startswith("https://"):
print(f"Pool URLs must be HTTPS on mainnet {pool_url}. Aborting.")
return
assert pool_url is not None
json_dict = await create_pool_args(pool_url)
relative_lock_height = json_dict["relative_lock_height"]
target_puzzle_hash = bytes32.from_hexstr(json_dict["target_puzzle_hash"])
else:
raise ValueError("Plot NFT must be created in SELF_POOLING or FARMING_TO_POOL state.")
pool_msg = f" and join pool: {pool_url}" if pool_url else ""
print(f"Will create a plot NFT{pool_msg}.")
if prompt:
user_input: str = input("Confirm [n]/y: ")
else:
user_input = "yes"
if user_input.lower() == "y" or user_input.lower() == "yes":
try:
tx_record: TransactionRecord = await wallet_client.create_new_pool_wallet(
target_puzzle_hash,
pool_url,
relative_lock_height,
"localhost:5000",
"new",
state,
fee_mojos,
)
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(1, tx_record.name)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_record.name))
return None
except Exception as e:
print(
f"Error creating plot NFT: {e}\n Please start both farmer and wallet with: chia start -r farmer"
)
return
json_dict = await create_pool_args(pool_url)
relative_lock_height = json_dict["relative_lock_height"]
target_puzzle_hash = bytes32.from_hexstr(json_dict["target_puzzle_hash"])
else:
raise ValueError("Plot NFT must be created in SELF_POOLING or FARMING_TO_POOL state.")
pool_msg = f" and join pool: {pool_url}" if pool_url else ""
print(f"Will create a plot NFT{pool_msg}.")
if prompt:
user_input: str = input("Confirm [n]/y: ")
else:
user_input = "yes"
if user_input.lower() == "y" or user_input.lower() == "yes":
try:
tx_record: TransactionRecord = await wallet_client.create_new_pool_wallet(
target_puzzle_hash,
pool_url,
relative_lock_height,
"localhost:5000",
"new",
state,
fee_mojos,
)
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(1, tx_record.name)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_record.name))
return None
except Exception as e:
print(f"Error creating plot NFT: {e}\n Please start both farmer and wallet with: chia start -r farmer")
return
print("Aborting.")
print("Aborting.")
async def pprint_pool_wallet_state(
@ -172,51 +182,53 @@ async def pprint_pool_wallet_state(
print(f"Expected to leave after block height: {expected_leave_height}")
async def show(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
async def show(wallet_rpc_port: Optional[int], fp: Optional[int], wallet_id_passed_in: Optional[int]) -> None:
async with get_any_service_client(FarmerRpcClient) as (farmer_client, config):
if farmer_client is not None:
address_prefix = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"]
summaries_response = await wallet_client.get_wallets()
wallet_id_passed_in = args.get("id", None)
pool_state_list = (await farmer_client.get_pool_state())["pool_state"]
pool_state_dict: Dict[bytes32, Dict[str, Any]] = {
bytes32.from_hexstr(pool_state_item["pool_config"]["launcher_id"]): pool_state_item
for pool_state_item in pool_state_list
}
if wallet_id_passed_in is not None:
for summary in summaries_response:
typ = WalletType(int(summary["type"]))
if summary["id"] == wallet_id_passed_in and typ != WalletType.POOLING_WALLET:
print(
f"Wallet with id: {wallet_id_passed_in} is not a pooling wallet."
" Please provide a different id."
)
return
pool_wallet_info, _ = await wallet_client.pw_status(wallet_id_passed_in)
await pprint_pool_wallet_state(
wallet_client,
wallet_id_passed_in,
pool_wallet_info,
address_prefix,
pool_state_dict.get(pool_wallet_info.launcher_id),
)
else:
print(f"Wallet height: {await wallet_client.get_height_info()}")
print(f"Sync status: {'Synced' if (await wallet_client.get_synced()) else 'Not synced'}")
for summary in summaries_response:
wallet_id = summary["id"]
typ = WalletType(int(summary["type"]))
if typ == WalletType.POOLING_WALLET:
print(f"Wallet id {wallet_id}: ")
pool_wallet_info, _ = await wallet_client.pw_status(wallet_id)
await pprint_pool_wallet_state(
wallet_client,
wallet_id,
pool_wallet_info,
address_prefix,
pool_state_dict.get(pool_wallet_info.launcher_id),
)
print("")
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, _):
if wallet_client is None:
return
if farmer_client is not None:
address_prefix = config["network_overrides"]["config"][config["selected_network"]]["address_prefix"]
summaries_response = await wallet_client.get_wallets()
pool_state_list = (await farmer_client.get_pool_state())["pool_state"]
pool_state_dict: Dict[bytes32, Dict[str, Any]] = {
bytes32.from_hexstr(pool_state_item["pool_config"]["launcher_id"]): pool_state_item
for pool_state_item in pool_state_list
}
if wallet_id_passed_in is not None:
for summary in summaries_response:
typ = WalletType(int(summary["type"]))
if summary["id"] == wallet_id_passed_in and typ != WalletType.POOLING_WALLET:
print(
f"Wallet with id: {wallet_id_passed_in} is not a pooling wallet."
" Please provide a different id."
)
return
pool_wallet_info, _ = await wallet_client.pw_status(wallet_id_passed_in)
await pprint_pool_wallet_state(
wallet_client,
wallet_id_passed_in,
pool_wallet_info,
address_prefix,
pool_state_dict.get(pool_wallet_info.launcher_id),
)
else:
print(f"Wallet height: {await wallet_client.get_height_info()}")
print(f"Sync status: {'Synced' if (await wallet_client.get_synced()) else 'Not synced'}")
for summary in summaries_response:
wallet_id = summary["id"]
typ = WalletType(int(summary["type"]))
if typ == WalletType.POOLING_WALLET:
print(f"Wallet id {wallet_id}: ")
pool_wallet_info, _ = await wallet_client.pw_status(wallet_id)
await pprint_pool_wallet_state(
wallet_client,
wallet_id,
pool_wallet_info,
address_prefix,
pool_state_dict.get(pool_wallet_info.launcher_id),
)
print("")
async def get_login_link(launcher_id_str: str) -> None:
@ -262,86 +274,97 @@ async def submit_tx_with_confirmation(
print("Aborting.")
async def join_pool(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
config = load_config(DEFAULT_ROOT_PATH, "config.yaml")
enforce_https = config["full_node"]["selected_network"] == "mainnet"
pool_url: str = args["pool_url"]
fee = Decimal(args.get("fee", 0))
fee_mojos = uint64(int(fee * units["chia"]))
async def join_pool(
wallet_rpc_port: Optional[int],
fingerprint: int,
pool_url: str,
fee: Decimal,
wallet_id: int,
prompt: bool,
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config):
if wallet_client is None:
return None
enforce_https = config["full_node"]["selected_network"] == "mainnet"
fee_mojos = uint64(int(fee * units["chia"]))
if enforce_https and not pool_url.startswith("https://"):
print(f"Pool URLs must be HTTPS on mainnet {pool_url}. Aborting.")
return
wallet_id = args.get("id", None)
prompt = not args.get("yes", False)
try:
async with aiohttp.ClientSession() as session:
async with session.get(f"{pool_url}/pool_info", ssl=ssl_context_for_root(get_mozilla_ca_crt())) as response:
if response.ok:
json_dict = json.loads(await response.text())
else:
print(f"Response not OK: {response.status}")
return
except Exception as e:
print(f"Error connecting to pool {pool_url}: {e}")
return
if enforce_https and not pool_url.startswith("https://"):
print(f"Pool URLs must be HTTPS on mainnet {pool_url}. Aborting.")
return
try:
async with aiohttp.ClientSession() as session:
async with session.get(
f"{pool_url}/pool_info", ssl=ssl_context_for_root(get_mozilla_ca_crt())
) as response:
if response.ok:
json_dict = json.loads(await response.text())
else:
print(f"Response not OK: {response.status}")
return
except Exception as e:
print(f"Error connecting to pool {pool_url}: {e}")
return
if json_dict["relative_lock_height"] > 1000:
print("Relative lock height too high for this pool, cannot join")
return
if json_dict["protocol_version"] != POOL_PROTOCOL_VERSION:
print(f"Incorrect version: {json_dict['protocol_version']}, should be {POOL_PROTOCOL_VERSION}")
return
if json_dict["relative_lock_height"] > 1000:
print("Relative lock height too high for this pool, cannot join")
return
if json_dict["protocol_version"] != POOL_PROTOCOL_VERSION:
print(f"Incorrect version: {json_dict['protocol_version']}, should be {POOL_PROTOCOL_VERSION}")
return
pprint(json_dict)
msg = f"\nWill join pool: {pool_url} with Plot NFT {fingerprint}."
func = functools.partial(
wallet_client.pw_join_pool,
wallet_id,
hexstr_to_bytes(json_dict["target_puzzle_hash"]),
pool_url,
json_dict["relative_lock_height"],
fee_mojos,
)
pprint(json_dict)
msg = f"\nWill join pool: {pool_url} with Plot NFT {fingerprint}."
func = functools.partial(
wallet_client.pw_join_pool,
wallet_id,
hexstr_to_bytes(json_dict["target_puzzle_hash"]),
pool_url,
json_dict["relative_lock_height"],
fee_mojos,
)
await submit_tx_with_confirmation(msg, prompt, func, wallet_client, fingerprint, wallet_id)
await submit_tx_with_confirmation(msg, prompt, func, wallet_client, fingerprint, wallet_id)
async def self_pool(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id = args.get("id", None)
prompt = not args.get("yes", False)
fee = Decimal(args.get("fee", 0))
fee_mojos = uint64(int(fee * units["chia"]))
msg = f"Will start self-farming with Plot NFT on wallet id {wallet_id} fingerprint {fingerprint}."
func = functools.partial(wallet_client.pw_self_pool, wallet_id, fee_mojos)
await submit_tx_with_confirmation(msg, prompt, func, wallet_client, fingerprint, wallet_id)
async def self_pool(
wallet_rpc_port: Optional[int], fingerprint: int, fee: Decimal, wallet_id: int, prompt: bool
) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, _):
if wallet_client is None:
return None
fee_mojos = uint64(int(fee * units["chia"]))
msg = f"Will start self-farming with Plot NFT on wallet id {wallet_id} fingerprint {fingerprint}."
func = functools.partial(wallet_client.pw_self_pool, wallet_id, fee_mojos)
await submit_tx_with_confirmation(msg, prompt, func, wallet_client, fingerprint, wallet_id)
async def inspect_cmd(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id = args.get("id", None)
pool_wallet_info, unconfirmed_transactions = await wallet_client.pw_status(wallet_id)
print(
{
"pool_wallet_info": pool_wallet_info,
"unconfirmed_transactions": [
{"sent_to": tx.sent_to, "transaction_id": tx.name.hex()} for tx in unconfirmed_transactions
],
}
)
async def inspect_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_id: int) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, _):
if wallet_client is None:
return None
pool_wallet_info, unconfirmed_transactions = await wallet_client.pw_status(wallet_id)
print(
{
"pool_wallet_info": pool_wallet_info,
"unconfirmed_transactions": [
{"sent_to": tx.sent_to, "transaction_id": tx.name.hex()} for tx in unconfirmed_transactions
],
}
)
async def claim_cmd(args: Dict[str, Any], wallet_client: WalletRpcClient, fingerprint: int) -> None:
wallet_id = args.get("id", None)
fee = Decimal(args.get("fee", 0))
fee_mojos = uint64(int(fee * units["chia"]))
msg = f"\nWill claim rewards for wallet ID: {wallet_id}."
func = functools.partial(
wallet_client.pw_absorb_rewards,
wallet_id,
fee_mojos,
)
await submit_tx_with_confirmation(msg, False, func, wallet_client, fingerprint, wallet_id)
async def claim_cmd(wallet_rpc_port: Optional[int], fingerprint: int, fee: Decimal, wallet_id: int) -> None:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, _):
if wallet_client is None:
return None
fee_mojos = uint64(int(fee * units["chia"]))
msg = f"\nWill claim rewards for wallet ID: {wallet_id}."
func = functools.partial(
wallet_client.pw_absorb_rewards,
wallet_id,
fee_mojos,
)
await submit_tx_with_confirmation(msg, False, func, wallet_client, fingerprint, wallet_id)
async def change_payout_instructions(launcher_id: str, address: str) -> None:

View File

@ -12,7 +12,7 @@ from chia.plotting.util import add_plot_directory, validate_plot_size
log = logging.getLogger(__name__)
def show_plots(root_path: Path):
def show_plots(root_path: Path) -> None:
from chia.plotting.util import get_plot_directories
print("Directories where plots are being searched for:")
@ -29,7 +29,7 @@ def show_plots(root_path: Path):
@click.group("plots", help="Manage your plots")
@click.pass_context
def plots_cmd(ctx: click.Context):
def plots_cmd(ctx: click.Context) -> None:
"""Create, add, remove and check your plots"""
from chia.util.chia_logging import initialize_logging
@ -114,7 +114,7 @@ def create_cmd(
nobitfield: bool,
exclude_final_dir: bool,
connect_to_daemon: bool,
):
) -> None:
from chia.plotting.create_plots import create_plots, resolve_plot_keys
from chia.plotting.util import Params
@ -174,7 +174,7 @@ def create_cmd(
@click.pass_context
def check_cmd(
ctx: click.Context, num: int, grep_string: str, list_duplicates: bool, debug_show_memo: bool, challenge_start: int
):
) -> None:
from chia.plotting.check_plots import check_plots
check_plots(ctx.obj["root_path"], num, challenge_start, grep_string, list_duplicates, debug_show_memo)
@ -190,7 +190,7 @@ def check_cmd(
show_default=True,
)
@click.pass_context
def add_cmd(ctx: click.Context, final_dir: str):
def add_cmd(ctx: click.Context, final_dir: str) -> None:
from chia.plotting.util import add_plot_directory
try:
@ -210,7 +210,7 @@ def add_cmd(ctx: click.Context, final_dir: str):
show_default=True,
)
@click.pass_context
def remove_cmd(ctx: click.Context, final_dir: str):
def remove_cmd(ctx: click.Context, final_dir: str) -> None:
from chia.plotting.util import remove_plot_directory
remove_plot_directory(ctx.obj["root_path"], final_dir)
@ -218,5 +218,5 @@ def remove_cmd(ctx: click.Context, final_dir: str):
@plots_cmd.command("show", help="Shows the directory of current plots")
@click.pass_context
def show_cmd(ctx: click.Context):
def show_cmd(ctx: click.Context) -> None:
show_plots(ctx.obj["root_path"])

View File

@ -13,5 +13,5 @@ from chia.plotters.plotters import call_plotters
)
@click.pass_context
@click.argument("args", nargs=-1)
def plotters_cmd(ctx: click.Context, args):
def plotters_cmd(ctx: click.Context, args: tuple[click.Argument]) -> None:
call_plotters(ctx.obj["root_path"], args)

View File

@ -1,12 +1,13 @@
from __future__ import annotations
import asyncio
import sys
from typing import Any, Dict, List, Optional, Tuple
from decimal import Decimal
from typing import List, Optional, Tuple
import click
from chia.cmds.check_wallet_db import help_text as check_help_text
from chia.cmds.cmds_util import execute_with_wallet
from chia.cmds.coins import coins_cmd
from chia.cmds.plotnft import validate_fee
from chia.wallet.transaction_sorting import SortKey
@ -33,12 +34,9 @@ def wallet_cmd(ctx: click.Context) -> None:
@click.option("-tx", "--tx_id", help="transaction id to search for", type=str, required=True)
@click.option("--verbose", "-v", count=True, type=int)
def get_transaction_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, tx_id: str, verbose: int) -> None:
extra_params = {"id": id, "tx_id": tx_id, "verbose": verbose}
import asyncio
from .wallet_funcs import get_transaction
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_transaction))
asyncio.run(get_transaction(wallet_rpc_port, fingerprint, tx_id, verbose)) # Wallet ID is not used.
@wallet_cmd.command("get_transactions", help="Get all transactions")
@ -114,22 +112,13 @@ def get_transactions_cmd(
reverse: bool,
clawback: bool,
) -> None: # pragma: no cover
extra_params = {
"id": id,
"verbose": verbose,
"offset": offset,
"paginate": paginate,
"limit": limit,
"sort_key": sort_key,
"reverse": reverse,
"clawback": clawback,
}
import asyncio
from .wallet_funcs import get_transactions
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_transactions))
asyncio.run(
get_transactions(
wallet_rpc_port, fingerprint, id, verbose, paginate, offset, limit, sort_key, reverse, clawback
)
)
# The flush/close avoids output like below when piping through `head -n 1`
# which will close stdout.
@ -215,24 +204,25 @@ def send_cmd(
reuse: bool,
clawback_time: int,
) -> None: # pragma: no cover
extra_params = {
"id": id,
"amount": amount,
"memo": memo,
"fee": fee,
"address": address,
"override": override,
"min_coin_amount": min_coin_amount,
"max_coin_amount": max_coin_amount,
"excluded_coin_ids": list(coins_to_exclude),
"reuse_puzhash": True if reuse else None,
"clawback_time": clawback_time,
}
import asyncio
from .wallet_funcs import send
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, send))
asyncio.run(
send(
wallet_rpc_port,
fingerprint,
id,
Decimal(amount),
memo,
Decimal(fee),
address,
override,
Decimal(min_coin_amount),
Decimal(max_coin_amount),
list(coins_to_exclude),
True if reuse else None,
clawback_time,
)
)
@wallet_cmd.command("show", help="Show wallet information")
@ -252,14 +242,9 @@ def send_cmd(
default=None,
)
def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Optional[str]) -> None:
import asyncio
from .wallet_funcs import print_balances
args: Dict[str, Any] = {}
if wallet_type is not None:
args["type"] = WalletType[wallet_type.upper()]
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, args, print_balances))
asyncio.run(print_balances(wallet_rpc_port, fingerprint, WalletType[wallet_type.upper()] if wallet_type else None))
@wallet_cmd.command("get_address", help="Get a wallet receive address")
@ -282,13 +267,10 @@ def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Opti
is_flag=True,
default=False,
)
def get_address_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int, new_address: bool) -> None:
extra_params = {"id": id, "new_address": new_address}
import asyncio
def get_address_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int, new_address: bool) -> None:
from .wallet_funcs import get_address
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_address))
asyncio.run(get_address(wallet_rpc_port, fingerprint, id, new_address))
@wallet_cmd.command(
@ -316,13 +298,12 @@ def get_address_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int, new_ad
@click.option(
"-m", "--fee", help="A fee to add to the offer when it gets taken, in XCH", default="0", show_default=True
)
def clawback(wallet_rpc_port: Optional[int], id, fingerprint: int, tx_ids: str, fee: str) -> None: # pragma: no cover
extra_params = {"id": id, "tx_ids": tx_ids, "fee": fee}
import asyncio
def clawback(
wallet_rpc_port: Optional[int], id: int, fingerprint: int, tx_ids: str, fee: str
) -> None: # pragma: no cover
from .wallet_funcs import spend_clawback
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, spend_clawback))
asyncio.run(spend_clawback(wallet_rpc_port, fingerprint, Decimal(fee), tx_ids)) # Wallet ID is not Used.
@wallet_cmd.command("delete_unconfirmed_transactions", help="Deletes all unconfirmed transactions for this wallet ID")
@ -335,13 +316,10 @@ def clawback(wallet_rpc_port: Optional[int], id, fingerprint: int, tx_ids: str,
)
@click.option("-i", "--id", help="Id of the wallet to use", type=int, default=1, show_default=True, required=True)
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int) -> None:
extra_params = {"id": id}
import asyncio
def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int) -> None:
from .wallet_funcs import delete_unconfirmed_transactions
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, delete_unconfirmed_transactions))
asyncio.run(delete_unconfirmed_transactions(wallet_rpc_port, fingerprint, id))
@wallet_cmd.command("get_derivation_index", help="Get the last puzzle hash derivation path index")
@ -354,12 +332,9 @@ def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id, fing
)
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
def get_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int) -> None:
extra_params: Dict[str, Any] = {}
import asyncio
from .wallet_funcs import get_derivation_index
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_derivation_index))
asyncio.run(get_derivation_index(wallet_rpc_port, fingerprint))
@wallet_cmd.command("sign_message", help="Sign a message by a derivation address")
@ -374,12 +349,11 @@ def get_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int) -
@click.option("-a", "--address", help="The address you want to use for signing", type=str, required=True)
@click.option("-m", "--hex_message", help="The hex message you want sign", type=str, required=True)
def address_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, address: str, hex_message: str) -> None:
extra_params: Dict[str, Any] = {"address": address, "message": hex_message, "type": AddressType.XCH}
import asyncio
from .wallet_funcs import sign_message
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, sign_message))
asyncio.run(
sign_message(wallet_rpc_port, fingerprint, addr_type=AddressType.XCH, message=hex_message, address=address)
)
@wallet_cmd.command(
@ -397,12 +371,9 @@ def address_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, addre
"-i", "--index", help="Index to set. Must be greater than the current derivation index", type=int, required=True
)
def update_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int, index: int) -> None:
extra_params = {"index": index}
import asyncio
from .wallet_funcs import update_derivation_index
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, update_derivation_index))
asyncio.run(update_derivation_index(wallet_rpc_port, fingerprint, index))
@wallet_cmd.command("add_token", help="Add/Rename a CAT to the wallet by its asset ID")
@ -432,12 +403,9 @@ def update_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int
help="The wallet fingerprint you wish to add the token to",
)
def add_token_cmd(wallet_rpc_port: Optional[int], asset_id: str, token_name: str, fingerprint: int) -> None:
extra_params = {"asset_id": asset_id, "token_name": token_name}
import asyncio
from .wallet_funcs import add_token
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_token))
asyncio.run(add_token(wallet_rpc_port, fingerprint, asset_id, token_name))
@wallet_cmd.command("make_offer", help="Create an offer of XCH/CATs/NFTs for XCH/CATs/NFTs")
@ -482,18 +450,11 @@ def make_offer_cmd(
fee: str,
reuse: bool,
) -> None:
extra_params = {
"offers": offer,
"requests": request,
"filepath": filepath,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
import asyncio
from .wallet_funcs import make_offer
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, make_offer))
asyncio.run(
make_offer(wallet_rpc_port, fingerprint, Decimal(fee), offer, request, filepath, True if reuse else None)
)
@wallet_cmd.command(
@ -527,20 +488,21 @@ def get_offers_cmd(
summaries: bool,
reverse: bool,
) -> None:
extra_params = {
"id": id,
"filepath": filepath,
"exclude_my_offers": exclude_my_offers,
"exclude_taken_offers": exclude_taken_offers,
"include_completed": include_completed,
"summaries": summaries,
"reverse": reverse,
}
import asyncio
from .wallet_funcs import get_offers
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_offers))
asyncio.run(
get_offers(
wallet_rpc_port,
fingerprint,
id,
filepath,
exclude_my_offers,
exclude_taken_offers,
include_completed,
summaries,
reverse,
)
)
@wallet_cmd.command("take_offer", help="Examine or take an offer")
@ -571,17 +533,9 @@ def take_offer_cmd(
fee: str,
reuse: bool,
) -> None:
extra_params = {
"file": path_or_hex,
"examine_only": examine_only,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
import asyncio
from .wallet_funcs import take_offer
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, take_offer))
asyncio.run(take_offer(wallet_rpc_port, fingerprint, Decimal(fee), path_or_hex, examine_only)) # reuse is not used
@wallet_cmd.command("cancel_offer", help="Cancel an existing offer")
@ -599,12 +553,9 @@ def take_offer_cmd(
"-m", "--fee", help="The fee to use when cancelling the offer securely, in XCH", default="0", show_default=True
)
def cancel_offer_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: str, insecure: bool, fee: str) -> None:
extra_params = {"id": id, "insecure": insecure, "fee": fee}
import asyncio
from .wallet_funcs import cancel_offer
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, cancel_offer))
asyncio.run(cancel_offer(wallet_rpc_port, fingerprint, Decimal(fee), id, insecure))
@wallet_cmd.command("check", short_help="Check wallet DB integrity", help=check_help_text)
@ -615,7 +566,6 @@ def cancel_offer_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: str,
# TODO: Convert to Path earlier
def check_wallet_cmd(ctx: click.Context, db_path: str, verbose: bool) -> None:
"""check, scan, diagnose, fsck Chia Wallet DBs"""
import asyncio
from chia.cmds.check_wallet_db import scan
@ -623,7 +573,7 @@ def check_wallet_cmd(ctx: click.Context, db_path: str, verbose: bool) -> None:
@wallet_cmd.group("did", help="DID related actions")
def did_cmd():
def did_cmd() -> None:
pass
@ -655,14 +605,11 @@ def did_cmd():
callback=validate_fee,
)
def did_create_wallet_cmd(
wallet_rpc_port: Optional[int], fingerprint: int, name: Optional[str], amount: Optional[int], fee: Optional[int]
wallet_rpc_port: Optional[int], fingerprint: int, name: Optional[str], amount: int, fee: str
) -> None:
import asyncio
from .wallet_funcs import create_did_wallet
extra_params = {"amount": amount, "fee": fee, "name": name}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, create_did_wallet))
asyncio.run(create_did_wallet(wallet_rpc_port, fingerprint, Decimal(fee), name, amount))
@did_cmd.command("sign_message", help="Sign a message by a DID")
@ -677,12 +624,11 @@ def did_create_wallet_cmd(
@click.option("-i", "--did_id", help="DID ID you want to use for signing", type=str, required=True)
@click.option("-m", "--hex_message", help="The hex message you want to sign", type=str, required=True)
def did_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, did_id: str, hex_message: str) -> None:
extra_params: Dict[str, Any] = {"did_id": did_id, "message": hex_message, "type": AddressType.DID}
import asyncio
from .wallet_funcs import sign_message
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, sign_message))
asyncio.run(
sign_message(wallet_rpc_port, fingerprint, addr_type=AddressType.DID, message=hex_message, did_id=did_id)
)
@did_cmd.command("set_name", help="Set DID wallet name")
@ -697,12 +643,9 @@ def did_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, did_id: s
@click.option("-i", "--id", help="Id of the wallet to use", type=int, required=True)
@click.option("-n", "--name", help="Set the DID wallet name", type=str, required=True)
def did_wallet_name_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, name: str) -> None:
import asyncio
from .wallet_funcs import did_set_wallet_name
extra_params = {"wallet_id": id, "name": name}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, did_set_wallet_name))
asyncio.run(did_set_wallet_name(wallet_rpc_port, fingerprint, id, name))
@did_cmd.command("get_did", help="Get DID from wallet")
@ -716,12 +659,9 @@ def did_wallet_name_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: in
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-i", "--id", help="Id of the wallet to use", type=int, required=True)
def did_get_did_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .wallet_funcs import get_did
extra_params = {"did_wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_did))
asyncio.run(get_did(wallet_rpc_port, fingerprint, id))
@did_cmd.command("get_details", help="Get more details of any DID")
@ -736,12 +676,9 @@ def did_get_did_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -
@click.option("-id", "--coin_id", help="Id of the DID or any coin ID of the DID", type=str, required=True)
@click.option("-l", "--latest", help="Return latest DID information", is_flag=True, default=True)
def did_get_details_cmd(wallet_rpc_port: Optional[int], fingerprint: int, coin_id: str, latest: bool) -> None:
import asyncio
from .wallet_funcs import get_did_info
extra_params = {"coin_id": coin_id, "latest": latest}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_did_info))
asyncio.run(get_did_info(wallet_rpc_port, fingerprint, coin_id, latest))
@did_cmd.command("update_metadata", help="Update the metadata of a DID")
@ -764,12 +701,9 @@ def did_get_details_cmd(wallet_rpc_port: Optional[int], fingerprint: int, coin_i
def did_update_metadata_cmd(
wallet_rpc_port: Optional[int], fingerprint: int, id: int, metadata: str, reuse: bool
) -> None:
import asyncio
from .wallet_funcs import update_did_metadata
extra_params = {"did_wallet_id": id, "metadata": metadata, "reuse_puzhash": reuse}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, update_did_metadata))
asyncio.run(update_did_metadata(wallet_rpc_port, fingerprint, id, metadata, reuse))
@did_cmd.command("find_lost", help="Find the did you should own and recovery the DID wallet")
@ -806,17 +740,9 @@ def did_find_lost_cmd(
recovery_list_hash: Optional[str],
num_verification: Optional[int],
) -> None:
import asyncio
from .wallet_funcs import find_lost_did
extra_params = {
"coin_id": coin_id,
"metadata": metadata,
"recovery_list_hash": recovery_list_hash,
"num_verification": num_verification,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, find_lost_did))
asyncio.run(find_lost_did(wallet_rpc_port, fingerprint, coin_id, metadata, recovery_list_hash, num_verification))
@did_cmd.command("message_spend", help="Generate a DID spend bundle for announcements")
@ -850,8 +776,6 @@ def did_message_spend_cmd(
puzzle_announcements: Optional[str],
coin_announcements: Optional[str],
) -> None:
import asyncio
from .wallet_funcs import did_message_spend
puzzle_list: List[str] = []
@ -874,8 +798,8 @@ def did_message_spend_cmd(
except ValueError:
print("Invalid coin announcement format, should be a list of hex strings.")
return
extra_params = {"did_wallet_id": id, "puzzle_announcements": puzzle_list, "coin_announcements": coin_list}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, did_message_spend))
asyncio.run(did_message_spend(wallet_rpc_port, fingerprint, id, puzzle_list, coin_list))
@did_cmd.command("transfer", help="Transfer a DID")
@ -913,25 +837,20 @@ def did_transfer_did(
id: int,
target_address: str,
reset_recovery: bool,
fee: str,
fee: int,
reuse: bool,
) -> None:
import asyncio
from .wallet_funcs import transfer_did
extra_params = {
"did_wallet_id": id,
"with_recovery": reset_recovery is False,
"target_address": target_address,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, transfer_did))
asyncio.run(
transfer_did(
wallet_rpc_port, fingerprint, id, fee, target_address, reset_recovery is False, True if reuse else None
)
)
@wallet_cmd.group("nft", help="NFT related actions")
def nft_cmd():
def nft_cmd() -> None:
pass
@ -949,12 +868,9 @@ def nft_cmd():
def nft_wallet_create_cmd(
wallet_rpc_port: Optional[int], fingerprint: int, did_id: Optional[str], name: Optional[str]
) -> None:
import asyncio
from .wallet_funcs import create_nft_wallet
extra_params: Dict[str, Any] = {"did_id": did_id, "name": name}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, create_nft_wallet))
asyncio.run(create_nft_wallet(wallet_rpc_port, fingerprint, did_id, name))
@nft_cmd.command("sign_message", help="Sign a message by a NFT")
@ -969,12 +885,11 @@ def nft_wallet_create_cmd(
@click.option("-i", "--nft_id", help="NFT ID you want to use for signing", type=str, required=True)
@click.option("-m", "--hex_message", help="The hex message you want to sign", type=str, required=True)
def nft_sign_message(wallet_rpc_port: Optional[int], fingerprint: int, nft_id: str, hex_message: str) -> None:
extra_params: Dict[str, Any] = {"nft_id": nft_id, "message": hex_message, "type": AddressType.NFT}
import asyncio
from .wallet_funcs import sign_message
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, sign_message))
asyncio.run(
sign_message(wallet_rpc_port, fingerprint, addr_type=AddressType.NFT, message=hex_message, nft_id=nft_id)
)
@nft_cmd.command("mint", help="Mint an NFT")
@ -1040,8 +955,6 @@ def nft_mint_cmd(
royalty_percentage_fraction: int,
reuse: bool,
) -> None:
import asyncio
from .wallet_funcs import mint_nft
if metadata_uris is None:
@ -1054,24 +967,27 @@ def nft_mint_cmd(
else:
license_uris_list = [lu.strip() for lu in license_uris.split(",")]
extra_params = {
"wallet_id": id,
"royalty_address": royalty_address,
"target_address": target_address,
"no_did_ownership": no_did_ownership,
"hash": hash,
"uris": [u.strip() for u in uris.split(",")],
"metadata_hash": metadata_hash,
"metadata_uris": metadata_uris_list,
"license_hash": license_hash,
"license_uris": license_uris_list,
"edition_total": edition_total,
"edition_number": edition_number,
"fee": fee,
"royalty_percentage": royalty_percentage_fraction,
"reuse_puzhash": True if reuse else None,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, mint_nft))
asyncio.run(
mint_nft(
wallet_rpc_port,
fingerprint,
id,
royalty_address,
target_address,
no_did_ownership,
hash,
[u.strip() for u in uris.split(",")],
metadata_hash,
metadata_uris_list,
license_hash,
license_uris_list,
edition_total,
edition_number,
Decimal(fee),
royalty_percentage_fraction,
True if reuse else None,
)
)
@nft_cmd.command("add_uri", help="Add an URI to an NFT")
@ -1114,20 +1030,21 @@ def nft_add_uri_cmd(
fee: str,
reuse: bool,
) -> None:
import asyncio
from .wallet_funcs import add_uri_to_nft
extra_params = {
"wallet_id": id,
"nft_coin_id": nft_coin_id,
"uri": uri,
"metadata_uri": metadata_uri,
"license_uri": license_uri,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_uri_to_nft))
asyncio.run(
add_uri_to_nft(
wallet_rpc_port,
fingerprint,
id,
Decimal(fee),
nft_coin_id,
uri,
metadata_uri,
license_uri,
True if reuse else None,
)
)
@nft_cmd.command("transfer", help="Transfer an NFT")
@ -1166,18 +1083,13 @@ def nft_transfer_cmd(
fee: str,
reuse: bool,
) -> None:
import asyncio
from .wallet_funcs import transfer_nft
extra_params = {
"wallet_id": id,
"nft_coin_id": nft_coin_id,
"target_address": target_address,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, transfer_nft))
asyncio.run(
transfer_nft(
wallet_rpc_port, fingerprint, id, Decimal(fee), nft_coin_id, target_address, True if reuse else None
)
)
@nft_cmd.command("list", help="List the current NFTs")
@ -1191,12 +1103,9 @@ def nft_transfer_cmd(
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-i", "--id", help="Id of the NFT wallet to use", type=int, required=True)
def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .wallet_funcs import list_nfts
extra_params = {"wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, list_nfts))
asyncio.run(list_nfts(wallet_rpc_port, fingerprint, id))
@nft_cmd.command("set_did", help="Set a DID on an NFT")
@ -1235,18 +1144,11 @@ def nft_set_did_cmd(
fee: str,
reuse: bool,
) -> None:
import asyncio
from .wallet_funcs import set_nft_did
extra_params = {
"wallet_id": id,
"did_id": did_id,
"nft_coin_id": nft_coin_id,
"fee": fee,
"reuse_puzhash": True if reuse else None,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, set_nft_did))
asyncio.run(
set_nft_did(wallet_rpc_port, fingerprint, id, Decimal(fee), nft_coin_id, did_id, True if reuse else None)
)
@nft_cmd.command("get_info", help="Get NFT information")
@ -1264,14 +1166,9 @@ def nft_get_info_cmd(
fingerprint: int,
nft_coin_id: str,
) -> None:
import asyncio
from .wallet_funcs import get_nft_info
extra_params = {
"nft_coin_id": nft_coin_id,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_nft_info))
asyncio.run(get_nft_info(wallet_rpc_port, fingerprint, nft_coin_id))
# Keep at bottom.
@ -1279,7 +1176,7 @@ wallet_cmd.add_command(coins_cmd)
@wallet_cmd.group("notifications", help="Send/Manage notifications")
def notification_cmd():
def notification_cmd() -> None:
pass
@ -1304,7 +1201,7 @@ def notification_cmd():
)
@click.option("-n", "--message", help="The message of the notification", type=str)
@click.option("-m", "--fee", help="The fee for the transaction, in XCH", type=str)
def _send_notification(
def send_notification_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
to_address: str,
@ -1312,19 +1209,9 @@ def _send_notification(
message: str,
fee: str,
) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import send_notification
extra_params = {
"address": to_address,
"amount": amount,
"message": message,
"fee": fee,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, send_notification))
asyncio.run(send_notification(wallet_rpc_port, fingerprint, Decimal(fee), to_address, message, Decimal(amount)))
@notification_cmd.command("get", help="Get notification(s) that are in your wallet")
@ -1339,25 +1226,16 @@ def _send_notification(
@click.option("-i", "--id", help="The specific notification ID to show", type=str, default=[], multiple=True)
@click.option("-s", "--start", help="The number of notifications to skip", type=int, default=None)
@click.option("-e", "--end", help="The number of notifications to stop at", type=int, default=None)
def _get_notifications(
def get_notifications_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
id: List[str],
start: Optional[int],
end: Optional[int],
) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import get_notifications
extra_params = {
"ids": id,
"start": start,
"end": end,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_notifications))
asyncio.run(get_notifications(wallet_rpc_port, fingerprint, id, start, end))
@notification_cmd.command("delete", help="Delete notification(s) that are in your wallet")
@ -1371,27 +1249,19 @@ def _get_notifications(
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-i", "--id", help="A specific notification ID to delete", type=str, multiple=True)
@click.option("--all", help="All notifications can be deleted (they will be recovered during resync)", is_flag=True)
def _delete_notifications(
def delete_notifications_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
id: List[str],
all: bool,
) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import delete_notifications
extra_params = {
"ids": id,
"all": all,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, delete_notifications))
asyncio.run(delete_notifications(wallet_rpc_port, fingerprint, id, all))
@wallet_cmd.group("vcs", short_help="Verifiable Credential related actions")
def vcs_cmd(): # pragma: no cover
def vcs_cmd() -> None: # pragma: no cover
pass
@ -1406,26 +1276,17 @@ def vcs_cmd(): # pragma: no cover
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-d", "--did", help="The DID of the VC's proof provider", type=str, required=True)
@click.option("-t", "--target-address", help="The address to send the VC to once it's minted", type=str, required=False)
@click.option("-m", "--fee", help="Blockchain fee for mint transaction, in XCH", type=str, required=False)
def _mint_vc(
@click.option("-m", "--fee", help="Blockchain fee for mint transaction, in XCH", type=str, required=False, default="0")
def mint_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
did: str,
target_address: Optional[str],
fee: Optional[str],
fee: str,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import mint_vc
extra_params = {
"did": did,
"target_address": target_address,
"fee": fee,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, mint_vc))
asyncio.run(mint_vc(wallet_rpc_port, fingerprint, did, Decimal(fee), target_address))
@vcs_cmd.command("get", short_help="Get a list of existing VCs")
@ -1443,23 +1304,15 @@ def _mint_vc(
@click.option(
"-c", "--count", help="How many results to return", type=int, required=False, default=50, show_default=True
)
def _get_vcs(
def get_vcs_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
start: int,
count: int,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import get_vcs
extra_params = {
"start": start,
"count": count,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_vcs))
asyncio.run(get_vcs(wallet_rpc_port, fingerprint, start, count))
@vcs_cmd.command("update_proofs", short_help="Update a VC's proofs if you have the provider DID")
@ -1480,14 +1333,16 @@ def _get_vcs(
required=False,
)
@click.option("-p", "--new-proof-hash", help="The new proof hash to update the VC to", type=str, required=True)
@click.option("-m", "--fee", help="Blockchain fee for update transaction, in XCH", type=str, required=False)
@click.option(
"-m", "--fee", help="Blockchain fee for update transaction, in XCH", type=str, required=False, default="0"
)
@click.option(
"--reuse-puzhash/--generate-new-puzhash",
help="Send the VC back to the same puzzle hash it came from (ignored if --new-puzhash is specified)",
default=False,
show_default=True,
)
def _spend_vc(
def spend_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
vc_id: str,
@ -1496,20 +1351,19 @@ def _spend_vc(
fee: str,
reuse_puzhash: bool,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import spend_vc
extra_params = {
"vc_id": vc_id,
"new_puzhash": new_puzhash,
"new_proof_hash": new_proof_hash,
"fee": fee,
"reuse_puzhash": reuse_puzhash,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, spend_vc))
asyncio.run(
spend_vc(
wallet_rpc_port,
fingerprint,
vc_id,
Decimal(fee),
new_puzhash,
new_proof_hash,
reuse_puzhash,
)
)
@vcs_cmd.command("add_proof_reveal", short_help="Add a series of proofs that will combine to a single proof hash")
@ -1523,23 +1377,15 @@ def _spend_vc(
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-p", "--proof", help="A flag to add as a proof", type=str, multiple=True)
@click.option("-r", "--root-only", help="Do not add the proofs to the DB, just output the root", is_flag=True)
def _add_proof_reveal(
def add_proof_reveal_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
proof: List[str],
root_only: bool,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import add_proof_reveal
extra_params = {
"proofs": proof,
"root_only": root_only,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_proof_reveal))
asyncio.run(add_proof_reveal(wallet_rpc_port, fingerprint, proof, root_only))
@vcs_cmd.command("get_proofs_for_root", short_help="Get the stored proof flags for a given proof hash")
@ -1552,21 +1398,14 @@ def _add_proof_reveal(
)
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which key to use", type=int)
@click.option("-r", "--proof-hash", help="The root to search for", type=str, required=True)
def _get_proofs_for_root(
def get_proofs_for_root_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
proof_hash: str,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import get_proofs_for_root
extra_params = {
"proof_hash": proof_hash,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_proofs_for_root))
asyncio.run(get_proofs_for_root(wallet_rpc_port, fingerprint, proof_hash))
@vcs_cmd.command("revoke", short_help="Revoke any VC if you have the proper DID and the VCs parent coin")
@ -1592,14 +1431,16 @@ def _get_proofs_for_root(
type=str,
required=False,
)
@click.option("-m", "--fee", help="Blockchain fee for revocation transaction, in XCH", type=str, required=False)
@click.option(
"-m", "--fee", help="Blockchain fee for revocation transaction, in XCH", type=str, required=False, default="0"
)
@click.option(
"--reuse-puzhash/--generate-new-puzhash",
help="Send the VC back to the same puzzle hash it came from (ignored if --new-puzhash is specified)",
default=False,
show_default=True,
)
def _revoke_vc(
def revoke_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
parent_coin_id: Optional[str],
@ -1607,16 +1448,6 @@ def _revoke_vc(
fee: str,
reuse_puzhash: bool,
) -> None: # pragma: no cover
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .wallet_funcs import revoke_vc
extra_params = {
"parent_coin_id": parent_coin_id,
"vc_id": vc_id,
"fee": fee,
"reuse_puzhash": reuse_puzhash,
}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, revoke_vc))
asyncio.run(revoke_vc(wallet_rpc_port, fingerprint, vc_id, parent_coin_id, Decimal(fee), reuse_puzhash))

File diff suppressed because it is too large Load Diff

View File

@ -875,7 +875,7 @@ class WalletRpcClient(RpcClient):
await self.fetch("cancel_offer", {"trade_id": trade_id.hex(), "secure": secure, "fee": fee})
# NFT wallet
async def create_new_nft_wallet(self, did_id, name=None):
async def create_new_nft_wallet(self, did_id, name=None) -> dict[str, Any]:
request: Dict[str, Any] = {
"wallet_type": "nft_wallet",
"did_id": did_id,
@ -986,7 +986,7 @@ class WalletRpcClient(RpcClient):
response = await self.fetch("nft_count_nfts", request)
return response
async def list_nfts(self, wallet_id):
async def list_nfts(self, wallet_id) -> dict[str, Any]:
request: Dict[str, Any] = {"wallet_id": wallet_id, "num": 100_000}
response = await self.fetch("nft_get_nfts", request)
return response
@ -1009,7 +1009,7 @@ class WalletRpcClient(RpcClient):
response = await self.fetch("nft_set_nft_did", request)
return response
async def get_nft_wallet_did(self, wallet_id):
async def get_nft_wallet_did(self, wallet_id) -> dict[str, Optional[str]]:
request: Dict[str, Any] = {"wallet_id": wallet_id}
response = await self.fetch("nft_get_wallet_did", request)
return response

View File

@ -1,9 +1,5 @@
# File created by: python manage-mypy.py build-exclusions
chia.cmds.plots
chia.cmds.plotters
chia.cmds.start_funcs
chia.cmds.wallet
chia.cmds.wallet_funcs
chia.daemon.server
chia.introducer.introducer
chia.introducer.introducer_api