Skip to content

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

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

romchornyi wants to merge 19 commits into
feat/platform-wallet-asset-lock-intentfrom
feat/kotlin-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 Kotlin host side (JNI, Room, SDK and example app). 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 #5933 (Kotlin port of #5931, Room v17). GitHub's diff therefore also shows the #5933 commits until #5933 lands. The commits of this PR are the five listed below. Merge order: #5931 → #5930 and #5933 → this PR.

What was done?

  • 9f6e2bd183 feat(kotlin-sdk):
    • JNI:
      • adds trampolines for on_persist/on_load_asset_lock_platform_address_recipients_fn. The record is variable length, 1..=4096 bytes; an empty, over-long or unreadable load fails the native load;
      • the trampolines are wired only for a bridge that overrides both methods, so FFIPersister attests bit 18 only then, and only together with ATOMIC_CHANGESETS;
      • new exports walletAssetLockPlatformAddressRecipients and walletResumeFundFromAssetLockToRecordedRecipients.
    • Room v18:
      • adds the asset_locks.platformAddressRecipients BLOB with a set-once trigger (as SQLite V024), MIGRATION_17_18 and 18.json;
      • the handler stores the record in the row's open round: the same value again is accepted, a different one is refused, and a missing row fails the round;
      • the record is carried through later upserts, and loading a missing row fails;
      • the handler declares bit 18.
    • SDK: adds ManagedPlatformWallet.assetLockPlatformAddressRecipients and resumeFundFromAssetLockToRecordedRecipients. fundFromAssetLockExternal no longer asks the host to persist and re-pass the recipients.
  • 5ab6358e23 feat(kotlin-example-app):
    • the top-up resume form sends a lock that has recorded recipients to the recorded-recipients resume, and shows the payees in place of the address picker;
    • the coordinator's slots, rows, dismiss calls and progress route key on the lock's outpoint;
    • when an external resume completes, the screen shows "Payment completed" without a balance line.
  • 595bba8a20 fix(kotlin-example-app): a funding result with no update for the picked address no longer shows "Address funded — 0 credits". AddressFundFromAssetLockController.reportedBalance keeps the missing update as null.
  • 4682bc39b3 fix(kotlin-example-app): a failed payee lookup no longer stays "Loading" for good:
    • RecordedPayeesLoad gives the read its own states (waiting for the wallet, loading, loaded, not found, failed);
    • the read re-runs when the wallet becomes available;
    • a failure offers Retry;
    • confirmation stays disabled, and submit refuses, until the payees are loaded.
  • 7df83aa782 docs(kotlin-sdk): adds the parity-manifest entry and the persistence capability, and regenerates PARITY_SUMMARY.md.

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

Not covered here: Kotlin's TrackedAssetLock has no hasPlatformAddressRecipients flag, because the Kotlin tracked-lock list carries only identity funding types. The example app identifies an external lock by the Room column instead.

How Has This Been Tested?

  • JNI (rs-unified-sdk-jni) tests: 86 passed.
  • kotlin-sdk unit tests: 656 passed.
  • Example app unit tests: 311 passed, including 6 new RecordedPayeesLoadTest.
  • Not run: the Room migration androidTest (MIGRATION_17_18), because no emulator was available. It should be run before this PR leaves draft.

Breaking Changes

None beyond #5930. Room schema 17 → 18 is migrated in place.

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

HashEngineering and others added 19 commits November 17, 2026 17:12
Kotlin side of #5924, on top of the Rust/FFI change.

Persistence: Room v17 adds the asset-lock sidecars SQLite (V019-V021) and
Swift already keep - operationId (16 bytes), shieldedRecipientRaw43 (43)
and identityRecipientId (32) - with a unique (walletId, operationId) index
and immutability triggers. The handler stores each sidecar in the round of
its row's upsert, refuses a different value (constraint) and accepts the
same one, carries the values through later upserts, and fails a load whose
row is missing or malformed. DrainCompleted (6) is now terminal like
Consumed, as in Swift and SQLite. The handler declares bits 13, 14 and 17.

JNI: trampolines for the three persist/load pairs, each wired only when the
bridge overrides both methods; bindings for the external top-up, the
recorded-recipient resume and the recipient assignment; TrackedAssetLock
carries the identity recipient and the unassigned flag. Code 81 maps to
AssetLockRecipientUnknown.

Example app: Top Up from Core resumes through the recorded recipient and
lists unassigned unbound locks with an assign action.

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

topUpExternalIdentityFromCore and resumeTopUpToRecordedRecipient ran under
gate.op, whose withContext drops a result that arrives after the caller was
cancelled. The blocking native call cannot observe cancellation, so a
top-up could complete and consume its lock while the caller saw only a
CancellationException; a retry with a new lock would pay the identity twice.
Both now use opReturningCompletedResult, as the other credit-moving calls do.

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

- IdentityCredits takes one TopUpNative seam instead of two.
- JNI sidecars live in one ASSET_LOCK_SIDECARS table; each width is stated
  once and two generic trampolines replace six forwarding ones.
- Sidecar loads and the pre-persist conflict check select only the sidecar
  columns instead of the whole row with its transaction and proof bytes.
- topUpIdentityWithExistingAssetLock uses read_outpoint; drop a dead check,
  an alias and copies of freshly read arrays.
- Example app uses toHex() and reads the selected unassigned lock once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…le recipients on consumed rows

- topUpExternalIdentityFromCore takes onAssetLockBuilt, called with the
  built lock's outpoint before the balance is returned or the error thrown
  (not called when nothing was built). The JNI export takes a byte[36] it
  fills from the FFI's new out_asset_lock_outpoint before raising any error.
- Room skips a different identity recipient for a Consumed or
  DrainCompleted row instead of failing the round, as the SQLite store does.
- KDoc: identityRecipientUnassigned is false for RecoveredFromChain locks,
  code 24 also covers AssetLockConsumptionUnknown, code 20 on the external
  top-up means resume the reported outpoint, and Rust keeps consumed rows
  as recovery tombstones.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in v5.2-dev through PR A's merge and its code-80 change, and
regenerates the parity summary.

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

The identity recipient migration is V023 now that #5890 took V022, and the
external top-up and recipient assignment report a lookup Platform could not
answer as IdentityLookupFailed (80).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… a confirmed use (24)

Assigning a recipient to a recipient-less lock rebuilt from the chain is
refused with ErrorAssetLockConsumptionUnknown (82), not 24:
DashSdkError.PlatformWallet.AssetLockConsumptionUnknown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Brings in v5.2-dev (#5929) and PR A's review fixes.

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

# Conflicts:
#	packages/kotlin-sdk/PARITY_SUMMARY.md
#	packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/credits/IdentityCredits.kt
…covered top-up lock

assignTopUpRecipient takes acknowledgeUnknownConsumption (default false), bound through the JNI to the new bool parameter of platform_wallet_assign_identity_top_up_recipient. KDoc describes the recipient-only assignment round, and a handler test pins that a round carrying the recipient alone records it on the stored row and leaves its status as stored.

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

The owned resume and the fresh funding closures fell back to `?: 0L`
when the result carried no update for the picked address, which
reconciliation returns when sync already applied the balance, so the
progress screen showed "Address funded — 0 credits". Completed now
carries an optional balance, both closures go through
AddressFundFromAssetLockController.reportedBalance, which keeps the
missing update as null, and the screen shows "Address funded" without a
balance line.

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

Port the Platform-address recipients of #5930 to Kotlin on
top of the #5933 sidecar patterns.

JNI: trampolines for on_persist/on_load_asset_lock_platform_address_recipients_fn
(variable length, 1..=4096 bytes; an empty, over-long or unreadable load fails
the native load), wired only for a bridge that overrides both methods, so
FFIPersister attests bit 18 only then (and only with ATOMIC_CHANGESETS).
New exports walletAssetLockPlatformAddressRecipients (getter + free, in the
funding-recipients blob shape) and
walletResumeFundFromAssetLockToRecordedRecipients.

Room v18: asset_locks.platformAddressRecipients BLOB with a set-once
trigger (as SQLite V024), migration 17 -> 18 and schema 18.json. The
handler stores the record in the row's open round (same value again ok, a
different one refused, a missing row fails the round), carries it through
later upserts, fails the load of a missing row, and declares bit 18 next
to its atomic rounds.

SDK: ManagedPlatformWallet.assetLockPlatformAddressRecipients and
resumeFundFromAssetLockToRecordedRecipients; fundFromAssetLockExternal no
longer asks the host to persist and re-pass the recipients.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ed 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, dismiss calls and the progress
route 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. A completion that establishes no balance, as an external
resume does, shows "Payment completed" without a balance line.

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

The external resume form read the recorded payees with
runCatching(...).getOrNull(): a failed read and a wallet the manager had
not loaded yet both stayed "Loading" for good, and nothing read them again.
The read now has its own states (waiting for the wallet, loading, loaded,
not found, failed) in RecordedPayeesLoad, re-runs when the wallet becomes
available, and offers Retry after a failure. Confirmation stays disabled,
and submit refuses, until the payees are loaded.

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

Add the platform_address.external_funding_recorded_recipients capability
(Kotlin SDK and example app partial, Swift 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

⛔ Final review complete — 5 blocking finding(s) (commit 7df83aa) · triage: critical · Phase 2 only (queue backlog)

@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: 5 blockers

  • The Android wallet database cannot open after upgrading from the published 5.1 dev SDKs — packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/DashDatabase.kt:213 (new)
    Impact: An app upgrading from the v5.1.0-dev.3 or v5.1.0-dev.4 Android AAR cannot open its existing wallet database with this build.
  • A JNI callback probe error can restore a payment without its recorded payees — packages/rs-unified-sdk-jni/src/persistence.rs:283-293 (new)
    Impact: If recipient callback discovery fails when a wallet reopens, an SDK caller can see no recorded recipients and resume the pending payment to its own wallet instead.
  • Cancelling a resume can hide a completed external payment — packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/ManagedPlatformWallet.kt:1054 (new)
    Impact: An SDK caller cancelled while the native resume is running can receive CancellationException instead of the successful result after the payees have been credited.
  • A recorded external payment cannot resume without an unrelated unused address — packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt:137-140 (new)
    Impact: A user whose wallet holds the recorded remainder address but has no unused zero-balance address can see the payees but cannot press “Complete External Payment.”
  • An external payment interrupted before broadcast is missing from the recovery list — packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt:68-72 (new)
    Impact: If Android stops the process after the lock and payees commit but before the Core transaction is sent, the user can reopen the wallet and find no payment to resume.

This PR connects Android Room persistence and JNI to Rust’s recorded-recipient recovery for external Platform-address asset locks, and adds a confirmation flow to the Kotlin example app. The Kotlin SDK build and emulator test check passed on 7df83aa7823e870485b9fd71f00e7818d236bcd3; this verification was static.

🔴 5 blocking | 🟡 5 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: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 6: gpt-6.2-astra (agent: phase2-reviewer, role: security-auditor); reviewer 7: gpt-6.2-astra (agent: phase2-reviewer, role: general); reviewer 8: gpt-6.2-astra (agent: phase2-reviewer, role: architecture-layering); reviewer 9: gpt-6.2-astra (agent: phase2-reviewer, role: ffi-engineer); reviewer 10: gpt-6.2-astra (agent: phase2-reviewer, role: platform-versioning); reviewer 11: gpt-6.2-astra (agent: phase2-reviewer, role: rust-quality); reviewer 12: 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 adds a Room 17→18 migration in DashDatabase.kt and changes how ManagedPlatformWallet.kt resumes movement of funds, relying on JNI callbacks and atomic, set-once persistence to preserve the original payees across retries.
  • Phase 1 reviewers: not run (skipped for throughput: 13 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 — rust-quality (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 — rust-quality (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/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/DashDatabase.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/DashDatabase.kt:213: The Android wallet database cannot open after upgrading from the published 5.1 dev SDKs
  Impact: An app upgrading from the v5.1.0-dev.3 or v5.1.0-dev.4 Android AAR cannot open its existing wallet database with this build.
  Both published AARs use `dash-sdk.db`, and their schema history is already in the stack’s eventual target, `v5.2-dev`. The shipped v17 schema in v5.1.0-dev.3 has `operationId` and `wallet_drain_operations`, but lacks `shieldedRecipientRaw43` and `identityRecipientId`. This PR’s `MIGRATION_17_18` adds only `platformAddressRecipients`, so Room finds the other two columns missing. The current test starts from this branch’s different `17.json` and cannot catch that failure. v5.1.0-dev.4 already reached v21 and used v18 for identity voting-key fields; this build would attempt an unsupported downgrade. Keep the published migration chain and add the missing sidecars and triggers after v21, then verify upgrades from the tagged v17 and v21 fixtures.

In `packages/rs-unified-sdk-jni/src/persistence.rs`:
- [BLOCKING] packages/rs-unified-sdk-jni/src/persistence.rs:283-293: A JNI callback probe error can restore a payment without its recorded payees
  Impact: If recipient callback discovery fails when a wallet reopens, an SDK caller can see no recorded recipients and resume the pending payment to its own wallet instead.
  The recipient restriction can disappear from memory even though the record is intact on disk. `bridge_overrides` clears reflection exceptions and returns `false`, so a failed probe for either callback leaves both slots unset and manager creation continues. `FFIPersister::load` does not ask the host for the sidecar without the load slot, and `validate_existing_asset_lock_role` accepts an owned address top-up when the recorded recipients are `None`. Losing bit 18 only prevents building a new external lock. Propagate probe errors through manager initialization instead of treating them as inherited methods, and wire a confirmed reader independently of the writer while still requiring both for the write capability.
- [SUGGESTION] packages/rs-unified-sdk-jni/src/persistence.rs:2519-2525: JNI copies oversized recipient records before checking the 4 KiB limit
  Impact: A custom persistence bridge returning a large malformed byte array can trigger an equally large native allocation during wallet restore instead of a bounded load error.
  `convert_byte_array` allocates a native `Vec` for the full Java array before the trampoline compares its length with the destination capacity and the format maximum. Room already checks the length, but custom persistence bridges need not. Read the Java array length first and reject a non-null array outside `1..=min(recipients_capacity, MAX_LEN)` before allocating or copying it.

In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/ManagedPlatformWallet.kt`:
- [BLOCKING] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/ManagedPlatformWallet.kt:1054: Cancelling a resume can hide a completed external payment
  Impact: An SDK caller cancelled while the native resume is running can receive `CancellationException` instead of the successful result after the payees have been credited.
  The blocking JNI call can finish and consume the lock after cancellation. `gate.op` uses `withContext(Dispatchers.IO)`, whose cancellable return dispatch can discard the successfully decoded changeset. Retrying the same outpoint cannot pay twice, but it reports the lock consumed rather than returning the original confirmation; a replacement funding could pay the recipient again. Use the existing `opReturningCompletedResult` handoff, as the identity recorded-recipient resume does, and test cancellation after native entry followed by a successful native return.
- [SUGGESTION] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/ManagedPlatformWallet.kt:1037-1039: The recovery guidance treats legacy external payments as owned fundings
  Impact: A host following the documented fallback for an interrupted pre-upgrade external payment can consume the lock into the sender’s wallet and leave the intended payee unpaid.
  A migrated `NULL` means no recipients were recorded in Room, not that the payment belonged to the sender. The v5.1.0-dev.2 SDK already supported external funding and told hosts to save payees by outpoint; the migration cannot recover that mapping, and Rust permits an owned resume when no recipient record exists. Qualify the fallback here and in `DashDatabase`: use `resumeFundFromAssetLock` only for known owned fundings, and retain the host’s saved list for legacy external locks until they can be resumed with `resumeFundFromAssetLockExternal`.

In `packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt`:
- [BLOCKING] packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt:137-140: A recorded external payment cannot resume without an unrelated unused address
  Impact: A user whose wallet holds the recorded remainder address but has no unused zero-balance address can see the payees but cannot press “Complete External Payment.”
  The recorded payment is ready to resume, but `canSubmit` always requires a picker result and the click handler independently returns at `recipient ?: return@SubmitButton`. The external call does not use that address: Rust finds the account from the recorded remainder, which can already be used or have a balance. The picker result only supplies the controller and progress-route identity on this path. Key recorded resumes by wallet and outpoint, and require a picked address only on the paths that actually pass one to Rust. Cover loaded payees with an empty candidate list.
- [BLOCKING] packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt:68-72: An external payment interrupted before broadcast is missing from the recovery list
  Impact: If Android stops the process after the lock and payees commit but before the Core transaction is sent, the user can reopen the wallet and find no payment to resume.
  The pending list is this screen’s recovery entry point, but its `AssetLockDao.observeResumableTopUpsByFundingType` query only includes statuses 1–3 and 5. The wallet deliberately commits the transaction and payees at `Built` (0), and there is no network event to advance a transaction that was never sent. Rust’s existing `(Built, None)` resume branch can broadcast the same transaction. Surface recorded type-4 `Built` locks for user-initiated recovery while retaining the in-flight guard, and test that a persisted pre-broadcast lock is selectable after restart. An address-lock projection of the Rust snapshot could also give SDK hosts this discovery path without exposing the Room schema or widening the identity-only picker.
- [SUGGESTION] packages/kotlin-sdk/KotlinExampleApp/app/src/main/java/org/dashfoundation/example/ui/funding/FundFromAssetLockScreen.kt:455-458: The payment confirmation shows only a prefix of each destination
  Impact: A user checking an interrupted payment cannot compare the recorded destination with the full Platform address supplied by the payee.
  The confirmation shows only eight bytes of each 20-byte hash, omits the address type, and provides no way to inspect the rest. A prefix works as a list label but not as the only destination on an irreversible payment’s confirmation screen. Show the full network-formatted address or let the user reveal and copy it alongside the compact label.

In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/PlatformWalletPersistenceHandler.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/PlatformWalletPersistenceHandler.kt:165: Room can silently omit a recorded payment when its base row is malformed
  Impact: A wallet reopening a malformed asset-lock row can report a successful restore even though Rust never receives the row or its recorded payees.
  `buildTrackedAssetLockData` logs and skips malformed outpoints, empty transactions, and status or funding values that do not fit the JNI carrier. For a row with an intact recipient BLOB and an empty transaction, `FFIPersister` never calls the sidecar loader: it only queries locks present in the base snapshot. Report a load error for a recorded row that cannot be marshalled rather than return a partial snapshot. Extend the Android manager round trip to cover a malformed base row, a valid record with an explicit payee and remainder, and a null control. The current JNI length test and emulator capability test do not exercise successful byte delivery with `out_found` and `out_recipients_len` set.

In `packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/entities/AssetLockEntity.kt`:
- [SUGGESTION] packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/persistence/entities/AssetLockEntity.kt:120: Precompiled Android clients can no longer construct or copy an asset-lock row
  Impact: An app that upgrades the Android AAR while retaining a library compiled against the old `AssetLockEntity` can get `NoSuchMethodError` when that library constructs or copies a row.
  The new defaulted property preserves Kotlin source calls after recompilation, but changes the JVM descriptors of the public constructor, `copy`, and `copy$default`, even relative to the stacked v17 model. Room’s migration preserves stored data, not those entry points. Either preserve the old descriptors if binary compatibility is required, or document in the PR and release notes that consumers must rebuild dependent Android libraries.
Out-of-scope follow-up suggestions (2)

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.

  • An identity top-up observer can mask the native payment outcome — In the unchanged #5933 Kotlin identity path, onAssetLockBuilt runs in finally and can replace either a proved balance or a typed native recovery error if the host callback throws.
    • Follow-up: Address this on #5933 or in a separate identity SDK PR by preserving the native outcome and reporting observer failure separately.
  • Seed-restored identity top-ups without a payee appear in the resume picker — The unchanged #5933 identity picker treats !identityRecipientUnassigned as evidence of a known payee. Rust also returns false for recipient-less RecoveredFromChain locks, which the recorded-recipient resume rejects.
    • Follow-up: Address this on #5933 or in a separate identity recovery PR by requiring an actual recorded identity for unbound resume rows and testing the recipient-less recovered case.

*/
@Database(
version = 16,
version = 18,

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: The Android wallet database cannot open after upgrading from the published 5.1 dev SDKs
Impact: An app upgrading from the v5.1.0-dev.3 or v5.1.0-dev.4 Android AAR cannot open its existing wallet database with this build.

Both published AARs use dash-sdk.db, and their schema history is already in the stack’s eventual target, v5.2-dev. The shipped v17 schema in v5.1.0-dev.3 has operationId and wallet_drain_operations, but lacks shieldedRecipientRaw43 and identityRecipientId. This PR’s MIGRATION_17_18 adds only platformAddressRecipients, so Room finds the other two columns missing. The current test starts from this branch’s different 17.json and cannot catch that failure. v5.1.0-dev.4 already reached v21 and used v18 for identity voting-key fields; this build would attempt an unsupported downgrade. Keep the published migration chain and add the missing sidecars and triggers after v21, then verify upgrades from the tagged v17 and v21 fixtures.

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

Comment on lines +283 to +293
asset_lock_platform_address_recipients: bridge_overrides(
env,
bridge,
PERSIST_PLATFORM_ADDRESS_RECIPIENTS_METHOD,
ASSET_LOCK_SIDECAR_PERSIST_DESCRIPTOR,
) && bridge_overrides(
env,
bridge,
LOAD_PLATFORM_ADDRESS_RECIPIENTS_METHOD,
ASSET_LOCK_SIDECAR_LOAD_DESCRIPTOR,
),

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: A JNI callback probe error can restore a payment without its recorded payees
Impact: If recipient callback discovery fails when a wallet reopens, an SDK caller can see no recorded recipients and resume the pending payment to its own wallet instead.

The recipient restriction can disappear from memory even though the record is intact on disk. bridge_overrides clears reflection exceptions and returns false, so a failed probe for either callback leaves both slots unset and manager creation continues. FFIPersister::load does not ask the host for the sidecar without the load slot, and validate_existing_asset_lock_role accepts an owned address top-up when the recorded recipients are None. Losing bit 18 only prevents building a new external lock. Propagate probe errors through manager initialization instead of treating them as inherited methods, and wire a confirmed reader independently of the writer while still requiring both for the write capability.

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

outPointVout: Int,
signerHandle: Long,
coreSignerHandle: Long,
): List<UpdatedBalance> = gate.op {

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: Cancelling a resume can hide a completed external payment
Impact: An SDK caller cancelled while the native resume is running can receive CancellationException instead of the successful result after the payees have been credited.

The blocking JNI call can finish and consume the lock after cancellation. gate.op uses withContext(Dispatchers.IO), whose cancellable return dispatch can discard the successfully decoded changeset. Retrying the same outpoint cannot pay twice, but it reports the lock consumed rather than returning the original confirmation; a replacement funding could pay the recipient again. Use the existing opReturningCompletedResult handoff, as the identity recorded-recipient resume does, and test cancellation after native entry followed by a successful native return.

Suggested change
): List<UpdatedBalance> = gate.op {
): List<UpdatedBalance> = gate.opReturningCompletedResult {

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

Comment on lines 137 to +140
val canSubmit = wallet != null && manager != null && recipient != null &&
if (isResume) resumeLock != null else (amount != null && amount > 0)
if (isResume) {
resumeLock != null && (!isExternal || recordedPayees.loadedPayees != null)
} else {

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: A recorded external payment cannot resume without an unrelated unused address
Impact: A user whose wallet holds the recorded remainder address but has no unused zero-balance address can see the payees but cannot press “Complete External Payment.”

The recorded payment is ready to resume, but canSubmit always requires a picker result and the click handler independently returns at recipient ?: return@SubmitButton. The external call does not use that address: Rust finds the account from the recorded remainder, which can already be used or have a balance. The picker result only supplies the controller and progress-route identity on this path. Key recorded resumes by wallet and outpoint, and require a picked address only on the paths that actually pass one to Rust. Cover loaded payees with an empty candidate list.

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

Comment on lines +68 to +72
* `fundFromAssetLockExternal` recorded the Platform addresses it pays
* (`AssetLockEntity.platformAddressRecipients`): it shows those payees in
* place of the address picker and resumes through
* [ManagedPlatformWallet.resumeFundFromAssetLockToRecordedRecipients], never
* as an owned top-up. The

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: An external payment interrupted before broadcast is missing from the recovery list
Impact: If Android stops the process after the lock and payees commit but before the Core transaction is sent, the user can reopen the wallet and find no payment to resume.

The pending list is this screen’s recovery entry point, but its AssetLockDao.observeResumableTopUpsByFundingType query only includes statuses 1–3 and 5. The wallet deliberately commits the transaction and payees at Built (0), and there is no network event to advance a transaction that was never sent. Rust’s existing (Built, None) resume branch can broadcast the same transaction. Surface recorded type-4 Built locks for user-initiated recovery while retaining the in-flight guard, and test that a persisted pre-broadcast lock is selectable after restart. An address-lock projection of the Rust snapshot could also give SDK hosts this discovery path without exposing the Room schema or widening the identity-only picker.

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

CAPABILITY_ASSET_LOCK_OPERATION_IDS or
CAPABILITY_ASSET_LOCK_SHIELDED_RECIPIENTS or
CAPABILITY_ASSET_LOCK_IDENTITY_RECIPIENTS or
CAPABILITY_ASSET_LOCK_PLATFORM_ADDRESS_RECIPIENTS

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: Room can silently omit a recorded payment when its base row is malformed
Impact: A wallet reopening a malformed asset-lock row can report a successful restore even though Rust never receives the row or its recorded payees.

buildTrackedAssetLockData logs and skips malformed outpoints, empty transactions, and status or funding values that do not fit the JNI carrier. For a row with an intact recipient BLOB and an empty transaction, FFIPersister never calls the sidecar loader: it only queries locks present in the base snapshot. Report a load error for a recorded row that cannot be marshalled rather than return a partial snapshot. Extend the Android manager round trip to cover a malformed base row, a valid record with an explicit payee and remainder, and a null control. The current JNI length test and emulator capability test do not exercise successful byte delivery with out_found and out_recipients_len set.

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

Comment on lines +1037 to +1039
* Refused before anything is submitted for a lock that is not tracked,
* of another funding type, already consumed, or that records no
* recipients (an owned funding: use [resumeFundFromAssetLock]).

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 recovery guidance treats legacy external payments as owned fundings
Impact: A host following the documented fallback for an interrupted pre-upgrade external payment can consume the lock into the sender’s wallet and leave the intended payee unpaid.

A migrated NULL means no recipients were recorded in Room, not that the payment belonged to the sender. The v5.1.0-dev.2 SDK already supported external funding and told hosts to save payees by outpoint; the migration cannot recover that mapping, and Rust permits an owned resume when no recipient record exists. Qualify the fallback here and in DashDatabase: use resumeFundFromAssetLock only for known owned fundings, and retain the host’s saved list for legacy external locks until they can be resumed with resumeFundFromAssetLockExternal.

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

* by parsing these bytes. Null for an owned funding, every other lock,
* and rows stored before recipients were recorded.
*/
val platformAddressRecipients: ByteArray? = null,

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: Precompiled Android clients can no longer construct or copy an asset-lock row
Impact: An app that upgrades the Android AAR while retaining a library compiled against the old AssetLockEntity can get NoSuchMethodError when that library constructs or copies a row.

The new defaulted property preserves Kotlin source calls after recompilation, but changes the JVM descriptors of the public constructor, copy, and copy$default, even relative to the stacked v17 model. Room’s migration preserves stored data, not those entry points. Either preserve the old descriptors if binary compatibility is required, or document in the PR and release notes that consumers must rebuild dependent Android libraries.

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

Comment on lines +2519 to +2525
env.convert_byte_array(JByteArray::from(value)).map(Some)
});
let Some(loaded) = loaded else {
return ERR_JNI;
};
let Ok(()) =
platform_address_recipients_value(loaded.as_ref().map(Vec::len), recipients_capacity)

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: JNI copies oversized recipient records before checking the 4 KiB limit
Impact: A custom persistence bridge returning a large malformed byte array can trigger an equally large native allocation during wallet restore instead of a bounded load error.

convert_byte_array allocates a native Vec for the full Java array before the trampoline compares its length with the destination capacity and the format maximum. Room already checks the length, but custom persistence bridges need not. Read the Java array length first and reject a non-null array outside 1..=min(recipients_capacity, MAX_LEN) before allocating or copying it.

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

Comment on lines +455 to +458
internal fun recordedPayeeLines(payees: List<ManagedPlatformWallet.FundRecipient>): List<String> =
payees.map { payee ->
val address = payee.hash.toHex().take(16) + "…"
payee.credits?.let { "$address — $it credits" } ?: "$address — remainder (this wallet)"

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 payment confirmation shows only a prefix of each destination
Impact: A user checking an interrupted payment cannot compare the recorded destination with the full Platform address supplied by the payee.

The confirmation shows only eight bytes of each 20-byte hash, omits the address type, and provides no way to inspect the rest. A prefix works as a list label but not as the only destination on an irreversible payment’s confirmation screen. Show the full network-formatted address or let the user reveal and copy it alongside the compact label.

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

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.

3 participants