You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
swift-sdk: keep the signer alive with withExtendedLifetime in every wrapper that passes its handle to the FFI #5939
Every SwiftDashSDK wrapper that passes signer.handle to the FFI guarantees on its own that the signer outlives the call. A caller does not need its own keepalive.
Current Behavior
KeychainSigner registers its callback context with Unmanaged.passUnretained(self), so the Swift object must stay alive until the native call returns. The wrappers ensure this in two different ways:
Bare keepalive. 20 wrappers read signer.handle and then write _ = signer as the first line of their Task.detached closure. This covers transferCredits, transferCreditsToAddresses, withdrawCredits and topUpFromAddresses, and the token actions:
Swift guarantees an object's lifetime only up to its last use. The language promises nothing about _ = signer at the start of a closure. In practice the closure context retains the signer until the task ends, but only withExtendedLifetime states this guarantee. Because the wrappers do not provide it, apps add their own keepalives, as dashpay/dashwallet-ios#1407 does around the identity-credit calls.
The same counts hold on v5.1-dev.
Possible Solution
Wrap the FFI call in withExtendedLifetime(signer) inside each detached closure, then drop the bare _ = signer and update the KeychainSigner doc. A shared helper (signer.withHandle { handle in … }) would leave a new wrapper only one way to do this. There is no behaviour change.
Context
Raised by the review of dashpay/dashwallet-ios#1407: "Identity FFI execution and signer lifetime remain caller conventions". After this lands, the app-side keepalive in LiveIdentityCreditsSend can go.
Activity