-
Notifications
You must be signed in to change notification settings - Fork 53
feat(swift-sdk): use SPV-synced quorums for Platform proof verification #3417
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuantumExplorer
wants to merge
7
commits into
v3.1-dev
Choose a base branch
from
feat/ios-spv-quorums
base: v3.1-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f4703d6
feat(swift-sdk): use SPV-synced quorums for Platform proof verification
QuantumExplorer ad6904a
refactor(rs-sdk-ffi): move SPV context provider from Swift to Rust
QuantumExplorer d9e478e
feat(platform-wallet): add pure-Rust SpvContextProvider
QuantumExplorer 8d2bb27
fix: address CodeRabbit review feedback on SPV quorums PR
QuantumExplorer fa7e531
feat: use pure-Rust SpvContextProvider, bump rust-dashcore
QuantumExplorer 54b6ed0
fix: eliminate race between didSet and handleNetworkSwitch
QuantumExplorer cfde224
fix: use try_read() instead of blocking_read(), add dep: prefix
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
packages/swift-sdk/Sources/SwiftDashSDK/Core/SPV/SPVContextProvider.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| import DashSDKFFI | ||
| import Foundation | ||
|
|
||
| // MARK: - C Callback: Get quorum public key from SPV | ||
|
|
||
| /// C-compatible callback that bridges Platform SDK quorum key requests to the SPV client. | ||
| /// | ||
| /// `handle` is the raw `FFIDashSpvClient*` pointer, passed as `core_handle` in | ||
| /// `ContextProviderCallbacks`. The SPV FFI function `ffi_dash_spv_get_quorum_public_key` | ||
| /// retrieves the BLS public key for the given quorum from the locally synced masternode list. | ||
| /// | ||
| /// - Parameters: | ||
| /// - handle: Raw pointer to `FFIDashSpvClient` (cast from `void*`). | ||
| /// - quorumType: The quorum type identifier. | ||
| /// - quorumHash: Pointer to 32-byte quorum hash. | ||
| /// - coreChainLockedHeight: The core chain locked height for the request. | ||
| /// - outPubkey: Pointer to a 48-byte output buffer for the BLS public key. | ||
| /// - Returns: `CallbackResult` with `success: true` on success or error details on failure. | ||
| func spvGetQuorumPublicKey( | ||
| handle: UnsafeMutableRawPointer?, | ||
| quorumType: UInt32, | ||
| quorumHash: UnsafePointer<UInt8>?, | ||
| coreChainLockedHeight: UInt32, | ||
| outPubkey: UnsafeMutablePointer<UInt8>? | ||
| ) -> CallbackResult { | ||
| guard let handle = handle else { | ||
| return CallbackResult(success: false, error_code: -1, error_message: nil) | ||
| } | ||
| guard let quorumHash = quorumHash, let outPubkey = outPubkey else { | ||
| return CallbackResult(success: false, error_code: -2, error_message: nil) | ||
| } | ||
|
|
||
| let client = handle.assumingMemoryBound(to: FFIDashSpvClient.self) | ||
| let ffiResult = ffi_dash_spv_get_quorum_public_key( | ||
| client, quorumType, quorumHash, coreChainLockedHeight, outPubkey, 48 | ||
| ) | ||
|
|
||
| if ffiResult.error_code == 0 { | ||
| return CallbackResult(success: true, error_code: 0, error_message: nil) | ||
| } else { | ||
| return CallbackResult( | ||
| success: false, | ||
| error_code: ffiResult.error_code, | ||
| error_message: ffiResult.error_message | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - C Callback: Get platform activation height from SPV | ||
|
|
||
| /// C-compatible callback that bridges Platform SDK activation height requests to the SPV client. | ||
| /// | ||
| /// `handle` is the raw `FFIDashSpvClient*` pointer. The SPV FFI function | ||
| /// `ffi_dash_spv_get_platform_activation_height` returns the core block height at which | ||
| /// Platform was activated, as determined from the locally synced chain. | ||
| /// | ||
| /// - Parameters: | ||
| /// - handle: Raw pointer to `FFIDashSpvClient` (cast from `void*`). | ||
| /// - outHeight: Pointer to a `UInt32` where the activation height will be written. | ||
| /// - Returns: `CallbackResult` with `success: true` on success or error details on failure. | ||
| func spvGetPlatformActivationHeight( | ||
| handle: UnsafeMutableRawPointer?, | ||
| outHeight: UnsafeMutablePointer<UInt32>? | ||
| ) -> CallbackResult { | ||
| guard let handle = handle else { | ||
| return CallbackResult(success: false, error_code: -1, error_message: nil) | ||
| } | ||
| guard let outHeight = outHeight else { | ||
| return CallbackResult(success: false, error_code: -2, error_message: nil) | ||
| } | ||
|
|
||
| let client = handle.assumingMemoryBound(to: FFIDashSpvClient.self) | ||
| let ffiResult = ffi_dash_spv_get_platform_activation_height(client, outHeight) | ||
|
|
||
| if ffiResult.error_code == 0 { | ||
| return CallbackResult(success: true, error_code: 0, error_message: nil) | ||
| } else { | ||
| return CallbackResult( | ||
| success: false, | ||
| error_code: ffiResult.error_code, | ||
| error_message: ffiResult.error_message | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| // MARK: - Helper to create ContextProviderCallbacks | ||
|
|
||
| /// Creates a `ContextProviderCallbacks` struct configured to use the SPV client | ||
| /// for quorum key lookups and platform activation height. | ||
| /// | ||
| /// The returned struct is suitable for passing to `dash_sdk_create_with_callbacks`. | ||
| /// The SPV client must remain alive for the entire lifetime of the SDK instance | ||
| /// that uses these callbacks. | ||
| /// | ||
| /// - Parameter spvClientHandle: Raw pointer to the `FFIDashSpvClient`, obtained | ||
| /// from `SPVClient.unsafeFFIClientPointer`. | ||
| /// - Returns: A `ContextProviderCallbacks` ready to pass to `dash_sdk_create_with_callbacks`. | ||
| func makeSPVContextProviderCallbacks(spvClientHandle: UnsafeMutableRawPointer) -> ContextProviderCallbacks { | ||
| return ContextProviderCallbacks( | ||
| core_handle: spvClientHandle, | ||
| get_platform_activation_height: spvGetPlatformActivationHeight, | ||
| get_quorum_public_key: spvGetQuorumPublicKey | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.