Skip to content

feat: pay contacts via spark - #1191

Merged
ovitrif merged 86 commits into
feat/breez-spark-lightningfrom
feat/paykit-spark-route
Nov 11, 2026
Merged

ovitrif merged 86 commits into
feat/breez-spark-lightningfrom
feat/paykit-spark-route

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1244
Closes #1285

Twin: synonymdev/bitkit-android#1754
Dependency:

This PR routes every bitcoin Paykit contact payment through bitkit-core's Paykit router, so a wallet whose spending balance sits on Spark pays contacts directly over Lightning, or through a Spark withdrawal to a contact who only accepts on-chain bitcoin.

Description

  • Asks bitkit-core's router (paykitRoutePayment) how to pay every bitcoin contact payment: on the amount screen's Continue, when a payment request's Confirm opens with its fixed terms, and when the source is switched on Confirm. The router gets the contact's endpoints and what the selected source can spend:
    • Spending: all endpoints, the Lightning spendable (Spark included), and a Spark withdrawal leg for each on-chain endpoint when a Spark leg is offered.
    • Savings: the on-chain endpoints and the on-chain spendable.
    • USDT and hardware wallet payments keep their own flow.
  • Acts on the router's answer:
    • Direct pays the endpoint it names, switching the send to it when the scan opened another one.
    • Service opens Confirm with Route: Spark and the leg's fee. The swipe withdraws exactly the amount to the contact's address, so the contact receives exactly the amount entered.
    • None stays on the amount screen and shows "Insufficient balance" when the amount is above what the source can spend, or when Spark's balance can't cover the amount plus its fee; an LNURL whose limits refuse the amount shows its own too-low or too-high toast; else "Can't pay this contact" (translated in every locale). The router's reason goes to the log only.
  • Offers a Spark leg while Spark is ready with a sendable balance, for a payment to a contact with an on-chain endpoint, payment requests included; the router still pays directly when it can. A contact that also lists USDT, whose scan asks for an asset first, gets it too, and so does one that lists Lightning and on-chain endpoints, which opens on the amount screen. The leg counts Spark's L1 broadcast fee as well as its own, so Confirm shows the whole fee, and the withdrawal refuses a fee above the one Confirm showed.
  • Offers Spending as a source for an on-chain-only contact while Spark can carry the payment, whether or not Savings covers it; Spending is the default when Savings holds no more than dust. A request's Confirm opens from Savings when Savings can send the amount after the on-chain fee, else from Spending, where the Spark leg can pay it.
  • Pays an on-chain payment request from Spark: its on-chain proof starts before Spark sends and completes with the withdrawal's txid, and its payment check runs right before the send. A refusal by the send itself releases the request for another try.
  • Counts a Spark leg's amount and fee in Confirm's warnings, and saves the tags picked on Confirm on the withdrawal's activity.
  • Records a Spark withdrawal to a contact as an on-chain Sent activity for the contact with Spark's fee once Spark completes it, never as a transfer. Until then the send shows as pending. The Spark screen lists only real transfers.
  • Journals each withdrawal before it sends, and settles it from Spark's payment list after each Spark sync and when Spark connects:
    • It matches only the payment id Spark returned, or a withdrawal to the same address and amount not listed before the send.
    • It stays open until Spark completes the withdrawal and the activity, its tags and the request's proof are saved, so a failed write is retried; a second contact withdrawal is refused meanwhile, including while the first one prepares.
    • A withdrawal Spark refuses before sending closes as unsent at once. One Spark never returned, or reports as failed, closes as unsent, releasing the request; one never returned closes only when a successful sync still lacks it 10 minutes after the send.
  • Builds on bitkit-core 0.8.0-spark.3, a prerelease of feat: pay contacts via spark bitkit-core#193. No build flag.

What it needs to ship

  • Fees: Confirm shows the leg's fee under the Lightning "Instant" label, which reads as a Lightning fee.
  • Merge order: the dependencies above first; this branch stacks on them.

Out of Scope

  • Cancelling a sent one-time payment request: not supported on iOS on either rail, tracked separately.
  • A Spark-native Payment Endpoint: the Payment Endpoint Identifier spec has no Spark rail (section 5.2).
  • Translations of the settling message (wallet__send_paykit_withdrawal_settling__description): it is in English for now; translations follow in chore: translate spark strings #1270.

Design

N/A — no design available.

Preview

Two regtest wallets, A and B, each other's Paykit contacts, with their spending balance on Spark; one recording per wallet and flow, at 2x speed.

A pays contact B 200 sats over B's private endpoint; the router picks Lightning from Spending, and B's activity links it to A.

1. Private endpoint, payer A 1. Private endpoint, payee B
1191-p1-a2x.mp4
1191-p1-b2x.mp4

B's app is closed while A pays B 200 sats; on relaunch B shows it received from A, once.

2. Payee closed, payer A 2. Payee closed, relaunched, payee B
1191-p2-a2x.mp4
1191-p2-b2x.mp4

A pays the fixture-issuer, a contact with only an on-chain endpoint: Confirm shows Route: Spark with a 2,190-sat fee, and the Spark withdrawal pays 5,000 sats on chain.

3. On-chain-only contact via Spark, payer A
1191-p3-a2x.mp4

B requests 150 sats; A's Payment Request opens by itself and A pays it from Spark.

4. Request paid from Spark, payer A 4. Request paid from Spark, payee B
1191-p4-a2x.mp4
1191-p4-b2x.mp4

A requests 2,000 sats; B dismisses it from Payment Requests, and A's request reads Rejected.

5. Request rejected, payee A 5. Request rejected, payer B
1191-p5-a2x.mp4
1191-p5-b2x.mp4

B gives A a $1-a-payment allowance: A's 300-sat request is paid automatically, a 2,000-sat request asks B, and after B ends the allowance a 200-sat request asks B too.

6. Allowance, payee A 6. Allowance, allower B
1191-p6-a2x.mp4
1191-p6-b2x.mp4

B ends the allowance; A's next 200-sat request isn't paid automatically and asks B.

6. Allowance ended, payee A 6. Allowance ended, allower B
1191-p6e-a2x.mp4
1191-p6e-b2x.mp4

B proposes a monthly 120-sat subscription; A subscribes and pays the first period from Spark, and after both apps relaunch it is still active.

7. Subscription, subscriber A 7. Subscription, creator B
1191-p7-a2x.mp4
1191-p7-b2x.mp4

B requests $0.20; A's Payment Request shows it quoted at 269 sats and A pays it from Spark.

8. Fiat request, payer A 8. Fiat request, payee B
1191-p8-a2x.mp4
1191-p8-b2x.mp4

B turns private contact payments off and A can't pay B; B turns them on again and A pays B 100 sats.

9. Contact payments off and on, payer A 9. Contact payments off and on, payee B
1191-p9-a2x.mp4
1191-p9-b2x.mp4

An amount above A's 30,403 balance can't be entered (99,999 stops at 9,999); tapping Available fills the sendable maximum with the reserve kept, and A pays it to B.

10. Above the balance, then the maximum, payer A 10. Sendable maximum, payee B
1191-p10-a2x.mp4
1191-p10-b2x.mp4

A's app is killed 2 s after the swipe paying B 300 sats; B receives it once and A's balance drops once. A's Sent row appeared only after the next relaunch.

11. Kill mid-payment, payer A 11. Kill mid-payment, payee B
1191-p11-a2x.mp4
1191-p11-b2x.mp4

Screens

iPhone 17 Pro 2x simulator (iOS 27.0), dark mode; wallets A and B from the Preview (No route: B paying the on-chain-only fixture-issuer 70 sats), with Spark on Lightspark's hosted regtest and Pubky contacts on a local homeserver; no debug hooks.

Confirm
Lightning contact, paid from Spending On-chain contact, Route: Spark No route (the app's copy)
Activity
Contact payment via Spark (detail) On-chain contact payment via Spark (detail)
Spark screen
Transfers list without contact payments

QA Notes

Setup

  • Pubky stack: synonymdev/bitkit-docker main: docker compose up -d, then ./pubky-marketplace up and ./pubky-marketplace seed, then docker compose --profile marketplace --profile payment-requests up -d --no-build fixture-issuer rc56-peer; its fixture-issuer, which publishes only btc-regtest-p2wpkh, is the on-chain-only contact (J1, Preview 3).
  • App: xcodebuild build -project Bitkit.xcodeproj -scheme Bitkit -configuration Debug -destination 'platform=iOS Simulator,name=<simulator>' 'SWIFT_ACTIVE_COMPILATION_CONDITIONS=$(inherited) E2E_BUILD' E2E_BACKEND=local E2E_NETWORK=regtest E2E_HOMESERVER_PUBKY=$(./pubky-marketplace info | jq -r .homeserver_z32), installed on two simulators on the same Mac as bitkit-docker.
  • Wallets: each a new wallet with no channel, a Pubky profile on the local homeserver, and the other saved as a contact (bitkit://contact?pubky=<pubky>); save the fixture-issuer the same way, its pubky from curl 127.0.0.1:23012/health.
  • Spark: dev builds run Spark on Lightspark's hosted regtest, which needs no key. Fund Spending by sending 50,000 sats from Lightspark's web regtest faucet to the deposit address on Settings › Advanced › Lightning Connections › Spark, which Spark claims after one confirmation.
  • Two chains: the node and Spark run on different regtest chains, so a Spark withdrawal to a contact's address (J1) lands on Lightspark's chain; check it on Lightspark's regtest mempool. Savings stays empty here.

Journeys

  • J1: new paykit-spark-route.xml — a wallet whose spending balance is on Spark pays an on-chain-only contact through a Spark withdrawal, and the contact receives exactly 20,000 sats

Manual Tests

Paykit flows with the money in Spark, against the Paykit v0.1 specs (pubky/paykit-rs cb8cba5). Wallet state a is Spark only with no channel; state b is a channel too small for the amount with Spark covering the rest. Results are under Paykit flows with a Spark balance.

  • 1. Pay a contact's Lightning endpoint with an amount: private reserved endpoint, public endpoint.
  • 2. Pay an amountless Lightning endpoint.
  • 3. Pay a contact with only an on-chain endpoint through a Spark withdrawal.
  • 4. Pay a contact with both endpoints: Lightning when Spark covers it, else on-chain.
  • 5. Payment requests as payer: pay over Lightning and on-chain, reject, cancel before payment, refuse an expired one.
  • 6. Recurring requests and subscriptions paid from Spark, surviving restarts.
  • 7. Allowances: within the limit auto-pays from Spark, over it goes manual, an ended one doesn't pay.
  • 8. Payment conversion: a fiat request paid at its quote and deadline.
  • 9. Balance edges: above Spark plus channel refused, within 5 sats of Spark leaves fee room, Spark unavailable fails clearly.
  • 10. Kill the app mid-payment: settles once, no double pay.
  • 11. Spark-backed Lightning endpoint as payee: public and private, rotated after each payment, republished after relaunch.
  • 12. On-chain endpoint as payee.
  • 13. As payee, send a request (Lightning and on-chain); the contact pays, the proof is matched.
  • 14. Recurring payments received into Spark.
  • 15. Allowances as payee: the contact auto-pays our request into Spark.
  • 16. Cancel a request we sent.
  • 17. Endpoint toggles remove and republish the Spark-backed endpoint.
  • 18. Payee app closed while paid: linked on reopen, no duplicates.
  • 19. Spark-native endpoint.

Evidence

  • At db348780 and 0a47cc8d: the unit and UI suites pass on an iOS 27.0 simulator, including PaykitRouteTests, which runs bitkit-core's real router for Direct over Lightning from Spending, Direct on-chain from Savings, the Spark leg to an on-chain-only contact, and None, and covers the leg's broadcast fee and the contact withdrawal's activity. The on-chain Spark leg is driven on simulators in 3 and 10.
  • J1 at 27569ae on bitkit-core 0.8.0-swaps.3, before the router, on a regtest iPhone simulator (iOS 26.5):
    • the amount screen offered only Spending; Confirm showed Route: Spark and the leg's fee;
    • Bitcoin Sent showed ₿ 20,000;
    • Spark's withdrawal 49780e91… is confirmed on Lightspark's regtest chain and pays exactly 20,000 sats to the contact's address.

Paykit flows with a Spark balance

Two regtest iPhone 17 simulators (iOS 26.5) at 771b250f, and at 0a47cc8d for 5 reject, 6, 7 ended, 8, 9 within 5 sats, 14 and 17: RouteIosA and RouteIosB, each other's contacts, Spark on Lightspark's hosted regtest, about 2,000-3,000 sats each. Each payment was 100-300 sats. All results are in state a; state b is ⏭️ for every flow, since the setup has no channel.

  • ✅ 1, private: A paid RouteIosB 200; the router picked Direct over Lightning on private list v1; A Sent 200 (fee 1), B Received from RouteIosA, linked. ⏭️ public endpoint: Bitkit pays a saved contact only over the private path (with B's private sharing off and public on, A's payment was refused), and paying B's pubky by hand opens the saved contact; it needs a payer that hasn't saved the contact, not staged so the test contacts stay linked.
  • ✅ 2: the contact's private endpoint is an amountless Spark invoice; covered by 1, 13 and 18.
  • ✅ 3, at 6957828: A paid the on-chain-only RouteIosB 1,000 through a Spark withdrawal; Spending dropped by the amount plus the fee Confirm showed, Activity shows it as a Sent row for the contact, and B's address received exactly 1,000. Details and recording under Spark leg on simulators.
  • ✅ 4, partly: with RouteIosB accepting Lightning and on-chain, the router picked Lightning (1). ⏭️ the on-chain fallback: same cost as 3.
  • ✅ 5, Lightning: A's Payment Request Confirm opened from Spending, the router paid it Direct over Lightning, and B's request reads "Proof submitted". ⏭️ on-chain from Spark: same cost as 3; unit-tested in PaykitPaymentProofServiceTests (the withdrawal txid becomes the on-chain proof; a withdrawal that never went out drops its proof). ✅ reject: B dismissed RouteIosA's 2,000 request from the Payment Requests sheet; A's request reads Rejected, nothing paid. ⏭️ payee cancel before payment: iOS can't cancel a sent one-time request (see 16). ⏭️ expired: the shortest request expiry is 1 hour, not staged.
  • ✅ 6: a daily subscription each way, first period paid from Spark (A paid B's 120, B paid A's 110); after both apps relaunched, A shows it Active and B shows 1 subscriber, 1 payment. Later periods were not waited for.
  • ✅ 7: B gave RouteIosA $1 a payment, $10 a month; A requested 300 and B paid it from Spark automatically ("Paid automatically $0.23"); a 2,000 request (above $1 = 1,318 sats) stayed manual (amount_outside_range), nothing paid. After B ended the allowance ("Ended · $0.23 paid automatically"), A's 200 request stayed manual.
  • ✅ 8: B requested $0.20; A's Confirm showed it quoted at 264 sats and paid it from Spark; B received 264. Fixed-rate conversion only; Bitkit issues no per-period quotes.
  • ✅ 9, above the balance: typing 9999 against an Available of 2,531 stayed at 999; nothing sent. ✅ within 5 sats: with 2,470 in Spark, 2,466 can't be entered; the Available 2,454 paid with a 7-sat fee, leaving 9. ⏭️ Spark unavailable: the iOS simulator has no device-scoped offline switch, and the host's networking stays untouched.
  • ✅ 10, partly: A killed 0.3 s after the swipe; the kill landed before Spark dispatched: no new Sent row, Spending unchanged, no double pay. ✅ a kill after dispatch, at 6957828: A was terminated 0.24 s after Spark returned the withdrawal; after relaunch it was paid once, B's request reads Proof submitted, and the allowance still shows $0.00 paid automatically. Details and recordings under Spark leg on simulators.
  • ✅ 11, private: B's private endpoint rotated after each payment, A opening it on list versions 1, 2 and then 5, each landing in Spark and linked. ⏭️ public: sharing off.
  • 12, from the code (no on-chain receive was run): Bitkit publishes a node Savings address as each contact's reserved on-chain endpoint (PrivatePaykitAddressReservationStore), rotated once used, never Spark's static deposit address, which can't be rotated and needs a claim. The spec defines only the endpoint's value format (Payment Endpoint Identifier), not which wallet holds it, so this matches it.
  • ✅ 13, Lightning: B sent RouteIosA a 150-sat request and A paid it; B's request reads "Proof submitted" and Spending went up 150. ⏭️ on-chain: same cost as 3.
  • ✅ 14: the payee side of 6, each wallet receiving the other's first period into Spark.
  • ✅ 15: the payee side of 7; A's 300 request was auto-paid into A's Spark.
  • ⏭️ 16: not supported on iOS on either rail, tracked separately. Only subscriptions have a cancel.
  • ✅ 17: iOS has no Lightning-only toggle, so the contact-payments toggle was used: with B's sharing off, A got "Unable To Pay Contact"; turned back on, A paid B 100 on a new private list about 25 s later.
  • ✅ 18: with B's app terminated, A paid RouteIosB 100; on relaunch B showed Received from RouteIosA, linked, with no duplicate rows.
  • 19: not in spec. Payment Endpoint Identifier §5.2 lists no Spark rail, and §8 covers extensions; nothing was invented.

Spark leg on simulators

At 6957828, two iPhone 17 Pro 2x simulators (iOS 27.0), dark mode, plain Debug builds: Spark on Lightspark's hosted regtest, Pubky on staging. A held 19,901 sats on Spark. B published only its on-chain endpoint: iOS has no setting for that (Bitkit turns every payment option on at launch), so B ran this head with a local test-only change that reports its Lightning option as off. A ran this head unchanged. B's Savings is on Bitkit's staging chain, so each withdrawal is checked on Lightspark's regtest explorer.

🟢 3. On-chain-only contact through a Spark withdrawal, 10. Kill after dispatch
3. On-chain-only contact through a Spark withdrawal

A paid contact RouteIosB 1,000 sats from Spending. Confirm showed Route: Spark with a ₿ 2,190 fee and the "fee over 50%" check. After the swipe Spending went from 19,901 to 16,711 (1,000 + 2,190). Activity shows one "Sent to RouteIosB" row, on-chain, with payment 1,000, fee 2,190 and the contact; the Other tab is empty, so it is not a transfer. Withdrawal 8d214083… confirmed and pays exactly 1,000 to the address B published for A.

flow3-A2x.mp4

10. Kill after dispatch

A gave B a $5-a-payment, $50-a-month allowance (Active). B requested 1,000 sats, accepted in Savings only; with no Lightning endpoint the request opened as a manual Payment Request on A, from Spending with Route: Spark and a ₿ 2,190 fee. A watcher on A's log terminated Bitkit 0.24 s after "Sent Spark withdrawal", with the withdrawal still journaled. After relaunch:

  • Spending read 13,521, down 3,190 once; Activity has one new "Sent to RouteIosB" row (1,000, fee 2,190), now Confirmed.
  • B's address has one transaction, a8983800…, paying exactly 1,000; no second withdrawal.
  • The journal closed, and the proof went out after relaunch: B's request reads Proof submitted, and A lists it as paid (- ₿ 1,000).
  • The allowance stays Active · $5 a payment, with $0.00 paid automatically: the manual payment did not count against it.

Before this run, B's endpoint address was marked used on its own chain so B rotated it: on two chains B never sees the first payment, and A, correctly, does not reuse a used address. That staging payment is the "Received from RouteIosA + 1,000" row on B's Home in the payee clip; A's withdrawal is the explorer transaction above, which B's app can't see.

Allowance set, payer A Kill after dispatch and relaunch, payer A Request after the relaunch, payee B
flow10-A-1-allowance2x.mp4
flow10-A-2-kill2x.mp4
flow10-B2x.mp4

Automated Checks

  • ran the unit test selection of unit-tests.yml on an iOS 27.0 simulator at be2c54068: pass; SwiftFormat 0.64.6 lint and the translation check pass
  • ran the unit and UI suites of unit-tests.yml on an iOS 27.0 simulator at a2a34000: pass; SwiftFormat shows no new findings and the translation check passes
  • ran the unit test selection of unit-tests.yml on an iOS 26.5 simulator at 27569ae: passes apart from three date-bound PaykitPaymentProofServiceTests cases that master fixed in 421e152
  • updated PaykitPaymentProofServiceTests.swift: a Spark withdrawal's txid completes and submits the on-chain proof, completing it again is a no-op, and one that never went out drops its started proof
  • added PaykitRouteTests.swift: the leg's debit includes the L1 broadcast fee, a contact withdrawal is not marked as a transfer, what the router is asked from Spending and from Savings, the real router's Direct, Service and None outcomes, when a Spark leg is offered, the None copy's balance check, a journaled contact withdrawal matches only its own attempt, the journal stays open until every local record is saved, the leg prepares a request before its proof is started and frees it on a failure before the send, when a source switch on Confirm reroutes, when a request starts on Spending, that a refused send releases its own proof while an older journal is open, that an unlisted withdrawal is dropped only after the expiry, that Confirm offers Spending for an on-chain request Spark can pay, and that a stale withdrawal close publishes no resolution and leaves a retry's proof and allowance alone
  • no unit test drives the Breez SDK's quote or send: SparkManager talks to the SDK directly. The route's Direct-first quote and the mapping of Spark's payment status to settlement are unit tested.

Mainnet tests (run by the author)

These run on real devices with mainnet funds, by the author. Reviewers and review bots don't need to run them, and they don't block review.

Round 1

None yet: the flows above ran on regtest.

Round 2 (pending)

On the final heads, two mainnet wallets that are each other's Paykit contacts, small amounts.

  • Spark only, no channel: pay a contact's Lightning endpoint, both ways; Activity shows the contact and the fee.
  • A channel too small for the amount: the payment goes from Spark.
  • A contact with only an on-chain endpoint: paid through a Spark withdrawal, the fee includes the on-chain fee, and Activity shows the contact.
  • A payment request paid from Spark, over Lightning and on-chain: the payee's request shows paid and the proof matches.
  • An allowance: a request within it auto-pays from Spark, and the ledger shows it.
  • Receive: a contact pays our Spark-backed endpoint while the app is closed; on reopen it's linked to the contact and the endpoint has rotated.
  • Kill the payer mid-payment: on relaunch it settles once, with no double pay.
  • An amount above Spark plus the channel: refused with the app's copy, and nothing is spent.

Models used

  • Planning/scoping: claude-opus-5-5 (reasoning: medium), claude-sonnet-5-5 (reasoning: high)
  • Implementation: claude-opus-5-5 (reasoning: medium)
  • Review: Not performed

Taken from the run logs of every session and subagent that planned or wrote this PR, which record the model and reasoning effort per turn. The claude-sonnet-5-5 planning runs were research and spec-mapping subagents. No independent agent review was run on this PR.

@ovitrif

ovitrif commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 9d8ca9f: adds the paykit-spark-route.xml journey (J1), ported from synonymdev/bitkit-android#1754. Ran it on an iOS 26.5 simulator against Lightspark's hosted regtest. The router picked a Spark withdrawal, and 49780e91… pays exactly 20,000 sats to the contact. The recording, setup and evidence are in the description.

@ovitrif ovitrif added this to the 3.2.0 milestone Nov 3, 2026
@ovitrif

ovitrif commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Added to the 3.2.0 milestone: Spark via Breez SDK is the 3.2.0 highlight, and this PR stacks on #1128.

@ovitrif ovitrif changed the title feat: pay on-chain contacts from spark feat: pay contacts via spark Nov 3, 2026
A spending-only wallet pays a Paykit contact whose only endpoint is on-chain through a Pubky Swaps provider found among its contacts. Behind PUBKY_SWAPS_ROUTES on regtest debug builds. Uses bitkit-core 0.8.0-swaps.2.
@ovitrif
ovitrif force-pushed the feat/breez-spark-lightning branch from ffba7c7 to 0eed9c2 Compare November 5, 2026 02:10
@ovitrif
ovitrif force-pushed the feat/paykit-spark-route branch from f376aa7 to 438d6ae Compare November 5, 2026 02:10
@ovitrif

ovitrif commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Force-pushed: rebuilt on #1128's new head 0eed9c2a, with the same route changes (old head kept as backup/paykit-spark-route-20261105). The unit and UI suites pass at 438d6ae5; the description is updated.

@ovitrif ovitrif mentioned this pull request Nov 6, 2026
5 of 44 tasks
Moves to bitkit-core 0.8.0-spark.3 and its `paykitRoutePayment`, and removes the Pubky Swaps code: the build flags,
provider quotes, commit and claim, and their journey and changelog fragment.

- On the amount screen, every bitcoin contact payment asks the router how to pay from the selected source:
  Spending offers all of the contact's bitcoin endpoints and a Spark leg to its on-chain ones, Savings only the
  on-chain endpoints. Direct pays the endpoint it picks, a Spark leg opens Confirm with Route: Spark and its fee,
  and none stays on the amount screen with the app's copy, its reason going to the log only.
- An on-chain-only contact opens with Spending as a source while Spark can carry the payment, whether or not
  Savings covers it.
- A Spark withdrawal to a contact is journaled before it is sent, settles from Spark's payment list on its event
  or on the next start, and is recorded as a sent on-chain activity for the contact, confirmed once Spark
  completes it. A second one waits while the first is open.
- A payment request's Confirm, which opens with fixed terms and no amount screen, asks the router too: Direct
  switches the send to the endpoint it picks.
- An on-chain request can be paid from Spending through a Spark withdrawal. Its on-chain proof is started before
  Spark sends and completed with the withdrawal's txid, the request's payment check runs right before the send,
  and the withdrawal journal completes or drops the proof when the app stopped mid-send.
@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

This push merges the updated base, #1128 at 7ce626f, with no conflicts. It brings the restore-hold fixes from that PR's latest round; nothing in this PR changes.

re-review is needed only because of this push: da90a39...8354e2b

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked after 9 new commits (ca16cb5, f08a0a9, baa00f8, and 6 more). Nothing blocking remains.

addressed

  • A definite Spark refusal at send time is held as unknown for 10 minutes (Bitkit/Managers/SparkManager.swift:707). Fixed: withdrawalSendFailure (SparkManager.swift:811) now also treats isWithdrawalFeeRise (SparkManager.swift:823-826) as a definite refusal. It closes the journal and returns SparkWithdrawalNotSent, alongside the existing InsufficientFunds mapping. I checked the pinned 0.28.0 xcframework: it carries the text "The onchain fee rose to … Please re-prepare the payment." The linked SDK source returns it as InvalidInput from affordable_speed before withdraw. testADefiniteSparkRefusalClosesTheWithdrawalAtOnce passes locally.
  • A pending contact withdrawal is listed as a transfer to Savings on the Spark screen (Bitkit/Managers/SparkManager.swift:919-931). Fixed: withdrawals(_:) (SparkManager.swift:1300-1307) now skips the open journal's payment, matched by paymentId or, before Spark returns one, by address and amount. Its only UI consumer is SparkConnectionViews.swift:179-182. The .synced refresh that runs before settling also skips it, because the journal is still open then. testSparkScreenWithdrawalsLeaveOutAPendingContactPayment passes locally.
  • A second Spark contact withdrawal fails while the first is still pending (Bitkit/Managers/SparkManager.swift:772-777). Fixed: PaykitRouteService.route (PaykitRouteService.swift:122) throws SparkWithdrawalSettling before quoting a leg while a journal is open. routeContactPayment (PaykitRouteService.swift:345-364) then returns .refused with its own toast, after the balance and LNURL checks. So the amount screen stays put, and Confirm keeps the swipe off (da90a39). Both PaykitRouteSettlingTests pass locally. The new copy is untranslated; that is a separate finding.
  • Pending contact payments appear as transfers to Savings (Bitkit/Managers/SparkManager.swift:923-924). Fixed: Same fix as point 2. SparkManager.swift:1302-1304 removes the journaled payment from withdrawals, so the pending contact send no longer shows under Transfer to savings. That holds during the sync that completes it too. The added test passes locally.

new since the last review

worth doing, does not block

  • Settling copy added in English only, other locales show a mixed toast (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316)
  • The settling message lacks every non-English translation (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316)

@jvsena42 jvsena42 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-review of aedeee5a4, 1a3a1799f, e24e37cc7 and da90a393d (base merge 8354e2b21 had no conflicts): no findings. Approving.

  • da90a393d: refusedRouteSource is now set on every routing call (SendConfirmationView.swift:1487). A first refusal on a request's Confirm disables the swipe (:1340), blocks the automatic start (:629), and makes submitPayment throw (:1006). That closes the gap I'd traced: the swipe used to stay enabled and end on a mismatch error.
  • 1a3a1799f: the fee-rise refusal closes the journal at once. In breez spark-sdk 0.28.0 that InvalidInput is raised before spark_wallet.withdraw, so no withdrawal can be in flight.
  • e24e37cc7: the settling guard sits before leg quoting (PaykitRouteService.swift:122), with the same toast order as Android.
  • aedeee5a4: display only.

A first refusal now keeps the swipe off until the sheet is reopened, even if its cause was transient, such as a quote error. That is the behaviour pwltr asked for.

Device gate: no device check needed for this delta; paykit-spark-route.xml stays with e2e CI. SwiftFormat passes; Run Tests was still pending.

Reviewer model: Claude Fable 5.2 (claude-fable-5-2), Claude Opus 5.5 (claude-opus-5-5)
Reasoning effort: not exposed

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coreyphillips Resolved your two threads on the settling message's translations as out of scope: #1270 carries every Spark PR's translations in one follow-up and already lists this key. The body's Out of Scope now says so.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked after replies, with no new commit since 8354e2b. Nothing blocking remains.

still open

  • Settling copy added in English only, other locales show a mixed toast (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). e24e37c adds wallet__send_paykit_withdrawal_settling__description only to en.lproj (Localizable.strings:1316). The other 14 locales lack it, which node scripts/validate-translations.js --warnings confirms. t() falls back to English per key (LocalizeHelpers.swift:106-110). In German, for example, the toast would show the translated title "Zahlung an diesen Kontakt nicht möglich" over an English body. The PR's other new keys are translated in every locale, and CLAUDE.md asks for every *.lproj to be updated in the same PR. The validator exits 0 because missing translations are only warnings. Fix: add the key to the 14 other Localizable.strings files. Codex still sees it: Translation validation still reports all 14 missing locales for the key at Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316, despite exiting 0. The #1270 reply defers this non-blocking defect but does not fix or rebut it.
  • The settling message lacks every non-English translation (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). The new settling explanation appears in English in every other locale. While a contact withdrawal is pending, try paying another on-chain contact from Spending. This key exists only in en.lproj, so LocalizationHelper falls back to English. The translation check confirms it is missing from all 14 other locales. Codex still sees it: Bitkit/Services/PaykitRouteService.swift:361 still uses the missing translation, with English fallback confirmed at Bitkit/Utilities/LocalizeHelpers.swift:109. Tracking this duplicate defect in #1270 leaves the mixed-language toast unchanged.

@ovitrif
ovitrif dismissed coreyphillips’s stale review November 11, 2026 17:50

Superseded by the approval on 8354e2b (5862126124).

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coreyphillips Dismissed your changes request from before 8354e2b, since your approval on that head replaces it.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked after replies, with no new commit since 8354e2b. Nothing blocking remains.

still open

  • Settling copy added in English only, other locales show a mixed toast (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). e24e37c adds wallet__send_paykit_withdrawal_settling__description only to en.lproj (Localizable.strings:1316). The other 14 locales lack it, which node scripts/validate-translations.js --warnings confirms. t() falls back to English per key (LocalizeHelpers.swift:106-110). In German, for example, the toast would show the translated title "Zahlung an diesen Kontakt nicht möglich" over an English body. The PR's other new keys are translated in every locale, and CLAUDE.md asks for every *.lproj to be updated in the same PR. The validator exits 0 because missing translations are only warnings. Fix: add the key to the 14 other Localizable.strings files. HEAD and refs/pull/1191/head are still 8354e2b. wallet__send_paykit_withdrawal_settling__description is still only in en.lproj (Localizable.strings:1316). validate-translations.js --warnings still lists ar, ca, cs, de, el, es, es-419, fr, it, nl, pl, pt, pt-BR and ru as missing it. The description's Out of Scope bullet defers this to #1270, but that is a deferral, not a fix. The only reply is a dismissal of an earlier review and does not address the key.
  • The settling message lacks every non-English translation (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). The new settling explanation appears in English in every other locale. While a contact withdrawal is pending, try paying another on-chain contact from Spending. This key exists only in en.lproj, so LocalizationHelper falls back to English. The translation check confirms it is missing from all 14 other locales. This is the same gap as point 1, and nothing changed. The key exists only in en.lproj, and the validator still reports it missing from all 14 other locales. The toast at PaykitRouteService.swift:361 therefore still shows a translated title over an English body. The #1270 note in the description defers the work but does not settle it, and no reply in the thread addresses it.

pwltr
pwltr previously requested changes Nov 11, 2026

@pwltr pwltr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 8354e2b.

Medium — Reroute mixed-endpoint payments when switching to Spending on Confirm. Bitkit/Views/Wallets/Send/SendConfirmationView.swift:1115-1120 skips routing whenever a Lightning invoice or LNURL remains decoded. After routing a mixed contact directly from Savings, switching to Spending therefore misses an affordable Spark withdrawal when the amount exceeds Lightning's limit. Submission follows the direct-payment path instead. Reroute this source change so the selected funding source gets a fresh route.

Medium candidate — Verify blockchain inclusion before showing Confirmed. Bitkit/Managers/SparkManager.swift:965-966 and :1252-1255 mark the on-chain activity confirmed solely from Spark's completed status. If completed means provider payout acceptance before mining, the activity prematurely shows Confirmed. Establish the pinned SDK guarantee or obtain chain confirmation evidence before setting this flag.

Low candidate — Resolve an LNURL the router picks without retained decoded data. Bitkit/Services/PaykitRouteService.swift:389-394 refuses that choice instead of decoding it. Common mixed-contact initialization already decodes the endpoints, so natural reachability remains uncertain.

Review details

Quick review
Model: Claude Opus 5.5
Reasoning effort: high

General review
Model: GPT-6.1 Sol
Reasoning effort: high

Combined review
Model: GPT-6.1 Sol
Reasoning effort: high

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coreyphillips On the settling message's translations: I'm keeping translations out of the Spark PRs on purpose. They ship together in #1270, which lists wallet__send_paykit_withdrawal_settling__description with the other new keys, so this PR stays English-only for that key until then.

@coreyphillips coreyphillips left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rechecked after replies, with no new commit since 8354e2b. One point still blocks a merge.

still open

  • Settling copy added in English only, other locales show a mixed toast (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). e24e37c adds wallet__send_paykit_withdrawal_settling__description only to en.lproj (Localizable.strings:1316). The other 14 locales lack it, which node scripts/validate-translations.js --warnings confirms. t() falls back to English per key (LocalizeHelpers.swift:106-110). In German, for example, the toast would show the translated title "Zahlung an diesen Kontakt nicht möglich" over an English body. The PR's other new keys are translated in every locale, and CLAUDE.md asks for every *.lproj to be updated in the same PR. The validator exits 0 because missing translations are only warnings. Fix: add the key to the 14 other Localizable.strings files. Codex still sees it: The key remains English-only at Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316, and LocalizeHelpers.swift:106-110 still falls back to English. @ovitrif's comment defers the translations to #1270 but does not resolve the mixed-language toast.
  • The settling message lacks every non-English translation (Bitkit/Resources/Localization/en.lproj/Localizable.strings:1316). The new settling explanation appears in English in every other locale. While a contact withdrawal is pending, try paying another on-chain contact from Spending. This key exists only in en.lproj, so LocalizationHelper falls back to English. The translation check confirms it is missing from all 14 other locales. Codex still sees it: node scripts/validate-translations.js --warnings exits successfully but still reports this key missing from all 14 non-English locales. The comment acknowledges that gap and postpones it, so the point remains unresolved.

new since the last review

needs changing before merge

  • Switching to Spending can bypass the Spark fallback (Bitkit/Views/Wallets/Send/SendConfirmationView.swift:1115-1120)

worth doing, does not block

  • Switching Confirm to Spending skips the router while a Lightning endpoint is decoded (Bitkit/Views/Wallets/Send/SendConfirmationView.swift:545-548)

A switch to Spending on Confirm now always asks the router for a contact a Spark leg can reach, also when a decoded invoice or LNURL is kept from an earlier Savings pick, so an amount past Lightning's limit goes through an affordable Spark withdrawal. A Direct LNURL pick there continues on the LNURL's own confirm, since Confirm has no LNURL send.
Spark lists a withdrawal completed once its provider accepts the payout, before the payout transaction is broadcast or mined (spark-sdk 0.28.0, crates/spark/src/ssp/graphql/models.rs:187-209 and crates/breez-sdk/core/src/models/adaptors.rs:339-347). A contact withdrawal's activity now stays unconfirmed until Electrum lists its payout output in a block.
A route built after the scan, once Spark became ready, can hold a contact's LNURL that was never decoded. The router can pick it, so the pick now decodes it instead of refusing the payment.
Confirm's expanded details for a Spark leg now show the payment request's note, as the on-chain and Lightning details do.
@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Pushed 3a772cc: the latest review round, plus base synonymdev/bitkit-ios#1128 at 18946a0 merged in (no conflicts). Each fix has a test that failed first, except c8d16ff, which is a view change. The full BitkitTests suite passes (3,496 tests, 0 failures, with CI's skips), and SwiftFormat lint is clean. No new strings.

@pwltr (review 5863348355)

  • Re-route on a source switch: addressed in d1efd4f. Confirm now routes again when the source switches to Spending on a route that offers a Spark leg.
  • Confirmed before mined: addressed in 313c683. Spark reports a cooperative exit as completed once the operator accepts it, before it's on chain (graphql/models.rs#L187-L209). The activity is now confirmed only once Electrum shows the payout output mined. The Android twin is fixed in synonymdev/bitkit-android#1754 (f9ad00149).
  • LNURL without decoded data: addressed in 46ccee9. It's reachable when Spark becomes ready after the scan. An LNURL the router picks without decoded data is now decoded before paying. Android can't reach this, because it builds the route only after every endpoint is decoded.
  • Request note on a Spark leg: addressed in c8d16ff. The Spark leg's route view now shows the payment-request note.
  • From your Android review of the same journal (5849298774), the iOS twin: addressed in c2346f3. Each withdrawal passes a UUID idempotency key, which Spark keeps as the payment id, and the journal matches on that id. So a withdrawal Spark lists without details is no longer dropped after the 10-minute grace. The in-flight point from that review has no iOS gap: releaseContactWithdrawalClaim() runs in a defer, so the flag holds through recording.

@coreyphillips (review 5863666613)

  • Switching to Spending bypassing the Spark fallback, and the router skipped while a Lightning endpoint is decoded: both addressed in d1efd4f, and answered in their threads.
  • The settling text in English only: out of scope, tracked in synonymdev/bitkit-ios#1270. The key wallet__send_paykit_withdrawal_settling__description is listed there and in this PR's Out of Scope list. All Spark translations land together in that follow-up, to keep these PRs small.

Re-review is needed only because of this push: 8354e2b...3a772cc

@ovitrif
ovitrif dismissed stale reviews from pwltr and coreyphillips November 11, 2026 22:53

Addressed in d1efd4f..3a772cc; see the PR comment.

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merging this PR into feat/breez-spark-lightning with a merge commit. It's approved, CI is green on 3a772cc, no changes are requested and no thread is open. Its Closes lines (#1244, #1285) take effect when the base reaches master with synonymdev/bitkit-ios#1128.

synonymdev/bitkit-ios#1217 merges after this one, so it takes the Route and Exit join: a contact withdrawal is refused while an exit runs.

@ovitrif
ovitrif merged commit a82a6ef into feat/breez-spark-lightning Nov 11, 2026
11 checks passed
@ovitrif
ovitrif deleted the feat/paykit-spark-route branch November 11, 2026 23:53
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.

6 participants