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-426] Port chia wallet clawback to @tx_out_cmd #18036

Merged
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
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
Loading