Skip to content

#137 lightning_refund fails: WalletManager._get_client() missing 'url' argument - #138

Merged
andycreed0x merged 2 commits into
developfrom
fix/137-lightning-refund-client
Oct 1, 2026
Merged

andycreed0x merged 2 commits into
developfrom
fix/137-lightning-refund-client

Conversation

@andycreed0x

Copy link
Copy Markdown
Collaborator

Walkthrough

Type: fix

lightning_refund failed on every attempt because the chain helpers added in #134 (get_block_height, get_transaction_hex, broadcast_raw_tx) still called _get_client(network), whose signature #131 (Airavata) changed to (network, url). The helpers now go through the backend fallback, and broadcast_raw_tx reuses the idempotent _broadcast. A live mainnet check then exposed a second bug hidden behind the first: lwk's EsploraClient has no get_tx, and every default Liquid backend is Esplora, so get_transaction_hex now reads GET {base}/tx/{txid}/hex over HTTP (Electrum overrides keep get_tx), with the same rules as tools._esplora_request: fall back on 5xx/429/network errors, and report "not found" only when every backend returns 404.

Closes #137

Changes

File What changes
src/aqua/wallet.py get_block_height → _with_client_fallback; broadcast_raw_tx → _broadcast (backend fallback + "already broadcast" = success); get_transaction_hex + new _fetch_tx_hex: HTTP for Esplora, get_tx for Electrum, with per-backend fallback.
tests/test_wallet.py New TestChainAccess (10 tests). It stubs _get_client(network, url) and urlopen instead of patching the helpers, so it catches both the signature mismatch and the missing get_tx. The existing refund tests in test_lightning.py mock the helpers and missed both.

Flow

sequenceDiagram
    participant CLI as lightning_refund
    participant LM as LightningManager
    participant WM as WalletManager
    participant BE as Liquid backends (Esplora)
    CLI->>LM: refund(swap_id)
    LM->>WM: get_transaction_hex(lockup_txid)
    WM->>BE: GET /tx/{txid}/hex (fallback on 5xx/429/404)
    BE-->>WM: raw hex
    LM->>WM: get_block_height()
    WM->>BE: tip() via _with_client_fallback
    LM->>WM: broadcast_raw_tx(refund_hex)
    WM->>BE: _broadcast (fallback, idempotent)
    BE-->>CLI: refund txid
Loading

Verification

  • Full suite: 1372 passed, 28 skipped. Ruff is clean on the touched files.
  • Live mainnet (tuna-test): get_block_height and get_transaction_hex return correct data through Airavata. broadcast_raw_tx reaches the backend and surfaces the node's real rejection.
  • Not verified: a full end-to-end refund. tuna-test has no refundable swap. Its old Boltz lockups were already claimed by the provider, and the Indra ones were already refunded.

🤖 Generated with Claude Code

get_block_height, get_transaction_hex and broadcast_raw_tx (added in #134)
still called _get_client(network), whose signature #131 changed to
(network, url), so every refund raised TypeError.

Route them through the backend fallback, reuse the idempotent _broadcast,
and read tx hex over HTTP for Esplora backends: lwk's EsploraClient has no
get_tx, and every default Liquid backend is Esplora.

Closes #137
@andycreed0x
andycreed0x marked this pull request as ready for review September 30, 2026 21:14
Electrum: lwk's ElectrumClient.get_tx never returns None; a missing tx
raises LwkError ("missing transaction", probed live on Blockstream's
Liquid Electrum). The old None check was dead, so a miss escaped as a
raw LwkError instead of the "Transaction ... not found" ValueError.
Recognize the miss and treat it like an Esplora 404. The test now raises
what lwk really raises instead of returning None.

Esplora: a 200 whose body is not tx hex (a proxy HTML page, a JSON
error, an empty or non-UTF-8 body) was returned as the lockup hex and
failed later inside wally.tx_from_hex, without trying the next backend.
Validate the body, record the backend as failed and fall back.
@marinate305

Copy link
Copy Markdown
Collaborator

@andycreed0x @TomasCast

Tested PR #138 on the fix branch — both issues resolved. MCP and CLI lightning_refund working correctly (cooperative refunds confirmed for swap IDs 1NLdmc6R and 1N4CK50F). Lightning send to Wallet of Satoshi also routing successfully via Indra now. One refund (1Nqv0DCV) kept locked on develop for post-merge verification. Ready to merge.

@TomasCast TomasCast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@andycreed0x
andycreed0x merged commit cf15f88 into develop Oct 1, 2026
1 check passed
@andycreed0x
andycreed0x deleted the fix/137-lightning-refund-client branch October 1, 2026 15:08
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.

3 participants