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

@eureka0928 eureka0928 commented Apr 10, 2026

Summary

When a swap completes or times out, the contract removes it from on-chain storage. alw view swap <id> previously showed a generic "Swap resolved" message with no details — users lost 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

  • 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 via the shared TAO_TO_RAO constant
    • 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 existing resolved-swap message
  • Tests: full coverage of field mapping, fallback swap ID, bad HTTP payloads, network errors, unsupported chains, unparseable integers

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 (10 tests)
  • Manual: `alw view swap <resolved_id>` shows full details from indexer
  • Manual: with `ALLWAYS_DAS_BASE_URL` set to invalid URL, falls back to the 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 5 times, most recently from c0a8b78 to d208503 Compare April 17, 2026 03:37
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 d208503 to f886495 Compare April 17, 2026 03:42
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