Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHIA-431] Port chia wallet vcs ... to @tx_out_cmd #18062

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions chia/_tests/cmds/wallet/test_vcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ async def vc_mint(
tx_config: TXConfig,
target_address: Optional[bytes32] = None,
fee: uint64 = uint64(0),
push: bool = True,
) -> VCMintResponse:
self.add_to_log("vc_mint", (did_id, tx_config, target_address, fee))
self.add_to_log("vc_mint", (did_id, tx_config, target_address, fee, push))

return VCMintResponse(
[STD_UTX],
Expand Down Expand Up @@ -64,7 +65,7 @@ async def vc_mint(
f"Transaction {get_bytes32(2).hex()}",
]
run_cli_command_and_assert(capsys, root_dir, command_args, assert_list)
expected_calls: logType = {"vc_mint": [(did_bytes, DEFAULT_TX_CONFIG, target_bytes, 500000000000)]}
expected_calls: logType = {"vc_mint": [(did_bytes, DEFAULT_TX_CONFIG, target_bytes, 500000000000, True)]}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)


Expand Down Expand Up @@ -117,8 +118,11 @@ async def vc_spend(
new_proof_hash: Optional[bytes32] = None,
provider_inner_puzhash: Optional[bytes32] = None,
fee: uint64 = uint64(0),
push: bool = True,
) -> VCSpendResponse:
self.add_to_log("vc_spend", (vc_id, tx_config, new_puzhash, new_proof_hash, provider_inner_puzhash, fee))
self.add_to_log(
"vc_spend", (vc_id, tx_config, new_puzhash, new_proof_hash, provider_inner_puzhash, fee, push)
)
return VCSpendResponse([STD_UTX], [STD_TX])

inst_rpc_client = VcsUpdateProofsRpcClient() # pylint: disable=no-value-for-parameter
Expand All @@ -145,7 +149,15 @@ async def vc_spend(
run_cli_command_and_assert(capsys, root_dir, command_args, assert_list)
expected_calls: logType = {
"vc_spend": [
(vc_bytes, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), target_ph, new_proof, None, uint64(500000000000))
(
vc_bytes,
DEFAULT_TX_CONFIG.override(reuse_puzhash=True),
target_ph,
new_proof,
None,
uint64(500000000000),
True,
)
]
}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)
Expand Down Expand Up @@ -219,8 +231,9 @@ async def vc_revoke(
vc_parent_id: bytes32,
tx_config: TXConfig,
fee: uint64 = uint64(0),
push: bool = True,
) -> VCRevokeResponse:
self.add_to_log("vc_revoke", (vc_parent_id, tx_config, fee))
self.add_to_log("vc_revoke", (vc_parent_id, tx_config, fee, push))
return VCRevokeResponse([STD_UTX], [STD_TX])

inst_rpc_client = VcsRevokeRpcClient() # pylint: disable=no-value-for-parameter
Expand All @@ -242,8 +255,8 @@ async def vc_revoke(
expected_calls: logType = {
"vc_get": [(vc_id,)],
"vc_revoke": [
(parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000)),
(parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000)),
(parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000), True),
(parent_id, DEFAULT_TX_CONFIG.override(reuse_puzhash=True), uint64(500000000000), True),
],
}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)
Expand All @@ -260,6 +273,7 @@ async def crcat_approve_pending(
min_amount_to_claim: uint64,
tx_config: TXConfig,
fee: uint64 = uint64(0),
push: bool = True,
) -> List[TransactionRecord]:
self.add_to_log(
"crcat_approve_pending",
Expand All @@ -268,6 +282,7 @@ async def crcat_approve_pending(
min_amount_to_claim,
tx_config,
fee,
push,
),
)
return [STD_TX]
Expand Down Expand Up @@ -305,6 +320,7 @@ async def crcat_approve_pending(
reuse_puzhash=True,
),
uint64(500000000000),
True,
)
],
"get_wallets": [(None,)],
Expand Down
37 changes: 28 additions & 9 deletions chia/cmds/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -1386,16 +1386,18 @@ def vcs_cmd() -> None: # pragma: no cover
@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, default="0")
@tx_out_cmd
def mint_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
did: str,
target_address: Optional[str],
fee: str,
) -> None: # pragma: no cover
push: bool,
) -> List[TransactionRecord]:
from .wallet_funcs import mint_vc

asyncio.run(mint_vc(wallet_rpc_port, fingerprint, did, Decimal(fee), target_address))
return asyncio.run(mint_vc(wallet_rpc_port, fingerprint, did, Decimal(fee), target_address, push=push))


@vcs_cmd.command("get", short_help="Get a list of existing VCs")
Expand Down Expand Up @@ -1451,6 +1453,7 @@ def get_vcs_cmd(
default=False,
show_default=True,
)
@tx_out_cmd
def spend_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -1459,10 +1462,11 @@ def spend_vc_cmd(
new_proof_hash: str,
fee: str,
reuse_puzhash: bool,
) -> None: # pragma: no cover
push: bool,
) -> List[TransactionRecord]:
from .wallet_funcs import spend_vc

asyncio.run(
return asyncio.run(
spend_vc(
wallet_rpc_port=wallet_rpc_port,
fp=fingerprint,
Expand All @@ -1471,6 +1475,7 @@ def spend_vc_cmd(
new_puzhash=new_puzhash,
new_proof_hash=new_proof_hash,
reuse_puzhash=reuse_puzhash,
push=push,
)
)

Expand Down Expand Up @@ -1549,17 +1554,21 @@ def get_proofs_for_root_cmd(
default=False,
show_default=True,
)
@tx_out_cmd
def revoke_vc_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
parent_coin_id: Optional[str],
vc_id: Optional[str],
fee: str,
reuse_puzhash: bool,
) -> None: # pragma: no cover
push: bool,
) -> List[TransactionRecord]:
from .wallet_funcs import revoke_vc

asyncio.run(revoke_vc(wallet_rpc_port, fingerprint, parent_coin_id, vc_id, Decimal(fee), reuse_puzhash))
return asyncio.run(
revoke_vc(wallet_rpc_port, fingerprint, parent_coin_id, vc_id, Decimal(fee), reuse_puzhash, push=push)
)


@vcs_cmd.command("approve_r_cats", help="Claim any R-CATs that are currently pending VC approval")
Expand All @@ -1586,6 +1595,7 @@ def revoke_vc_cmd(
is_flag=True,
default=False,
)
@tx_out_cmd
def approve_r_cats_cmd(
wallet_rpc_port: Optional[int],
fingerprint: int,
Expand All @@ -1595,11 +1605,20 @@ def approve_r_cats_cmd(
min_coin_amount: Optional[Decimal],
max_coin_amount: Optional[Decimal],
reuse: bool,
) -> None: # pragma: no cover
push: bool,
) -> List[TransactionRecord]:
from .wallet_funcs import approve_r_cats

asyncio.run(
return asyncio.run(
approve_r_cats(
wallet_rpc_port, fingerprint, id, min_amount_to_claim, Decimal(fee), min_coin_amount, max_coin_amount, reuse
wallet_rpc_port,
fingerprint,
id,
min_amount_to_claim,
Decimal(fee),
min_coin_amount,
max_coin_amount,
reuse,
push,
)
)
44 changes: 32 additions & 12 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,13 @@ async def spend_clawback(


async def mint_vc(
wallet_rpc_port: Optional[int], fp: Optional[int], did: str, d_fee: Decimal, target_address: Optional[str]
) -> None: # pragma: no cover
wallet_rpc_port: Optional[int],
fp: Optional[int],
did: str,
d_fee: Decimal,
target_address: Optional[str],
push: bool,
) -> List[TransactionRecord]:
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config):
res = await wallet_client.vc_mint(
decode_puzzle_hash(ensure_valid_address(did, allowed_types={AddressType.DID}, config=config)),
Expand All @@ -1544,9 +1549,11 @@ async def mint_vc(
)
),
uint64(int(d_fee * units["chia"])),
push=push,
)

print(f"New VC with launcher ID minted: {res.vc_record.vc.launcher_id.hex()}")
if push:
print(f"New VC with launcher ID minted: {res.vc_record.vc.launcher_id.hex()}")
print("Relevant TX records:")
print("")
for tx in res.transactions:
Expand All @@ -1557,6 +1564,7 @@ async def mint_vc(
address_prefix=selected_network_address_prefix(config),
mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET),
)
return res.transactions


async def get_vcs(
Expand Down Expand Up @@ -1593,7 +1601,8 @@ async def spend_vc(
new_puzhash: Optional[str],
new_proof_hash: str,
reuse_puzhash: bool,
) -> None: # pragma: no cover
push: bool = True,
) -> List[TransactionRecord]:
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config):
txs = (
await wallet_client.vc_spend(
Expand All @@ -1604,10 +1613,12 @@ async def spend_vc(
tx_config=CMDTXConfigLoader(
reuse_puzhash=reuse_puzhash,
).to_tx_config(units["chia"], config, fingerprint),
push=push,
)
).transactions

print("Proofs successfully updated!")
if push:
print("Proofs successfully updated!")
print("Relevant TX records:")
print("")
for tx in txs:
Expand All @@ -1618,6 +1629,7 @@ async def spend_vc(
address_prefix=selected_network_address_prefix(config),
mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET),
)
return txs


async def add_proof_reveal(
Expand Down Expand Up @@ -1655,16 +1667,17 @@ async def revoke_vc(
vc_id: Optional[str],
fee: Decimal,
reuse_puzhash: bool,
) -> None: # pragma: no cover
push: bool,
) -> List[TransactionRecord]:
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, fingerprint, config):
if parent_coin_id is None:
if vc_id is None:
print("Must specify either --parent-coin-id or --vc-id")
return
return []
record = await wallet_client.vc_get(bytes32.from_hexstr(vc_id))
if record is None:
print(f"Cannot find a VC with ID {vc_id}")
return
return []
parent_id: bytes32 = bytes32(record.vc.coin.parent_coin_info)
else:
parent_id = bytes32.from_hexstr(parent_coin_id)
Expand All @@ -1675,10 +1688,12 @@ async def revoke_vc(
tx_config=CMDTXConfigLoader(
reuse_puzhash=reuse_puzhash,
).to_tx_config(units["chia"], config, fingerprint),
push=push,
)
).transactions

print("VC successfully revoked!")
if push:
print("VC successfully revoked!")
print("Relevant TX records:")
print("")
for tx in txs:
Expand All @@ -1689,6 +1704,7 @@ async def revoke_vc(
address_prefix=selected_network_address_prefix(config),
mojo_per_unit=get_mojo_per_unit(wallet_type=WalletType.STANDARD_WALLET),
)
return txs


async def approve_r_cats(
Expand All @@ -1700,7 +1716,8 @@ async def approve_r_cats(
min_coin_amount: Optional[Decimal],
max_coin_amount: Optional[Decimal],
reuse: bool,
) -> None: # pragma: no cover
push: bool = True,
) -> List[TransactionRecord]:
async with get_wallet_client(wallet_rpc_port, fingerprint) as (wallet_client, fingerprint, config):
if wallet_client is None:
return
Expand All @@ -1713,9 +1730,11 @@ async def approve_r_cats(
max_coin_amount=None if max_coin_amount is None else str(max_coin_amount),
reuse_puzhash=reuse,
).to_tx_config(units["cat"], config, fingerprint),
push=push,
)

print("VC successfully approved R-CATs!")
if push:
print("VC successfully approved R-CATs!")
print("Relevant TX records:")
print("")
for tx in txs:
Expand All @@ -1730,7 +1749,7 @@ async def approve_r_cats(
)
except LookupError as e:
print(e.args[0])
return
return txs

print_transaction(
tx,
Expand All @@ -1739,3 +1758,4 @@ async def approve_r_cats(
address_prefix=selected_network_address_prefix(config),
mojo_per_unit=mojo_per_unit,
)
return txs
Loading