Skip to content

Resume Boltz submarine swaps on 409#75

Draft
andycreed0x wants to merge 1 commit into
developfrom
resume_boltz_submarine_swap
Draft

Resume Boltz submarine swaps on 409#75
andycreed0x wants to merge 1 commit into
developfrom
resume_boltz_submarine_swap

Conversation

@andycreed0x

Copy link
Copy Markdown
Collaborator

Purpose

Add QR code reading capability (image → decoded string), a lightning decode CLI command to inspect BOLT11 invoices without paying them, and automatic recovery when Boltz returns a 409 "swap already exists" error by finding and resuming the existing local swap.

Main Changes

  • QR decode tool (src/aqua/qr.py) — decode_qr(image_path) using zxing-cpp + Pillow; 5/5 on real phone photos including logo-overlaid QR codes
  • MCP tool qr_decode — registered in tools.py + server.py; returns {"content": "<decoded_string>"}
  • CLI command aqua qr decode <image_path> — new cli/qr.py group registered in commands.py
  • lightning decode CLI commandaqua lightning decode --invoice lnbc... shows amount, description, expiry without paying
  • MCP tool lightning_decode — same capability exposed over MCP
  • 🏗️ src/aqua/bolt11.py — new module for BOLT11 protocol parsing (decode_bolt11_amount_sats, decode_bolt11_fields, bech32 tagged-field decoder); moved out of boltz.py to remove provider coupling and avoid circular import with lnurl.py
  • 🐛 Boltz 409 recovery_resume_existing_swap() in LightningManager: on duplicate invoice error, finds existing local swap, checks Boltz status, resumes if funded or re-funds if lockup address is stored
  • boltz_lockup_address field added to LightningSwap dataclass — persisted at swap creation so unfunded swaps can be re-funded on recovery
  • Storage.find_lightning_swap_by_invoice() — lookup swap by invoice string for 409 recovery
  • 🐛 BoltzSwapAlreadyExistsError — specific exception for Boltz 409 with a dedicated HTTP status mapping; replaces generic RuntimeError
  • Dependencies: zxing-cpp>=2.2, pillow>=10.0; removed opencv-python-headless (was 50MB, only needed for imread which Pillow handles)
  • ✅ New test files: tests/test_qr.py (5 tests), tests/test_cli.py

⚠️ Breaking Changes

  • LightningSwap.from_dict() now defaults boltz_lockup_address=None for backward compatibility with existing swap files — no migration needed

Checklist

  • Added/updated tests (if necessary)
  • Added/updated relevant documentation (if necessary)

@andycreed0x andycreed0x changed the base branch from develop to 74-add-qr-decode-to-send-pics-to-the-agents-and-it-can-pay-invoices May 22, 2026 22:04
@andycreed0x andycreed0x changed the title Add QR decode tool, lightning decode CLI, and resume Boltz submarine swaps on 409 Resume Boltz submarine swaps on 409 May 22, 2026
@andycreed0x

Copy link
Copy Markdown
Collaborator Author

This was for solving a bug that only happend once:

  • each time I wanted to pay a LN invoice, Boltz responded that invoice was was already being handled in other swap.
  • it got solved deleting AA and installing it again. This PR was a in-parallel trial for solving the same issue

Base automatically changed from 74-add-qr-decode-to-send-pics-to-the-agents-and-it-can-pay-invoices to develop June 4, 2026 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant