Skip to content

Commit

Permalink
[CHIA-426] Port chia wallet clawback to @tx_out_cmd (#18036)
Browse files Browse the repository at this point in the history
This brings another set of commands to the @tx_out_cmd decorator which
gives it the capability to optionally push a transaction and export the
transactions to a local file.
  • Loading branch information
Quexington committed May 17, 2024
2 parents 8f43e6c + a1bccab commit 6a51fdc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
17 changes: 14 additions & 3 deletions chia/_tests/cmds/wallet/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,21 @@ async def spend_clawback_coins(
coin_ids: List[bytes32],
fee: int = 0,
force: bool = False,
push: bool = True,
) -> Dict[str, Any]:
self.add_to_log("spend_clawback_coins", (coin_ids, fee, force))
self.add_to_log("spend_clawback_coins", (coin_ids, fee, force, push))
tx_hex_list = [get_bytes32(6).hex(), get_bytes32(7).hex(), get_bytes32(8).hex()]
return {"transaction_ids": tx_hex_list}
return {
"transaction_ids": tx_hex_list,
"transactions": [
STD_TX.to_json_dict_convenience(
{
"selected_network": "mainnet",
"network_overrides": {"config": {"mainnet": {"address_prefix": "xch"}}},
}
)
],
}

inst_rpc_client = ClawbackWalletRpcClient() # pylint: disable=no-value-for-parameter
test_rpc_clients.wallet_rpc_client = inst_rpc_client
Expand All @@ -528,7 +539,7 @@ async def spend_clawback_coins(
run_cli_command_and_assert(capsys, root_dir, command_args, ["transaction_ids", str(r_tx_ids_hex)])
# these are various things that should be in the output
expected_calls: logType = {
"spend_clawback_coins": [(tx_ids, 1000000000000, False)],
"spend_clawback_coins": [(tx_ids, 1000000000000, False, True)],
}
test_rpc_clients.wallet_rpc_client.check_log(expected_calls)

Expand Down
9 changes: 5 additions & 4 deletions chia/cmds/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,15 @@ def get_address_cmd(wallet_rpc_port: Optional[int], id: int, fingerprint: int, n
is_flag=True,
default=False,
)
@tx_out_cmd
def clawback(
wallet_rpc_port: Optional[int], id: int, fingerprint: int, tx_ids: str, fee: str, force: bool
) -> None: # pragma: no cover
wallet_rpc_port: Optional[int], id: int, fingerprint: int, tx_ids: str, fee: str, force: bool, push: bool
) -> List[TransactionRecord]:
from .wallet_funcs import spend_clawback

asyncio.run(
return asyncio.run(
spend_clawback(
wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=Decimal(fee), tx_ids_str=tx_ids, force=force
wallet_rpc_port=wallet_rpc_port, fp=fingerprint, fee=Decimal(fee), tx_ids_str=tx_ids, force=force, push=push
)
)

Expand Down
17 changes: 12 additions & 5 deletions chia/cmds/wallet_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1457,20 +1457,27 @@ async def sign_message(


async def spend_clawback(
*, wallet_rpc_port: Optional[int], fp: Optional[int], fee: Decimal, tx_ids_str: str, force: bool = False
) -> None: # pragma: no cover
*,
wallet_rpc_port: Optional[int],
fp: Optional[int],
fee: Decimal,
tx_ids_str: str,
force: bool = False,
push: bool = True,
) -> List[TransactionRecord]:
async with get_wallet_client(wallet_rpc_port, fp) as (wallet_client, _, _):
tx_ids = []
for tid in tx_ids_str.split(","):
tx_ids.append(bytes32.from_hexstr(tid))
if len(tx_ids) == 0:
print("Transaction ID is required.")
return
return []
if fee < 0:
print("Batch fee cannot be negative.")
return
response = await wallet_client.spend_clawback_coins(tx_ids, int(fee * units["chia"]), force)
return []
response = await wallet_client.spend_clawback_coins(tx_ids, int(fee * units["chia"]), force, push=push)
print(str(response))
return [TransactionRecord.from_json_dict_convenience(tx) for tx in response["transactions"]]


async def mint_vc(
Expand Down
2 changes: 2 additions & 0 deletions chia/rpc/wallet_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ async def spend_clawback_coins(
coin_ids: List[bytes32],
fee: int = 0,
force: bool = False,
push: bool = True,
extra_conditions: Tuple[Condition, ...] = tuple(),
timelock_info: ConditionValidTimes = ConditionValidTimes(),
) -> Dict[str, Any]:
Expand All @@ -307,6 +308,7 @@ async def spend_clawback_coins(
"fee": fee,
"force": force,
"extra_conditions": conditions_to_json_dicts(extra_conditions),
"push": push,
**timelock_info.to_json_dict(),
}
response = await self.fetch("spend_clawback_coins", request)
Expand Down

0 comments on commit 6a51fdc

Please sign in to comment.