remove an insane amount of imports & add support for edge case (#13195)

add support for edge case
This commit is contained in:
Jack Nelson 2022-09-02 15:08:48 -07:00 committed by GitHub
parent 0a433b3368
commit 9c0e236a3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 33 deletions

View File

@ -34,12 +34,12 @@ def transaction_status_msg(fingerprint: int, tx_id: bytes32) -> str:
async def validate_client_connection(
rpc_client: RpcClient, node_type: str, rpc_port: int, fingerprint: Optional[int]
rpc_client: RpcClient, node_type: str, rpc_port: int, fingerprint: Optional[int], login_to_wallet: bool
) -> Optional[int]:
try:
await rpc_client.healthz()
if type(rpc_client) == WalletRpcClient:
if type(rpc_client) == WalletRpcClient and login_to_wallet:
fingerprint = await get_wallet(rpc_client, fingerprint)
if fingerprint is None:
rpc_client.close()
@ -57,6 +57,7 @@ async def get_any_service_client(
rpc_port: Optional[int] = None,
root_path: Path = DEFAULT_ROOT_PATH,
fingerprint: Optional[int] = None,
login_to_wallet: bool = True,
) -> AsyncIterator[Tuple[Optional[Any], Dict[str, Any], Optional[int]]]:
"""
Yields a tuple with a RpcClient for the applicable node type a dictionary of the node's configuration,
@ -77,7 +78,7 @@ async def get_any_service_client(
try:
# check if we can connect to node, and if we can then validate
# fingerprint access, otherwise return fingerprint and shutdown client
fingerprint = await validate_client_connection(node_client, node_type, rpc_port, fingerprint)
fingerprint = await validate_client_connection(node_client, node_type, rpc_port, fingerprint, login_to_wallet)
if node_client.session.closed:
yield None, config, fingerprint
else:

View File

@ -59,7 +59,7 @@ async def get_average_block_time(rpc_port: Optional[int]) -> float:
async def get_wallets_stats(wallet_rpc_port: Optional[int]) -> Optional[Dict[str, Any]]:
wallet_client: Optional[WalletRpcClient]
async with get_any_service_client("wallet", wallet_rpc_port) as node_config_fp:
async with get_any_service_client("wallet", wallet_rpc_port, login_to_wallet=False) as node_config_fp:
wallet_client, _, _ = node_config_fp
if wallet_client is not None:
return await wallet_client.get_farmed_amount()

View File

@ -2,6 +2,7 @@ from decimal import Decimal
from typing import Optional
import click
from chia.cmds.cmds_util import execute_with_wallet
MAX_CMDLINE_FEE = Decimal(0.5)
@ -34,7 +35,7 @@ def plotnft_cmd() -> None:
@click.option("-f", "--fingerprint", help="Set the fingerprint to specify which wallet to use", type=int)
def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import show
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, {"id": id}, show))
@ -82,7 +83,7 @@ def create_cmd(
yes: bool,
) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import create
if pool_url is not None and state.lower() == "local":
@ -125,7 +126,7 @@ def create_cmd(
)
def join_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int, pool_url: str, yes: bool) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import join_pool
extra_params = {"pool_url": pool_url, "id": id, "fee": fee, "yes": yes}
@ -155,7 +156,7 @@ def join_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int
)
def self_pool_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int, yes: bool) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import self_pool
extra_params = {"id": id, "fee": fee, "yes": yes}
@ -174,7 +175,7 @@ def self_pool_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee
)
def inspect(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import inspect_cmd
extra_params = {"id": id}
@ -203,7 +204,7 @@ def inspect(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
)
def claim(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee: int) -> None:
import asyncio
from chia.cmds.cmds_util import execute_with_wallet
from .plotnft_funcs import claim_cmd
extra_params = {"id": id, "fee": fee}

View File

@ -6,6 +6,7 @@ import click
from chia.cmds.plotnft import validate_fee
from chia.wallet.transaction_sorting import SortKey
from chia.wallet.util.wallet_types import WalletType
from chia.cmds.cmds_util import execute_with_wallet
@click.group("wallet", short_help="Manage your wallet")
@ -30,7 +31,6 @@ def get_transaction_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: in
extra_params = {"id": id, "tx_id": tx_id, "verbose": verbose}
import asyncio
from .wallet_funcs import get_transaction
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_transaction))
@ -111,7 +111,6 @@ def get_transactions_cmd(
import asyncio
from .wallet_funcs import get_transactions
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_transactions))
@ -179,7 +178,6 @@ def send_cmd(
}
import asyncio
from .wallet_funcs import send
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, send))
@ -203,7 +201,6 @@ def send_cmd(
def show_cmd(wallet_rpc_port: Optional[int], fingerprint: int, wallet_type: Optional[str]) -> None:
import asyncio
from .wallet_funcs import print_balances
from chia.cmds.cmds_util import execute_with_wallet
args: Dict[str, Any] = {}
if wallet_type is not None:
@ -235,7 +232,6 @@ def get_address_cmd(wallet_rpc_port: Optional[int], id, fingerprint: int, new_ad
extra_params = {"id": id, "new_address": new_address}
import asyncio
from .wallet_funcs import get_address
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_address))
@ -256,7 +252,6 @@ def delete_unconfirmed_transactions_cmd(wallet_rpc_port: Optional[int], id, fing
extra_params = {"id": id}
import asyncio
from .wallet_funcs import delete_unconfirmed_transactions
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, delete_unconfirmed_transactions))
@ -274,7 +269,6 @@ def get_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int) -
extra_params: Dict[str, Any] = {}
import asyncio
from .wallet_funcs import get_derivation_index
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_derivation_index))
@ -297,7 +291,6 @@ def update_derivation_index_cmd(wallet_rpc_port: Optional[int], fingerprint: int
extra_params = {"index": index}
import asyncio
from .wallet_funcs import update_derivation_index
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, update_derivation_index))
@ -332,7 +325,6 @@ def add_token_cmd(wallet_rpc_port: Optional[int], asset_id: str, token_name: str
extra_params = {"asset_id": asset_id, "token_name": token_name}
import asyncio
from .wallet_funcs import add_token
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, add_token))
@ -368,7 +360,6 @@ def make_offer_cmd(
extra_params = {"offers": offer, "requests": request, "filepath": filepath, "fee": fee}
import asyncio
from .wallet_funcs import make_offer
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, make_offer))
@ -415,7 +406,6 @@ def get_offers_cmd(
}
import asyncio
from .wallet_funcs import get_offers
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_offers))
@ -438,7 +428,6 @@ def take_offer_cmd(
extra_params = {"file": path_or_hex, "examine_only": examine_only, "fee": fee}
import asyncio
from .wallet_funcs import take_offer
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, take_offer))
@ -459,7 +448,6 @@ def cancel_offer_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: str,
extra_params = {"id": id, "insecure": insecure, "fee": fee}
import asyncio
from .wallet_funcs import cancel_offer
from chia.cmds.cmds_util import execute_with_wallet
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, cancel_offer))
@ -501,7 +489,6 @@ def did_create_wallet_cmd(
) -> None:
import asyncio
from .wallet_funcs import create_did_wallet
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {"amount": amount, "fee": fee, "name": name}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, create_did_wallet))
@ -521,7 +508,6 @@ def did_create_wallet_cmd(
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
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {"wallet_id": id, "name": name}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, did_set_wallet_name))
@ -540,7 +526,6 @@ def did_wallet_name_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: in
def did_get_did_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .wallet_funcs import get_did
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {"did_wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, get_did))
@ -567,7 +552,6 @@ def nft_wallet_create_cmd(
) -> None:
import asyncio
from .wallet_funcs import create_nft_wallet
from chia.cmds.cmds_util import execute_with_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))
@ -631,7 +615,6 @@ def nft_mint_cmd(
) -> None:
import asyncio
from .wallet_funcs import mint_nft
from chia.cmds.cmds_util import execute_with_wallet
if metadata_uris is None:
metadata_uris_list = []
@ -697,7 +680,6 @@ def nft_add_uri_cmd(
) -> None:
import asyncio
from .wallet_funcs import add_uri_to_nft
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {
"wallet_id": id,
@ -741,7 +723,6 @@ def nft_transfer_cmd(
) -> None:
import asyncio
from .wallet_funcs import transfer_nft
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {
"wallet_id": id,
@ -765,7 +746,6 @@ def nft_transfer_cmd(
def nft_list_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int) -> None:
import asyncio
from .wallet_funcs import list_nfts
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {"wallet_id": id}
asyncio.run(execute_with_wallet(wallet_rpc_port, fingerprint, extra_params, list_nfts))
@ -802,7 +782,6 @@ def nft_set_did_cmd(
) -> None:
import asyncio
from .wallet_funcs import set_nft_did
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {
"wallet_id": id,
@ -830,7 +809,6 @@ def nft_get_info_cmd(
) -> None:
import asyncio
from .wallet_funcs import get_nft_info
from chia.cmds.cmds_util import execute_with_wallet
extra_params = {
"nft_coin_id": nft_coin_id,