Skip to content

feat(swift-sdk): persist and resume the Platform addresses an external asset lock pays - #6272

Draft
romchornyi wants to merge 27 commits into
feat/platform-wallet-asset-lock-intentfrom
feat/swift-sdk-platform-address-external-funding
Draft

romchornyi wants to merge 27 commits into
feat/platform-wallet-asset-lock-intentfrom
feat/swift-sdk-platform-address-external-funding

Conversation

@romchornyi

@romchornyi romchornyi commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Issue being fixed or feature implemented

#5930 lets the wallet fund Platform addresses it does not own from an asset lock, and records those recipients so that a resume of the lock pays exactly them. This PR is the Swift host side: the SDK persists and reads the recorded recipients, and the example app resumes such a lock to its recorded payees. It also fixes two example-app defects found while reviewing #5930 (review threads 4622517171 and 4622517179).

Stacked: the base is #5930 (feat/platform-wallet-asset-lock-intent), and the branch merges #6139 (Swift port of #5931). GitHub's diff therefore also shows the #6139 commits until #6139 lands. The commits of this PR are the five listed below. Merge order: #5931 → #5930 and #6139 → this PR.

What was done?

  • 92e361ea71 feat(swift-sdk):
    • stores the opaque recipient record on PersistentAssetLock.platformAddressRecipients (live V5 schema) through on_persist/on_load_asset_lock_platform_address_recipients, inside the handler's atomic changeset;
    • attests ASSET_LOCK_PLATFORM_ADDRESS_RECIPIENTS (bit 18) next to ATOMIC_CHANGESETS and ASSET_LOCK_FUNDING_INDICES;
    • the recorded recipients never change, and reading a missing row fails;
    • adds TrackedAssetLock.hasPlatformAddressRecipients, ManagedPlatformWallet.assetLockPlatformAddressRecipients(txid:vout:) and ManagedPlatformAddressWallet.resumeFundFromAssetLockToRecordedRecipients.
  • 89a4efaf89 feat(swift-example-app):
    • the top-up resume form sends a lock that has recorded recipients to resumeFundFromAssetLockToRecordedRecipients, and shows the recorded payees in place of the address picker;
    • the funding coordinator keys its slots, rows and dismiss calls on the lock's outpoint;
    • when an external resume completes, the screen shows "Payment completed" without a balance line.
  • c9244309fd fix(swift-example-app): a failed payee lookup is no longer shown as "no recorded recipients":
    • the read has its own states (waiting for the wallet, loading, loaded, not found, failed);
    • it runs off the main actor and restarts once the wallet is available;
    • a failure offers Retry;
    • confirmation stays disabled until the payees are loaded.
  • 5512794ccd fix(swift-example-app): when a funding result carries no update for the picked address, the screen no longer reports a balance of 0. AddressFundFromAssetLockController.reportedBalance keeps the missing update as nil.
  • b754d122b4 docs(swift-sdk): adds the parity-manifest entry platform_address.external_funding_recorded_recipients and the asset_lock_platform_address_recipients persistence capability, and regenerates PARITY_SUMMARY.md.

Parity manifest merge rule: the Kotlin counterpart (#6273) adds the same platform_address.external_funding_recorded_recipients entry. Whichever PR merges second takes the Swift host block from this PR and the Kotlin host block from the other, combines both verification lists, and then regenerates the summary with python3 scripts/check_sdk_parity_manifest.py --write-summary.

How Has This Been Tested?

  • SwiftDashSDK unit tests: 30 passed.
  • SwiftExampleApp unit tests: 269 passed, 0 failed (iOS simulator).
  • scripts/check_sdk_parity_manifest.py passes.

Breaking Changes

None beyond #5930. The persister gains two optional callbacks, and bit 18 is declared only when they are wired.

Checklist:

  • I have performed a self-review of my own code
  • My Rust, FFI, WASM, Swift or Kotlin changes follow the coding conventions
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request
  • If I added or changed a system contract's document schemas, I checked the contract viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

romchornyi and others added 11 commits November 25, 2026 00:51
…lock

PersistentAssetLock gains identityRecipient (32 bytes, nullable column in
the live, unpublished V5 schema). The persistence handler wires
on_persist/on_load_asset_lock_identity_recipient_fn: a repeat of the
recorded identity is accepted, a different one fails the round, a
conflicting value on a consumed row is dropped (as the SQLite store does),
upserts never replace a recorded value, and a missing row or a malformed
value fails the load. The handler now declares
ASSET_LOCK_IDENTITY_RECIPIENTS (bit 17).

Part of #5924 (PR C).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ManagedPlatformWallet binds the three exports from #5931:
- topUpExternalIdentityWithFunding wraps
  platform_wallet_top_up_external_identity_with_funding_signer and hands
  the built lock's outpoint to onAssetLockBuilt after the native call,
  on failure as well as success; it is not called when nothing was built.
- resumeTopUpToRecordedRecipient wraps
  platform_wallet_resume_identity_top_up_to_recorded_recipient_signer and
  returns the identity paid and its new balance.
- assignTopUpRecipient wraps platform_wallet_assign_identity_top_up_recipient.

Error code 81 maps to PlatformWalletError.assetLockRecipientUnknown, and the
docs of code 61 cover identity recipients. Both tracked-lock lists carry
identityRecipient and identityRecipientUnassigned.

Part of #5924 (PR C).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds identity.top_up_any_identity_from_core (Swift SDK partial, Swift
example app and Kotlin unsupported on this base), declares
asset_lock_identity_recipients and lists the three new exports.
PARITY_SUMMARY.md regenerated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…top-up

The retry guidance of `topUpExternalIdentityWithFunding` sent
`transactionBroadcastUnconfirmed` (20) to "any other error", where a resume
answering `assetLockNotTracked` licensed a new lock. After 20 the lock may be
on the network, or its row may come back after a restart with its inputs
still reserved, so a new lock could pay the identity twice. Code 20 now has
its own branch, as in the FFI doc: resume that outpoint, never build a new
lock.

Also:
- `IdentityTopUpResult.newBalance` says what a managed identity returns: the
  proved balance or a newer verified one the wallet already holds.
- Code 81 and the resume doc no longer promise that a lock rebuilt from the
  chain can be assigned; assignment refuses it (`assetLockConsumptionUnknown`).
- `PersistentAssetLock.identityRecipient` is `public internal(set)`: only the
  SDK writes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…knowledged unknown consumption

#5931 gave platform_wallet_assign_identity_top_up_recipient an
acknowledge_unknown_consumption flag and a new code 82
(ErrorAssetLockConsumptionUnknown). assignTopUpRecipient takes
acknowledgeUnknownConsumption (default false) and passes it through, and code
82 maps to PlatformWalletError.assetLockConsumptionUnknown, as #5933 does on
Kotlin.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…asset lock pays

Store the opaque recipient record of an external Platform-address funding
on PersistentAssetLock.platformAddressRecipients (live V5 schema) through
the new on_persist/on_load_asset_lock_platform_address_recipients slots,
inside the handler's atomic changeset, and attest
ASSET_LOCK_PLATFORM_ADDRESS_RECIPIENTS (bit 18) next to the already
declared ATOMIC_CHANGESETS and ASSET_LOCK_FUNDING_INDICES. Recorded
recipients never change, and a read of a missing row fails.

Expose TrackedAssetLock.hasPlatformAddressRecipients,
ManagedPlatformWallet.assetLockPlatformAddressRecipients(txid:vout:) and
ManagedPlatformAddressWallet.resumeFundFromAssetLockToRecordedRecipients,
and document that such a lock resumes only to its recorded recipients.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d payees, keyed by its lock

The Platform top-up resume form routes a lock that recorded Platform-address
recipients to resumeFundFromAssetLockToRecordedRecipients: it shows the
recorded payees (each amount and the remainder) in place of the address
picker, and enables "Complete External Payment" only once they are
shown. The funding coordinator's slots, row ids and dismiss calls also key
on the resumed lock's outpoint, because an external payment does not
credit the picked address and a later resume of another lock may pick it
again. Completed carries an optional balance and shows "Payment completed"
without a balance line for an external resume, and the consumed-row
recipient backfill skips such a lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… without recorded payees

The external resume form read the recorded payees once, on appear, with
try?: a failed read and a wallet the manager had not loaded yet both
showed "no longer carries its recorded recipients", and nothing read them
again. The read now has its own states (waiting for the wallet, loading,
loaded, not found, failed), runs off the main actor, restarts when the
wallet becomes available, and offers Retry after a failure.
Confirmation stays disabled until the payees are loaded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…address funding returns no update

The owned resume and the fresh funding closures substituted 0 when the
result carried no update for the picked address, which reconciliation
returns when sync already applied the balance, so Completed showed a
balance of 0. Both now go through
AddressFundFromAssetLockController.reportedBalance, which keeps the
missing update as nil, and Completed shows no balance line, as it does
for an external resume.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… external funding in the parity manifest

Add the platform_address.external_funding_recorded_recipients capability
(Swift SDK and example app partial, Kotlin unsupported on this branch), the
asset_lock_platform_address_recipients persistence capability and the three
shared symbols it uses, and regenerate PARITY_SUMMARY.md.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

🕓 Review not started yet because this PR is a draft.

  • Request normal review — click when the PR is ready for review.
  • Request priority review — click to move this review to the front of the queue.

Commit e89fd2f. Normal review starts when eligible; priority review starts as soon as a slot is available.

@thepastaclaw thepastaclaw 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.

Final validation — Phase 2 only (queue backlog)

Changes requested: 1 blocker

  • An external payment cannot resume without an unused local address — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift:594-602 (new)
    Impact: A sender who opens a pending external payment can see all its recorded payees but cannot complete it if the selected account has no unused, zero-balance address.

This PR adds SwiftData persistence for the recipients of an external Platform-address asset lock and lets the Swift example app resume that lock through Rust without supplying new recipients. The Kotlin SDK build and tests and the SwiftData explorer check passed, and the automated review check is pending. GitHub does not list a Swift simulator test job for this head; the simulator results are author-reported, and this verification was static.

🔴 1 blocking | 🟡 8 suggestion(s)

2 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: An active resume appears twice and disables Resume for unrelated locks
Impact: While one resumed lock is waiting for finality, a user returning to the pending list can see that lock counted twice and cannot resume a different proof-ready lock in the same wallet.
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift:69-81

A single active resume can make unrelated payments wait. The exclusion set is always empty because compactMap returns nil for every controller, and hasActiveFunding disables Resume for every remaining row. Resumed controllers now expose assetLockOutPoint, so exclude only the matching rows for active controllers with known outpoints. Keep the conservative wallet-wide guard for active fresh funding with an unknown outpoint, and leave failed locks eligible for retry.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

🟡 Suggestion: Resume progress can show a different lock’s finality state
Impact: A sender resuming an older broadcast lock can see “Building asset-lock transaction” instead of the finality wait if a newer, consumed lock sorts first.
packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/AddressFundFromAssetLockProgressView.swift:124-135

The progress screen can describe an operation the current lock is not performing. The query includes all type-4 rows for the wallet and sorts them by updatedAt; both the current-step and skipped-step checks then use activeLocks.first. When the controller has an assetLockOutPoint, select that exact row for every progress calculation. Use the current fallback only for fresh funding whose outpoint is not yet known.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 10: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff makes an intricate change to funds movement: ManagedPlatformAddressWallet.resumeFundFromAssetLockToRecordedRecipients routes resumed payments to payees recovered through PlatformWalletPersistenceHandler, so correct persistence and outpoint matching determine who gets paid.
  • Phase 1 reviewers: not run (skipped for throughput: 15 PRs queued, above the 10 limit)
  • Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift:594-602: An external payment cannot resume without an unused local address
  Impact: A sender who opens a pending external payment can see all its recorded payees but cannot complete it if the selected account has no unused, zero-balance address.
  The recovery screen can leave an already-funded lock unsubmitted even when the wallet still holds its recorded remainder address. `canSubmit` requires a selected address, and `submit()` looks it up again among unused, zero-balance addresses before reaching the external branch, where the address picker is hidden. The SDK call passes neither that address nor the selected account: Rust finds the account that holds the recorded remainder, which need not be unused. Handle external recovery before both picker guards, key its controller by wallet and outpoint alone, and test submission with loaded payees and an empty candidate list.
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift:411-417: The confirmation screen hides the full payee address and rounds the recorded amount
  Impact: A sender checking an interrupted payment cannot compare the full recorded address or exact credit amount with the original payment request.
  The confirmation cannot distinguish different destinations or amounts that render the same way. `hexShort` shows only six leading and six trailing hash digits and omits the address type; `formatCredits` rounds to six DASH decimal places, so 500,000 and 500,001 credits display identically. Use the SDK’s network-aware address formatter to show the full typed address and make it copyable. Show exact integer credits alongside any rounded DASH value, and keep the remainder labeled separately.
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift:445-449: The inline resume sheet can omit its completion or failure controls
  Impact: A user who stays on the resume sheet can see the progress steps change without getting the corresponding Done or Dismiss button until another update redraws the sheet.
  The inline terminal section can stay in its in-flight state after Rust returns. The sheet holds the controller in `@State`, which observes replacement of the reference, not its `@Published phase`; `.onChange(of:)` does not add that subscription. The progress child observes the controller, but that does not invalidate the parent. An early failure, for example, need not change any of the parent’s queried rows. Render the terminal controls from a view observing the controller with `@ObservedObject`, as the standalone progress screen does.

In `packages/swift-sdk/Sources/SwiftDashSDK/Persistence/Models/PersistentAssetLock.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/Persistence/Models/PersistentAssetLock.swift:256: A SwiftData model edit can erase a lock’s recorded payment intent
  Impact: An SDK host that clears and saves this field on a pending lock can make the next wallet restore treat the external payment as eligible for an owned-address resume.
  Recovery cannot tell that the original payees were erased. The public setter bypasses the recipient callback’s conflict check; the load callback reports a cleared value as absent, and Rust accepts that as a legitimate legacy or owned lock. No current SDK callback clears the field, but client code can do so through an ordinary model assignment. Give the field the same externally read-only access as `identityRecipient`. Keep the checked sidecar as the writer: `persistAssetLocks` also gives incoming non-nil bytes precedence over stored bytes, even though its current FFI caller does not populate that field.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift:69-81: An active resume appears twice and disables Resume for unrelated locks
  Impact: While one resumed lock is waiting for finality, a user returning to the pending list can see that lock counted twice and cannot resume a different proof-ready lock in the same wallet.
  A single active resume can make unrelated payments wait. The exclusion set is always empty because `compactMap` returns `nil` for every controller, and `hasActiveFunding` disables Resume for every remaining row. Resumed controllers now expose `assetLockOutPoint`, so exclude only the matching rows for active controllers with known outpoints. Keep the conservative wallet-wide guard for active fresh funding with an unknown outpoint, and leave failed locks eligible for retry.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/AddressFundFromAssetLockProgressView.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/AddressFundFromAssetLockProgressView.swift:124-135: Resume progress can show a different lock’s finality state
  Impact: A sender resuming an older broadcast lock can see “Building asset-lock transaction” instead of the finality wait if a newer, consumed lock sorts first.
  The progress screen can describe an operation the current lock is not performing. The query includes all type-4 rows for the wallet and sorts them by `updatedAt`; both the current-step and skipped-step checks then use `activeLocks.first`. When the controller has an `assetLockOutPoint`, select that exact row for every progress calculation. Use the current fallback only for fresh funding whose outpoint is not yet known.

In `packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerDiagnostics.swift`:
- [SUGGESTION] packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerDiagnostics.swift:201-205: The manager’s tracked-lock list omits which payments have recorded payees
  Impact: Swift clients using `PlatformWalletManager.trackedAssetLocks(for:)` need a separate lookup to distinguish external funding from owned funding.
  Two Swift listings of the same lock expose different recovery information. Rust already populates `TrackedAssetLockEntryFFI.has_platform_address_recipients`, but the manager projection ends at `identityRecipientUnassigned`. Forward the flag on `TrackedAssetLockSnapshot`, as `ManagedAssetLockManager.TrackedAssetLock` already does.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift:101-102: The reopen test passes with recipient bytes Rust cannot restore
  Impact: A regression in the callbacks’ found flag, output length, or byte copy could pass the Swift persistence tests and surface only when a wallet restarts.
  The test proves that SwiftData preserves opaque bytes, not that the registered callbacks can return a restorable record. It calls the handler directly and puts `0x44` in the address-type byte, which Rust’s decoder rejects. Keep the opaque-byte check and add a reopen round trip through the registered persist and load callbacks using a canonical Rust fixture with an explicit payee and a remainder. Check the found flag, length, and exact bytes without adding a Swift decoder.
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift:182-184: The migration test does not check that legacy locks stay without recorded payees
  Impact: A regression that populates the new recipient field on a migrated wallet row would go undetected by the historical-store test.
  An upgrade could make a legacy lock look like a recorded-payee lock without failing this test. The new nil assertion elsewhere covers a row created in V5; this test opens a published V3 store and checks the other optional fields after migration. Assert that the new field is nil on the migrated row as well. The migration plan itself does not need to change.
Out-of-scope follow-up suggestions (1)

These are valid observations, but they are outside this PR's scope and should be handled in separate issues or author/maintainer-requested PRs rather than blocking this review.

  • The stacked identity top-up docs can lead a caller to pay again after a local lookup miss — The Swift docs carried unchanged from #6139 say that after certain failures, assetLockNotTracked makes a new payment safe. The native lookup checks only the current wallet’s tracked locks, so a wallet re-created after broadcast may not yet know about the first outpoint. A second call can then build a separate payable lock. The native docs explicitly warn against that inference.
    • Follow-up: Correct the retry contract in #6139 to match the native identity top-up docs: reconcile the original outpoint before funding another lock, and do not infer that nothing was sent or paid from a local tracking miss.

Comment on lines +594 to +602
private var canSubmit: Bool {
if resumeFromLock != nil {
// Resume only needs a recipient. The lock + amount +
// funding account are fixed by the original build.
// funding account are fixed by the original build. An
// external lock also needs its recorded payees shown.
return platformAccountIndex != nil
&& selectedRecipientHash != nil
&& activeController == nil
&& (!isExternalResume || recordedPayees.loadedPayees != nil)

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🔴 Blocking: An external payment cannot resume without an unused local address
Impact: A sender who opens a pending external payment can see all its recorded payees but cannot complete it if the selected account has no unused, zero-balance address.

The recovery screen can leave an already-funded lock unsubmitted even when the wallet still holds its recorded remainder address. canSubmit requires a selected address, and submit() looks it up again among unused, zero-balance addresses before reaching the external branch, where the address picker is hidden. The SDK call passes neither that address nor the selected account: Rust finds the account that holds the recorded remainder, which need not be unused. Handle external recovery before both picker guards, key its controller by wallet and outpoint alone, and test submission with loaded payees and an empty candidate list.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c154235: an external resume needs no picked account or unused address. submit/canSubmit handle it before both picker guards, and its controller slot is wallet + outpoint alone (account, address and type are nil). Tests: AddressFundExternalResumeSlotTests.

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.

Resolved (re-reviewed at c154235e): The form makes confirmation available once payees load and dispatches the recorded-recipient resume before either picker guard. The slot and the SDK call use the lock's outpoint without requiring any unused local address.

///
/// Default `nil` keeps SwiftData's lightweight migration safe. Lands in
/// the live, not yet published, V5 schema.
public var platformAddressRecipients: Data?

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: A SwiftData model edit can erase a lock’s recorded payment intent
Impact: An SDK host that clears and saves this field on a pending lock can make the next wallet restore treat the external payment as eligible for an owned-address resume.

Recovery cannot tell that the original payees were erased. The public setter bypasses the recipient callback’s conflict check; the load callback reports a cleared value as absent, and Rust accepts that as a legitimate legacy or owned lock. No current SDK callback clears the field, but client code can do so through an ordinary model assignment. Give the field the same externally read-only access as identityRecipient. Keep the checked sidecar as the writer: persistAssetLocks also gives incoming non-nil bytes precedence over stored bytes, even though its current FFI caller does not populate that field.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f156d9a: public internal(set) like identityRecipient, and persistAssetLocks keeps stored bytes over incoming ones.

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.

Resolved (re-reviewed at c154235e): The setter is internal to the SDK, a base upsert preserves an existing recipient record over incoming bytes, and the sidecar still refuses conflicting bytes.

Comment on lines +411 to +417
ForEach(Array(payees.enumerated()), id: \.offset) { _, payee in
HStack {
Text(hexShort(payee.hash))
.font(.system(.body, design: .monospaced))
Spacer()
Text(payee.credits.map(formatCredits) ?? "Remainder (this wallet)")
.foregroundColor(.secondary)

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: The confirmation screen hides the full payee address and rounds the recorded amount
Impact: A sender checking an interrupted payment cannot compare the full recorded address or exact credit amount with the original payment request.

The confirmation cannot distinguish different destinations or amounts that render the same way. hexShort shows only six leading and six trailing hash digits and omits the address type; formatCredits rounds to six DASH decimal places, so 500,000 and 500,001 credits display identically. Use the SDK’s network-aware address formatter to show the full typed address and make it copyable. Show exact integer credits alongside any rounded DASH value, and keep the remainder labeled separately.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c154235: full bech32m address for the current network, copyable, plus exact integer credits beside the rounded DASH value; the remainder keeps its own label.

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.

Resolved (re-reviewed at c154235e): The confirmation now shows the full typed, network-formatted address with text selection and prints the exact credit amount beside the DASH estimate. The remainder is labeled separately.

@@ -338,21 +449,27 @@ struct FundFromAssetLockPlatformAddressView: View {
case .completed(let newBalance):

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: The inline resume sheet can omit its completion or failure controls
Impact: A user who stays on the resume sheet can see the progress steps change without getting the corresponding Done or Dismiss button until another update redraws the sheet.

The inline terminal section can stay in its in-flight state after Rust returns. The sheet holds the controller in @State, which observes replacement of the reference, not its @Published phase; .onChange(of:) does not add that subscription. The progress child observes the controller, but that does not invalidate the parent. An early failure, for example, need not change any of the parent’s queried rows. Render the terminal controls from a view observing the controller with @ObservedObject, as the standalone progress screen does.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in c154235: the terminal controls render from a view observing the controller (@ObservedObject). The completion back-fill, which had the same .onChange gap on the parent, moved into it too.

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.

Resolved (re-reviewed at c154235e): InlineFundingTerminalSection observes the controller directly and renders Done or Dismiss from its published phase. The completion observer is in that same child.

Comment on lines +201 to 205
identityRecipient: entry.has_identity_recipient
? withUnsafeBytes(of: &entry.identity_recipient) { Data($0) }
: nil,
identityRecipientUnassigned: entry.identity_recipient_unassigned
)

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: The manager’s tracked-lock list omits which payments have recorded payees
Impact: Swift clients using PlatformWalletManager.trackedAssetLocks(for:) need a separate lookup to distinguish external funding from owned funding.

Two Swift listings of the same lock expose different recovery information. Rust already populates TrackedAssetLockEntryFFI.has_platform_address_recipients, but the manager projection ends at identityRecipientUnassigned. Forward the flag on TrackedAssetLockSnapshot, as ManagedAssetLockManager.TrackedAssetLock already does.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f156d9a: TrackedAssetLockSnapshot.hasPlatformAddressRecipients.

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.

Resolved (re-reviewed at c154235e): The manager now copies entry.has_platform_address_recipients into the public TrackedAssetLockSnapshot, matching the asset-lock manager's listing.

Comment on lines +101 to +102
func testPlatformAddressRecipientsSurviveStaleSnapshotsAndStoreReopenAndCannotChange() throws {
let recipients = Data([1, 0, 1] + [UInt8](repeating: 0x44, count: 21) + [0])

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: The reopen test passes with recipient bytes Rust cannot restore
Impact: A regression in the callbacks’ found flag, output length, or byte copy could pass the Swift persistence tests and surface only when a wallet restarts.

The test proves that SwiftData preserves opaque bytes, not that the registered callbacks can return a restorable record. It calls the handler directly and puts 0x44 in the address-type byte, which Rust’s decoder rejects. Keep the opaque-byte check and add a reopen round trip through the registered persist and load callbacks using a canonical Rust fixture with an explicit payee and a remainder. Check the found flag, length, and exact bytes without adding a Swift decoder.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f156d9a: a round trip through the registered persist/load callbacks with Rust's canonical bytes (one payee of 500,000 credits plus a remainder), across a reopen, checking found, length and bytes.

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.

Resolved (re-reviewed at c154235e): The new test calls the registered persist and load callbacks on either side of a reopen and asserts success, found, length, and exact bytes. The fixture matches Rust's format for a 500,000-credit P2PKH payee followed by one P2PKH remainder.

Comment on lines 182 to +184
XCTAssertNil(rows.first?.operationId)
XCTAssertNil(rows.first?.shieldedRecipientRaw43)
XCTAssertNil(rows.first?.identityRecipient)

@thepastaclaw thepastaclaw Nov 25, 2026 •

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.

✅ Resolved at c154235e; see the replies below.

🟡 Suggestion: The migration test does not check that legacy locks stay without recorded payees
Impact: A regression that populates the new recipient field on a migrated wallet row would go undetected by the historical-store test.

An upgrade could make a legacy lock look like a recorded-payee lock without failing this test. The new nil assertion elsewhere covers a row created in V5; this test opens a published V3 store and checks the other optional fields after migration. Assert that the new field is nil on the migrated row as well. The migration plan itself does not need to change.

Suggested change
XCTAssertNil(rows.first?.operationId)
XCTAssertNil(rows.first?.shieldedRecipientRaw43)
XCTAssertNil(rows.first?.identityRecipient)
XCTAssertNil(rows.first?.operationId)
XCTAssertNil(rows.first?.shieldedRecipientRaw43)
XCTAssertNil(rows.first?.identityRecipient)
XCTAssertNil(rows.first?.platformAddressRecipients)

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in f156d9a: the migrated V3 row asserts platformAddressRecipients == nil.

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.

Resolved (re-reviewed at c154235e): The new assertion checks the row fetched after opening the V3 store with the current schema, so the test now catches legacy locks gaining apparent recorded payees during migration.

romchornyi and others added 3 commits November 26, 2026 13:24
Brings in #5930's merge of #5931's branch. Swift keeps both sides' result codes and errors
(63-66 and 83-87 from the base, 81-82 from the identity top-up port), the schema doc lists both
sides' additions, and the parity summary is regenerated from the merged manifest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nd list them on every snapshot

- PersistentAssetLock.platformAddressRecipients is read-only outside the SDK, like
  identityRecipient, and a snapshot upsert keeps stored bytes over incoming ones: only the
  checked recipient callback writes them.
- TrackedAssetLockSnapshot carries hasPlatformAddressRecipients, as TrackedAssetLock does.
- Tests: the registered persist and load callbacks hand back Rust's canonical bytes across a
  store reopen (found flag, length, bytes), and a migrated V3 lock has no recorded payees.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ddress

An external resume pays its lock's recorded recipients, so it no longer needs a selected
account or an unused address: submit and canSubmit handle it before the picker guards, and
its controller slot is the wallet and the outpoint alone (account, address and type are nil).

Around it:
- The recorded payees show the full bech32m address for the network and the exact credits.
- The inline terminal section and the completion back-fill observe the controller, so Done,
  Dismiss and the back-fill follow its phase.
- While a resume runs only its own lock is hidden from the pending list; the wallet-wide
  Resume guard stays for a fresh funding whose outpoint is unknown.
- The progress screen reads the resumed lock by its outpoint, not the newest row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@romchornyi

Copy link
Copy Markdown
Contributor Author

The two suggestions from the b754d12 round that have no inline thread, both fixed in c154235:

  • An active resume appears twice and disables Resume for unrelated locks: active controllers with a known outpoint now exclude only their own row; the wallet-wide Resume guard stays only for an active fresh funding whose outpoint is unknown, and failed locks stay eligible for retry.
  • Resume progress can show a different lock's finality state: every progress calculation reads the row whose outpoint the controller names; the newest-row fallback is kept only for a fresh funding whose outpoint is not known yet.

The branch also merges the new #5930 head (8d00e7a).

romchornyi and others added 2 commits November 26, 2026 16:45
…ntity-fr (d7d22a9)

The base renumbered the identity-recipient codes to 89 (recipient unknown) and 90
(consumption unknown), since 81 and 82 belong to #5865 and #5647: Swift's raw values, their
docs and the pin tests follow. Both sides' result codes and errors are kept, the schema doc
lists both sides' additions, and the parity summary is regenerated from the merged manifest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nce, recipient conflicts, initializer

- topUpExternalIdentityWithFunding: once the outpoint is reported, only
  transactionBroadcastRejected allows a new lock. assetLockNotTracked means only that this
  wallet does not track the outpoint now; the lock may still be on the network (a wallet
  removed after Core accepted it, found again only after a reimport's rescan). The built
  outpoint goes through deliverTopUpOutcome, tested to report it once before the error.
- IdentityTopUpResult.newBalance is the proved balance for an identity this wallet does not
  manage, and the locally retained one for an identity it manages, which need not reflect
  the payment.
- The identity-recipient sidecar and the upsert check a conflicting recipient against the
  lock's status before the round, as SQLite does: a round whose upsert consumes a live row
  no longer drops the conflicting recipient as stale and commits Consumed with the old one.
- PersistentAssetLock's public initializer keeps its previous signature; the one that sets
  identityRecipient is internal, so a client cannot save a replacement row with another
  identity.
- The code 89/90 tests use the Swift error seam instead of handing a strdup string to Rust's
  CString deallocator.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@thepastaclaw thepastaclaw 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.

Re-review — Final validation — Phase 1 + Phase 2

Changes requested: 1 blocker

  • Submitting a second pending top-up can freeze the app while the first waits for finality — packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift:71-75 (new)
    Impact: A sender who leaves one broadcast lock waiting for finality and confirms another pending Platform-address top-up can lose use of the app even if the second lock already has a proof.

New on this head: This revision preserves recorded Platform-address recipients across SwiftData upserts, exposes the recorded-recipient flag in both SDK listings, and lets the example app confirm and resume an external payment without a local address selection. The SwiftData explorer check and Kotlin build and tests passed; the review check is pending, and no Swift SDK or simulator test job is listed for this head.

🔴 1 blocking | 🟡 3 suggestion(s)

Review provenance

Source: reviewer 1: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 2: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 3: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 4: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 5: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: critical by gpt-6.2-sol (effort low) — The diff changes funds movement by adding ManagedPlatformAddressWallet.resumeFundFromAssetLockToRecordedRecipients and wiring it to an intricate persistence and resume flow that determines who receives the funds after a restart.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Single stage: Phase 1 and Phase 2 reviewed this head side by side, with no blocker gate between them (triage tier)
  • New since the last final review (b754d122): 1 new blocker(s) went to an independent confirmation pass (the final verifier's model in a fresh session, without its reasoning): 1 confirmed
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-astra — general (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — architecture-layering (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — ffi-engineer (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — platform-versioning (completed, effort high); agent phase2-reviewer, gpt-6.2-astra — security-auditor (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift`:
- [BLOCKING] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/PendingPlatformFundFromAssetLocksList.swift:71-75: Submitting a second pending top-up can freeze the app while the first waits for finality
  Impact: A sender who leaves one broadcast lock waiting for finality and confirms another pending Platform-address top-up can lose use of the app even if the second lock already has a proof.
  The second confirmation can block the main thread before its progress controller starts. A user can resume a broadcast lock, swipe down the progress sheet without cancelling the operation, and open another pending lock from the same wallet. The new per-outpoint filter leaves that second Resume button available. On confirmation, `acquireAddressWallet()` calls `platform_wallet_get_platform` synchronously, and inserting the new handle needs the global `PLATFORM_ADDRESS_WALLET_STORAGE` write lock. The first resume holds a read guard on that registry because `fund_from_asset_lock.rs` calls `block_on_worker` inside `with_item`, including through the ChainLock fallback with no deadline. Clone the wallet under `with_item` and release the guard before waiting on the worker, as the withdrawal FFI does, so unrelated handles can be acquired without waiting for network finality.

  _Confirmed by an independent pass: A wallet with two pending Platform-address top-ups from interrupted attempts can resume a broadcast lock, swipe away its progress sheet without cancelling it, and confirm the second lock while the first still waits for finality. The second confirmation synchronously calls `platform_wallet_get_platform` on the main thread and blocks trying to insert a handle into the registry whose read lock the first resume still holds. The app becomes unresponsive before the second progress controller starts, and the freeze has no deadline if the first resume reaches the ChainLock fallback._

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleApp/Views/FundFromAssetLockPlatformAddressView.swift:855-860: An owned resume can leave its recipient blank when another lock completes
  Impact: A developer inspecting an owned top-up in the storage explorer can see a blank recipient when an external lock also becomes consumed after the owned resume starts.
  The storage explorer can omit a recipient the app already knows. The new per-outpoint list allows two different resumes, and the FFI work starts on detached tasks, so the second submission can take its snapshot before the first worker enters the registry. If both locks become consumed after the owned resume takes its snapshot, the external row intentionally has no owned-recipient stamp and both rows pass the `newRows` filter. The backfill then refuses to stamp either. Match an owned resume's consumed row by `controller.assetLockOutPoint` and reserve the snapshot comparison for fresh funding, where the outpoint is unknown. External resumes do not use the snapshot.

In `packages/swift-sdk/SwiftExampleApp/SwiftExampleAppTests/AddressFundExternalResumeSlotTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftExampleApp/SwiftExampleAppTests/AddressFundExternalResumeSlotTests.swift:29-37: The no-address test still passes if the form requires a picked address
  Impact: A regression that hides confirmation or prevents submission for a sender with no unused local address would leave the new slot tests green.
  The test proves that the coordinator accepts a slot with nil picker values, but it starts the coordinator directly and bypasses both `canSubmit` and `submit()`, where the original bug was. Keep the slot tests and add a case that exercises the form's routing with loaded payees, no selected account, and no address candidates. A fake submitter can verify that confirmation is available and dispatches the recorded-recipient resume for the displayed outpoint without needing a funded wallet.

In `packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift`:
- [SUGGESTION] packages/swift-sdk/SwiftTests/SwiftDashSDKTests/AssetLockOperationPersistenceTests.swift:184-185: The callback round trip puts recorded Platform payees on a shielded lock
  Impact: The reopen test can pass even if recipient persistence regresses specifically for the Platform-address top-up rows used in recovery.
  The test verifies the byte round trip on the wrong kind of row. Its `snapshot` helper hardcodes `fundingTypeRaw: 5`, which Rust restores as `AssetLockShieldedAddressTopUp`. The recorded-recipient resume accepts only `AssetLockAddressTopUp`, tag 4. Use a type-4 fixture for this test so the canonical bytes travel through the callbacks on the same kind of row that carries them in production.

Comment on lines +71 to +75
let activeControllers = walletControllers.filter { $0.phase.isActive }
let hasActiveFunding = activeControllers.contains { $0.assetLockOutPoint == nil }
let orphans = resumableLocks(
excludingControllerOutpoints: Set(activeControllers.compactMap(\.assetLockOutPoint))
)

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.

🔴 Blocking: Submitting a second pending top-up can freeze the app while the first waits for finality
Impact: A sender who leaves one broadcast lock waiting for finality and confirms another pending Platform-address top-up can lose use of the app even if the second lock already has a proof.

The second confirmation can block the main thread before its progress controller starts. A user can resume a broadcast lock, swipe down the progress sheet without cancelling the operation, and open another pending lock from the same wallet. The new per-outpoint filter leaves that second Resume button available. On confirmation, acquireAddressWallet() calls platform_wallet_get_platform synchronously, and inserting the new handle needs the global PLATFORM_ADDRESS_WALLET_STORAGE write lock. The first resume holds a read guard on that registry because fund_from_asset_lock.rs calls block_on_worker inside with_item, including through the ChainLock fallback with no deadline. Clone the wallet under with_item and release the guard before waiting on the worker, as the withdrawal FFI does, so unrelated handles can be acquired without waiting for network finality.

Confirmed by an independent pass: A wallet with two pending Platform-address top-ups from interrupted attempts can resume a broadcast lock, swipe away its progress sheet without cancelling it, and confirm the second lock while the first still waits for finality. The second confirmation synchronously calls platform_wallet_get_platform on the main thread and blocks trying to insert a handle into the registry whose read lock the first resume still holds. The app becomes unresponsive before the second progress controller starts, and the freeze has no deadline if the first resume reaches the ChainLock fallback.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Comment on lines +855 to +860
if resumeFromLock?.platformAddressRecipients != nil { return }
guard
let controller = activeController,
let recipientHash = controller.recipientHash,
let recipientType = controller.recipientType
else { return }

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.

🟡 Suggestion: An owned resume can leave its recipient blank when another lock completes
Impact: A developer inspecting an owned top-up in the storage explorer can see a blank recipient when an external lock also becomes consumed after the owned resume starts.

The storage explorer can omit a recipient the app already knows. The new per-outpoint list allows two different resumes, and the FFI work starts on detached tasks, so the second submission can take its snapshot before the first worker enters the registry. If both locks become consumed after the owned resume takes its snapshot, the external row intentionally has no owned-recipient stamp and both rows pass the newRows filter. The backfill then refuses to stamp either. Match an owned resume's consumed row by controller.assetLockOutPoint and reserve the snapshot comparison for fresh funding, where the outpoint is unknown. External resumes do not use the snapshot.

source: gpt-6.2-astra (phase2-reviewer: general)

Comment on lines +29 to +37
func testAnExternalResumeStartsWithoutAPickedAccountOrAddress() {
let coordinator = AddressFundFromAssetLockCoordinator()
let controller = startExternalResume(on: coordinator)

XCTAssertEqual(controller.phase, .inFlight)
XCTAssertNil(controller.platformAccountIndex)
XCTAssertNil(controller.recipientHash)
XCTAssertNil(controller.recipientType)
XCTAssertEqual(controller.assetLockOutPoint, outPoint)

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.

🟡 Suggestion: The no-address test still passes if the form requires a picked address
Impact: A regression that hides confirmation or prevents submission for a sender with no unused local address would leave the new slot tests green.

The test proves that the coordinator accepts a slot with nil picker values, but it starts the coordinator directly and bypasses both canSubmit and submit(), where the original bug was. Keep the slot tests and add a case that exercises the form's routing with loaded payees, no selected account, and no address candidates. A fake submitter can verify that confirmation is available and dispatches the recorded-recipient resume for the displayed outpoint without needing a funded wallet.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Comment on lines +184 to +185
XCTAssertTrue(handler.persistAssetLocks(walletId: walletId,
upserts: [snapshot(status: 0, operationId: nil)], removed: []))

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.

🟡 Suggestion: The callback round trip puts recorded Platform payees on a shielded lock
Impact: The reopen test can pass even if recipient persistence regresses specifically for the Platform-address top-up rows used in recovery.

The test verifies the byte round trip on the wrong kind of row. Its snapshot helper hardcodes fundingTypeRaw: 5, which Rust restores as AssetLockShieldedAddressTopUp. The recorded-recipient resume accepts only AssetLockAddressTopUp, tag 4. Use a type-4 fixture for this test so the canonical bytes travel through the callbacks on the same kind of row that carries them in production.

source: gpt-6.2-astra (phase2-reviewer: general, architecture-layering, ffi-engineer, platform-versioning, security-auditor)

Comment on lines +594 to +602
private var canSubmit: Bool {
if resumeFromLock != nil {
// Resume only needs a recipient. The lock + amount +
// funding account are fixed by the original build.
// funding account are fixed by the original build. An
// external lock also needs its recorded payees shown.
return platformAccountIndex != nil
&& selectedRecipientHash != nil
&& activeController == nil
&& (!isExternalResume || recordedPayees.loadedPayees != nil)

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.

Resolved (re-reviewed at c154235e): The form makes confirmation available once payees load and dispatches the recorded-recipient resume before either picker guard. The slot and the SDK call use the lock's outpoint without requiring any unused local address.

Comment on lines +411 to +417
ForEach(Array(payees.enumerated()), id: \.offset) { _, payee in
HStack {
Text(hexShort(payee.hash))
.font(.system(.body, design: .monospaced))
Spacer()
Text(payee.credits.map(formatCredits) ?? "Remainder (this wallet)")
.foregroundColor(.secondary)

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.

Resolved (re-reviewed at c154235e): The confirmation now shows the full typed, network-formatted address with text selection and prints the exact credit amount beside the DASH estimate. The remainder is labeled separately.

@@ -338,21 +449,27 @@ struct FundFromAssetLockPlatformAddressView: View {
case .completed(let newBalance):

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.

Resolved (re-reviewed at c154235e): InlineFundingTerminalSection observes the controller directly and renders Done or Dismiss from its published phase. The completion observer is in that same child.

Comment on lines +201 to 205
identityRecipient: entry.has_identity_recipient
? withUnsafeBytes(of: &entry.identity_recipient) { Data($0) }
: nil,
identityRecipientUnassigned: entry.identity_recipient_unassigned
)

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.

Resolved (re-reviewed at c154235e): The manager now copies entry.has_platform_address_recipients into the public TrackedAssetLockSnapshot, matching the asset-lock manager's listing.

Comment on lines +101 to +102
func testPlatformAddressRecipientsSurviveStaleSnapshotsAndStoreReopenAndCannotChange() throws {
let recipients = Data([1, 0, 1] + [UInt8](repeating: 0x44, count: 21) + [0])

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.

Resolved (re-reviewed at c154235e): The new test calls the registered persist and load callbacks on either side of a reopen and asserts success, found, length, and exact bytes. The fixture matches Rust's format for a 500,000-credit P2PKH payee followed by one P2PKH remainder.

Comment on lines 182 to +184
XCTAssertNil(rows.first?.operationId)
XCTAssertNil(rows.first?.shieldedRecipientRaw43)
XCTAssertNil(rows.first?.identityRecipient)

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.

Resolved (re-reviewed at c154235e): The new assertion checks the row fetched after opening the V3 store with the current schema, so the test now catches legacy locks gaining apparent recorded payees during migration.

romchornyi and others added 5 commits December 1, 2026 01:47
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… state the acknowledgement and retry rules as the FFI does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… state the acknowledgement and retry rules as the FFI does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
romchornyi and others added 5 commits December 1, 2026 02:07
…'s upsert, as the SQLite store does

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed recipients to the wallet only after the user confirms it

A row without recipients does not prove an owned funding: an external payment
built before recipients were recorded, or rebuilt from the chain, records none
either. The resume form now asks, per outpoint and each time it opens, refuses
a row the host marked external, refuses a row that changed while the form was
open, and back-fills only the lock it resumed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
romchornyi added a commit that referenced this pull request Dec 4, 2026
…nly a backend that can finish it

`EXTERNAL_PLATFORM_ADDRESS_FUNDING` now also requires `TRACKED_ASSET_LOCKS`
(bit 9) and `WALLET_RESTORE` (bit 7). A backend declaring only bits 0, 2
and 18 could broadcast an external payment that both external resume APIs
then refuse for the missing bit 9, and lose its `Consumed` status; such a
backend is now refused before anything is built (NotSent). Resuming still
needs only bit 9. The in-tree SQLite, Swift (#6272) and Kotlin (#6273)
backends declare bits 7, 9 and 18.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
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.

2 participants