Add local swap history with SQLite persistence#22
Open
eureka0928 wants to merge 1 commit intoentrius:testfrom
Open
Add local swap history with SQLite persistence#22eureka0928 wants to merge 1 commit intoentrius:testfrom
eureka0928 wants to merge 1 commit intoentrius:testfrom
Conversation
- Save swap receipts to ~/.allways/swap_history.db when swaps reach terminal state (completed/timed_out) or are initiated in non-interactive mode - alw view swap <id> auto-falls back to local history when swap is resolved on-chain, instead of showing "Swap resolved" with no details - alw view history shows all past swaps with --status, --limit, --swap filters - alw view history --stats shows aggregate summary (volume, success rate) - History captured from all touchpoints: swap now, swap resume, post-tx, and view swap --watch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When a swap completes or times out, the smart contract deletes it from on-chain storage. Running
alw view swap 42after resolution returns:No record of what was swapped, the rate applied, amounts, tx hashes, or when it happened. This PR adds local swap history so completed swaps are never lost.
What Changed
allways/cli/swap_commands/history.py(new) — SQLite persistence layer (~/.allways/swap_history.db). Stores all swap fields at terminal state. WAL mode,INSERT OR REPLACEfor safe dedup.allways/cli/swap_commands/view.py— Three additions:alw view swap <id>auto-falls back to local history when swap is resolved on-chainalw view historycommand with--swap,--status,--limit,--statsflagssave_to_history()/save_initiated_swap_to_history()helpersallways/cli/swap_commands/swap.py— Save to history in agent mode (--yes) where watch is skippedallways/cli/swap_commands/post_tx.py— Save to history after swap initiatedallways/cli/swap_commands/resume.py— Save to history in non-interactive modeHow It Works
Transparent fallback —
alw view swap 42just worksBefore (swap resolved on-chain):
After:
Browse all past swaps —
alw view historyFilter —
alw view history --status completedAggregate stats —
alw view history --statsAll flags
--swap <id>alw view history --swap 42--status <s>completedortimed_outalw view history --status completed--limit <n>alw view history --limit 5--statsalw view history --statsDesign Decisions
~/.allways/location.swap now(agent mode),swap resume,post-tx, andview swap --watch. Non-interactive flows save at initiation; watched flows update at terminal state.INSERT OR REPLACEhandles dedup.alw view swap <id>checks local history before showing "resolved" message. Users don't need to learn a new command for the common case.save_to_history()never raises. If SQLite write fails, the swap flow is unaffected.Limitation
History is per-machine (local SQLite). Same limitation as
pending_swap.json— right tradeoff for simplicity.Test Plan
alw view historyshows table of past swapsalw view history --swap 42shows full detail with all fieldsalw view history --status completedfilters correctlyalw view history --statsshows aggregate summaryalw view swap <id>falls back to local history when resolved on-chainalw swap now --yessaves initiated swap to history (agent mode)alw swap post-tx <hash>saves to historyruff checkandruff formatpass