Skip to content
Open
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
21 changes: 20 additions & 1 deletion allways/cli/swap_commands/post_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
print_contract_error,
resolve_source_tx_block,
)
from allways.cli.swap_commands.swap import from_smallest_unit, poll_for_swap_creation, sign_and_broadcast_confirm
from allways.cli.swap_commands.swap import (
from_smallest_unit,
poll_for_swap_creation,
resolve_recent_swap_id,
sign_and_broadcast_confirm,
)
from allways.constants import NETUID_FINNEY
from allways.contract_client import ContractError

Expand Down Expand Up @@ -70,6 +75,20 @@ def post_tx_command(tx_hash: str, tx_block: int):
return

if reserved_until <= current_block:
# reserved_until drops to 0 the moment the swap initiates (the contract clears
# the reservation row in vote_initiate), which by block number alone is
# indistinguishable from a genuine expiry. Check for a live swap first so we
# don't tell the user their reservation expired — and delete the pending
# record — when it actually advanced into a swap.
try:
swap_id = resolve_recent_swap_id(client, state.miner_hotkey)
except ContractError:
swap_id = None
if swap_id is not None:
clear_pending_swap()
console.print(f'\n[green]Your reservation has advanced into a swap. ID: {swap_id}[/green]')
console.print(f'[dim]Watch with: alw view swap {swap_id} --watch[/dim]\n')
return
clear_pending_swap()
console.print('[red]Reservation has expired.[/red]')
console.print('[dim]Run `alw swap now` to start a new swap.[/dim]')
Expand Down