Skip to content

Resolve off-chain swaps via Allways DAS indexer#31

Open
eureka0928 wants to merge 1 commit intoentrius:testfrom
eureka0928:feat/cli-view-swap-indexer
Open

Resolve off-chain swaps via Allways DAS indexer#31
eureka0928 wants to merge 1 commit intoentrius:testfrom
eureka0928:feat/cli-view-swap-indexer

Conversation

@eureka0928
Copy link
Copy Markdown
Contributor

Summary

When a swap completes or times out, the contract removes it from on-chain storage. Currently alw view swap <id> shows a generic "Swap resolved" message with no details — users lose visibility into their swap history.

This PR adds a lightweight fallback to the existing Allways DAS (indexer) API so resolved swaps are displayed with full details instead of a dead-end message.

  • No new infrastructure — uses the already-deployed indexer at test-api.all-ways.io
  • Best-effort only — if the indexer is unreachable or returns bad data, the existing "resolved" message is shown as before
  • Zero impact on happy path — DAS is only called when get_swap() returns None

Changes

Commit 1: Resolve off-chain swaps via Allways DAS indexer

  • New allways/cli/das_api.py — thin client for GET /swaps/{id}, maps indexer JSON to the existing Swap dataclass
    • TAO decimal string → rao conversion (_tao_decimal_to_rao)
    • Validates chains against SUPPORTED_CHAINS
    • Configurable base URL via ALLWAYS_DAS_BASE_URL env var
    • Returns None on any transport/parse error (never raises)
  • Modified allways/cli/swap_commands/view.py — when get_swap() returns None, tries fetch_swap_from_das() before falling back to the old message
  • Tests: full coverage of field mapping, fallback ID, bad payloads, network errors, unsupported chains, unparseable integers

Commit 2: Clarify SwapTracker docs and add unit tests

  • Expanded SwapTracker docstring explaining window pruning, voted_ids lifecycle, and cold-start behavior
  • Tests: _resolved_block ordering, window pruning, voted_ids cleanup on swap resolution

Example

Before:

$ alw view swap 1
Swap 1 has been resolved (completed or timed out).
Resolved swaps are removed from on-chain storage.

After:

$ alw view swap 1
Swap no longer on-chain; showing indexer record.

Swap #1 — COMPLETED

  BTC -> TAO | 0.005 BTC -> 1.72650000 TAO | Rate: 345.3

  Timeline:
    ● Initiated      Block 8000
    ● Fulfilled       Block 8050
    ● Completed       Block 8120
    ⏱ Timeout        Block 9000

  Source TX: abc123...
  Dest TX:   def456...

  User:    5GrwvaEF...
  Miner:   5FHneW46...

Test plan

  • pytest tests/test_das_api.py -v — DAS client mapping and error handling
  • pytest tests/test_swap_tracker.py -v — SwapTracker pruning and voted_ids cleanup
  • Manual: alw view swap <resolved_id> shows full details from indexer
  • Manual: with ALLWAYS_DAS_BASE_URL set to invalid URL, falls back to existing message

@eureka0928
Copy link
Copy Markdown
Contributor Author

Hi @LandynDev I put the new PR based on your comments from closed one
Thank you for your time
Let me know if there is any feedback

@eureka0928 eureka0928 force-pushed the feat/cli-view-swap-indexer branch from 906e424 to 035daa2 Compare April 10, 2026 17:41
When a swap is no longer in contract storage (completed or timed out),
alw view swap <id> now fetches details from the Allways Data Access
Service (indexer API) instead of showing a bare "Swap resolved" message.

- Add das_api.py: API client for the DAS /swaps/{swapId} endpoint
- Fallback in view swap: try DAS when contract returns None
- Configurable via ALLWAYS_DAS_BASE_URL env var (default: test-api.all-ways.io)
- Full test coverage for field mapping, error handling, and edge cases
@eureka0928 eureka0928 force-pushed the feat/cli-view-swap-indexer branch from 035daa2 to 4055aeb Compare April 14, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant