Repository navigation
feat(swift-example-app): shield the whole Core balance (Max) and recover it after a restart - #6050
Merged
QuantumExplorer merged 16 commits intoNov 22, 2026
Merged
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basic explanation
What this does: The example iOS app can now move everything held at one Core (L1) account index into the wallet's own shielded balance in one step, called "Max". Before it runs, the screen shows the wallet's estimate of what will be swept, the fees, and what arrives in the shielded balance. If the app is killed mid-transfer, the next launch finds the unfinished transfer and offers to finish that same asset lock instead of losing track of it.
Value: The Swift SDK already supported this (preview, execute, status by a durable operation id), but no app screen used it, so it could not be tested by hand or shown to integrators. It also gives the Kotlin port a reference screen with fixed accessibility ids.
Risks: Low. No Rust or FFI changes and no consensus effect. One SDK wrapper,
shieldedResumeFundFromAssetLock, now waits inside the manager's operation admission (see Public interface changes). Otherwise the change is app-only, and the existing fixed-amount shield path is unchanged unless the new toggle is turned on. Max only pays the wallet's own shielded address, because the drain sweeps whatever is eligible when it runs, which can exceed the estimate, and new Max transfers are not offered on mainnet until a drain's completion is proof-backed (#5580). Resume can only finish an existing asset lock, never build a new one. What could go wrong is in the app itself: a stored operation id that is never cleared would keep a stale row on the wallet screen, and Rust refuses a new Max while one is unfinished, so the user must resume it first. The flow has not yet been run on a funded testnet wallet or through a process kill (see testing).Issue being fixed or feature implemented
docs/sdk/sdk-parity-manifest.jsonlistedshielded.core_wallet_drainas supported in the Swift SDK and unsupported in SwiftExampleApp:shieldedWalletDrainPreview,shieldedFundFromWalletDrainandshieldedWalletDrainStatushad no caller in the app.No open PR or issue covered the app side. Related SDK work: #5528, #5788; issues #5607, #5737, #5478, #5580.
What was done?
ShieldedFundFromAssetLockView, Core Balance source). When it is on, the amount field is replaced by the preview fromshieldedWalletDrainPreviewfor the selected account index, and the button reads "Shield Max". The preview carries the wallet and account index it was read for; submit requires a match and uses the quoted index. Max pays the wallet's own shielded address, read at submit, with no override field, until the SDK can cap the swept amount (Wallet drain: let the host cap the swept balance at what the user confirmed #5607). The drain runs through the existingShieldedFundFromAssetLockCoordinator, so it shares the per-wallet single-flight rule and the five-step progress UI with the fixed-amount shield.WalletDrainOperationStorewrites the operation UUID, wallet, network, account index and recipient to a JSON file (.atomic) before the FFI call, as the SDK contract requires. It is a file rather thanUserDefaultsbecause it must be on disk before the call starts, and rather than a SwiftData model to avoid changing the shared model graph for an app-only marker. A corrupt file throws instead of reading as empty, so an unfinished transfer cannot be hidden.WalletDrainCoordinator.reconcilereadsshieldedWalletDrainStatusfor every stored id at launch, when the wallet screen opens, and after each attempt. A stored id is forgotten when Rust reportscompleted, ornotSentwith no attempt overlapping the read. Apendingresult or a failed read keeps it. Unfinished transfers are listed on the wallet screen under "Unfinished Max Transfers". Resume is offered only when a status read named the asset lock's outpoint, and callsshieldedResumeFundFromAssetLockwith that exact outpoint and the stored recipient, which can never build a new lock; Rust writes the drain's completion receipt when it lands. A row without an outpoint offers only Check again, which re-reads the status. Progress follows the operation's own lock (by drain id or resumed outpoint), not the wallet's newest shielded lock. Deleting a wallet removes its stored ids.operationIdhas a stored marker is not also offered in "Pending Platform Top Ups". A drain lock without a marker stays there, since resuming by exact outpoint is the fallback Rust supports.SdkRebuildOutcome.fundingInFlight; Max and Resume refuse to start while a rebuild runs. Otherwise a rebuild could wait forever for a funding that needs a ChainLock from the SPV client it had just stopped.shieldedResumeFundFromAssetLocknow runs inside the manager's native-operation admission, sodeleteWalletandshutdown()wait for it.shieldedFundFromCoinJoinDrain), because the app shows CoinJoin balances only read-only and has no flow that starts from one; and a Max option in the send flow's Core to Shielded pair.TEST_PLAN.mdrows SH-18 (Max), SH-19 (restart), SH-20 (second Max refused while one is unfinished) and arestarttag. The manifest entry now sayspartialfor the Swift example app, andPARITY_SUMMARY.mdis regenerated.Before / after
Shield from Core screen, Core Balance source:
App killed after the asset lock was broadcast, then relaunched:
The figures above illustrate the layout; they are not from a run.
Public interface changes
No
pubitem in any Rust crate and no FFI symbol changed. InSwiftDashSDKno public signature changed; one public method's runtime behaviour did:PlatformWalletManager.shieldedResumeFundFromAssetLock(walletId:outPointTxid:outPointVout:recipients:surplusOutput:)now runs inside the manager's native-operation admission, as the wallet-drain wrappers already did. While it runs,deleteWallet(walletId:)throws ("an async native operation is in flight") andshutdown()waits for it. During a shutdown it is rejected withPlatformWalletError.invalidHandleinstead of calling into Rust. Existing callers compile unchanged.withWalletDrainNativeOperationis renamedwithAdmittedNativeOperationand moved toPlatformWalletManager.swift.App side: All new types (
WalletDrainOperationStore,WalletDrainOperationRecord,WalletDrainCoordinator, the two views) are internal to the SwiftExampleApp target. New accessibility ids, for the Kotlin app to reuse verbatim:shieldFromCore.maxToggle,shieldFromCore.maxPreview.{swept,l1Fee,poolFee,receive,status,refreshButton},shieldFromCore.fixedRecipient,shieldFromCore.submitButton,walletDetail.unfinishedMaxTransfers,walletDetail.unfinishedMaxTransfer.resumeButton,walletDetail.unfinishedMaxTransfer.checkAgainButton.How Has This Been Tested?
build_ios.sh --target sim --profile dev(framework), then the SwiftExampleApp target built with-warnings-as-errors: BUILD SUCCEEDED.xcodebuild test -only-testing:SwiftExampleAppTests/WalletDrainRecoveryTestsplusPendingPlatformTopUpResumeTestsandWalletBalanceCardStateTestson an iPhone 17 simulator (iOS 27.2): plusWalletDeletionTests,SdkRebuildSequenceTestsandAppStateSdkRebuildTests: all 64 passed. SDK:PlatformWalletShutdownTestsandWalletDrainTests, 21 of 21 passed, including the newtestShouldRefuseDeleteWalletWhileAnAdmittedOperationIsInFlight. The new tests cover the store surviving a reopen, removing only the named record or wallet, a corrupt file and an unwritable directory throwing, the rule for forgetting a stored id (including anotSentread overlapped by an attempt), a completed outcome that carries an error counting as done, the row action (In progress / Resume by outpoint / Check again), the progress lock matching, the progress steps for a failed attempt with no lock, the mainnet rule, the resumable-list decision including Built drain checkpoints, progress for recovered and completed locks, the resume message when a lock was never stored, and the rebuild refusal while a funding is in flight.python3 scripts/check_sdk_parity_manifest.py --write-summary: OK.Not run yet: SH-18, SH-19 and SH-20 on a funded testnet wallet, including the process-death run of SH-19. The new screens have compiled but have not been driven in the simulator. For that reason the manifest keeps the Swift example app at
partial; the host-widerestart: testedrests on the existing SDK tests.Separately, building the test target with
-warnings-as-errorsfails inStateTransitionTests.swift, which this PR does not touch; the tests above ran without that flag.Breaking Changes
None.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
7226e6b/self-reviewedsdk-parity— you own itkotlin-sdk(packages/kotlin-sdk/PARITY_SUMMARY.md) — HashEngineeringswift-sdk(packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManager.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerShieldedFunding.swift,packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PlatformWalletManagerWalletDrain.swiftand 24 more) — llbartekll or romchornyiWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.