Skip to content

Commit

Permalink
Convert wallet RPC client to deserialized types
Browse files Browse the repository at this point in the history
  • Loading branch information
Quexington committed Jan 24, 2024
1 parent 2cc1df3 commit 628c9ca
Show file tree
Hide file tree
Showing 24 changed files with 948 additions and 600 deletions.
2 changes: 1 addition & 1 deletion chia/cmds/cmds_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def transaction_submitted_msg(tx: TransactionRecord) -> str:


def transaction_status_msg(fingerprint: int, tx_id: bytes32) -> str:
return f"Run 'chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id}' to get status"
return f"Run 'chia wallet get_transaction -f {fingerprint} -tx 0x{tx_id.hex()}' to get status"


async def validate_client_connection(
Expand Down
14 changes: 8 additions & 6 deletions chia/cmds/coin_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ async def async_combine(
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, tx_config, removals, final_fee
)
transaction: TransactionRecord = (
await wallet_client.send_transaction_multi(wallet_id, additions, tx_config, removals, final_fee)
).transaction
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}")
Expand Down Expand Up @@ -242,9 +242,11 @@ async def async_split(
# TODO: [add TXConfig args]
).to_tx_config(mojo_per_unit, config, fingerprint)

transaction: TransactionRecord = await wallet_client.send_transaction_multi(
wallet_id, additions, tx_config, [removal_coin_record.coin], final_fee
)
transaction: TransactionRecord = (
await wallet_client.send_transaction_multi(
wallet_id, additions, tx_config, [removal_coin_record.coin], final_fee
)
).transaction
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}")
Expand Down
86 changes: 37 additions & 49 deletions chia/cmds/dao_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ async def add_dao_wallet(args: Dict[str, Any], wallet_rpc_port: Optional[int], f
)

print("Successfully created DAO Wallet")
print("DAO Treasury ID: {treasury_id}".format(**res))
print("DAO Wallet ID: {wallet_id}".format(**res))
print("CAT Wallet ID: {cat_wallet_id}".format(**res))
print("DAOCAT Wallet ID: {dao_cat_wallet_id}".format(**res))
print(f"DAO Treasury ID: {res.treasury_id.hex()}")
print(f"DAO Wallet ID: {res.wallet_id}")
print(f"CAT Wallet ID: {res.cat_wallet_id}")
print(f"DAOCAT Wallet ID: {res.dao_cat_wallet_id}")


async def create_dao_wallet(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -98,10 +98,10 @@ async def create_dao_wallet(args: Dict[str, Any], wallet_rpc_port: Optional[int]
)

print("Successfully created DAO Wallet")
print("DAO Treasury ID: {treasury_id}".format(**res))
print("DAO Wallet ID: {wallet_id}".format(**res))
print("CAT Wallet ID: {cat_wallet_id}".format(**res))
print("DAOCAT Wallet ID: {dao_cat_wallet_id}".format(**res))
print(f"DAO Treasury ID: {res.treasury_id.hex()}")
print(f"DAO Wallet ID: {res.wallet_id}")
print(f"CAT Wallet ID: {res.cat_wallet_id}")
print(f"DAOCAT Wallet ID: {res.dao_cat_wallet_id}")


async def get_treasury_id(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -156,17 +156,16 @@ async def add_funds_to_treasury(args: Dict[str, Any], wallet_rpc_port: Optional[
).to_tx_config(units["chia"], config, fingerprint),
)

tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None

print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def get_treasury_balance(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -309,17 +308,16 @@ async def vote_on_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int],
}
).to_tx_config(units["chia"], config, fingerprint),
)
tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None

print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def close_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand All @@ -344,17 +342,16 @@ async def close_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int], f
}
).to_tx_config(units["chia"], config, fingerprint),
)
tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None

print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def lockup_coins(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand All @@ -378,17 +375,16 @@ async def lockup_coins(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp:
}
).to_tx_config(units["chia"], config, fingerprint),
)
tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None

print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def release_coins(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand All @@ -409,16 +405,15 @@ async def release_coins(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp
}
).to_tx_config(units["chia"], config, fingerprint),
)
tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None
print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def exit_lockup(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand All @@ -440,16 +435,15 @@ async def exit_lockup(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp:
}
).to_tx_config(units["chia"], config, fingerprint),
)
tx_id = res["tx_id"]
start = time.time()
while time.time() - start < 10:
await asyncio.sleep(0.1)
tx = await wallet_client.get_transaction(wallet_id, bytes32.from_hexstr(tx_id))
tx = await wallet_client.get_transaction(wallet_id, res.tx_id)
if len(tx.sent_to) > 0:
print(transaction_submitted_msg(tx))
print(transaction_status_msg(fingerprint, tx_id[2:]))
print(transaction_status_msg(fingerprint, res.tx_id))
return None
print(f"Transaction not yet submitted to nodes. TX ID: {tx_id}") # pragma: no cover
print(f"Transaction not yet submitted to nodes. TX ID: {res.tx_id.hex()}") # pragma: no cover


async def create_spend_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -496,13 +490,11 @@ async def create_spend_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[
}
).to_tx_config(units["chia"], config, fingerprint),
)
if res["success"]:
asset_id_name = asset_id if asset_id else "XCH"
print(f"Created spend proposal for asset: {asset_id_name}")
print("Successfully created proposal.")
print("Proposal ID: {}".format(res["proposal_id"]))
else: # pragma: no cover
print("Failed to create proposal.")

asset_id_name = asset_id if asset_id else "XCH"
print(f"Created spend proposal for asset: {asset_id_name}")
print("Successfully created proposal.")
print(f"Proposal ID: {res.proposal_id.hex()}")


async def create_update_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -541,11 +533,9 @@ async def create_update_proposal(args: Dict[str, Any], wallet_rpc_port: Optional
}
).to_tx_config(units["chia"], config, fingerprint),
)
if res["success"]:
print("Successfully created proposal.")
print("Proposal ID: {}".format(res["proposal_id"]))
else: # pragma: no cover
print("Failed to create proposal.")

print("Successfully created proposal.")
print(f"Proposal ID: {res.proposal_id.hex()}")


async def create_mint_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[int], fp: int) -> None:
Expand Down Expand Up @@ -573,8 +563,6 @@ async def create_mint_proposal(args: Dict[str, Any], wallet_rpc_port: Optional[i
}
).to_tx_config(units["chia"], config, fingerprint),
)
if res["success"]:
print("Successfully created proposal.")
print("Proposal ID: {}".format(res["proposal_id"]))
else: # pragma: no cover
print("Failed to create proposal.")

print("Successfully created proposal.")
print(f"Proposal ID: {res.proposal_id.hex()}")
Loading

0 comments on commit 628c9ca

Please sign in to comment.