Skip to content

Commit

Permalink
fix confusion between prompt and don't prompt in the plotnft CLI (#17951
Browse files Browse the repository at this point in the history
)

* fix confusion between prompt and don't prompt in the plotnft CLI

* use cli_confirm in plotnft CLI
  • Loading branch information
arvidn authored May 4, 2024
1 parent cb57cc8 commit 1661ce2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
10 changes: 7 additions & 3 deletions chia/cmds/plotnft.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ 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"}
asyncio.run(create(wallet_rpc_port, fingerprint, pool_url, valid_initial_states[state], Decimal(fee), dont_prompt))
asyncio.run(
create(
wallet_rpc_port, fingerprint, pool_url, valid_initial_states[state], Decimal(fee), prompt=not dont_prompt
)
)


@plotnft_cmd.command("join", help="Join a plot NFT to a Pool")
Expand Down Expand Up @@ -133,7 +137,7 @@ def join_cmd(
pool_url=pool_url,
fee=Decimal(fee),
wallet_id=id,
prompt=dont_prompt,
prompt=not dont_prompt,
)
)

Expand Down Expand Up @@ -170,7 +174,7 @@ def self_pool_cmd(wallet_rpc_port: Optional[int], fingerprint: int, id: int, fee
fingerprint=fingerprint,
fee=Decimal(fee),
wallet_id=id,
prompt=dont_prompt,
prompt=not dont_prompt,
)
)

Expand Down
86 changes: 37 additions & 49 deletions chia/cmds/plotnft_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import aiohttp

from chia.cmds.cmds_util import (
cli_confirm,
get_any_service_client,
get_wallet_client,
transaction_status_msg,
Expand Down Expand Up @@ -61,7 +62,7 @@ async def create_pool_args(pool_url: str) -> Dict[str, Any]:


async def create(
wallet_rpc_port: Optional[int], fingerprint: int, pool_url: Optional[str], state: str, fee: Decimal, prompt: bool
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, _):
fee_mojos = uint64(int(fee * units["chia"]))
Expand All @@ -88,35 +89,28 @@ async def create(
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"
cli_confirm("Confirm (y/n): ", "Aborting.")

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(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.")
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(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")


async def pprint_pool_wallet_state(
Expand Down Expand Up @@ -261,26 +255,20 @@ async def submit_tx_with_confirmation(
) -> None:
print(message)
if prompt:
user_input: str = input("Confirm [n]/y: ")
else:
user_input = "yes"

if user_input.lower() == "y" or user_input.lower() == "yes":
try:
result = await func()
tx_record: TransactionRecord = result["transaction"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(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 performing operation on Plot NFT -f {fingerprint} wallet id: {wallet_id}: {e}")
return
print("Aborting.")
cli_confirm("Confirm (y/n): ", "Aborting.")
try:
result = await func()
tx_record: TransactionRecord = result["transaction"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(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 performing operation on Plot NFT -f {fingerprint} wallet id: {wallet_id}: {e}")


async def join_pool(
Expand Down

0 comments on commit 1661ce2

Please sign in to comment.