Repository navigation
fix(sdk): refresh SDK protocol version to the network's on startup and network switch #3886
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f87f6ed
fix(sdk): refresh SDK protocol version to the network's on startup an…
QuantumExplorer e744e0d
fix(sdk): use configured request settings and structured error mappin…
QuantumExplorer 79f4b1c
feat(sdk): floor SDK protocol version at the per-network minimum
QuantumExplorer d062b14
fix(sdk): pin regtest protocol-version floor to 12
QuantumExplorer 75df20f
refactor(sdk): move refresh_protocol_version into its own module
QuantumExplorer 9274936
refactor(sdk): borrow version fields in extract and document construc…
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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,9 @@ | ||
| // Protocol version queries | ||
| pub mod refresh; | ||
| pub mod upgrade_state; | ||
| pub mod upgrade_vote_status; | ||
|
|
||
| // Re-export all public functions for convenient access | ||
| pub use refresh::dash_sdk_refresh_protocol_version; | ||
| pub use upgrade_state::dash_sdk_protocol_version_get_upgrade_state; | ||
| pub use upgrade_vote_status::dash_sdk_protocol_version_get_upgrade_vote_status; |
76 changes: 76 additions & 0 deletions
76
packages/rs-sdk-ffi/src/protocol_version/queries/refresh.rs
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,76 @@ | ||
| use crate::sdk::SDKWrapper; | ||
| use crate::types::SDKHandle; | ||
| use crate::{DashSDKError, DashSDKErrorCode, DashSDKResult}; | ||
| use std::ffi::CString; | ||
|
|
||
| /// Refresh the SDK's protocol version from the connected network. | ||
| /// | ||
| /// Issues an unproved `getStatus` against the network and ratchets this SDK's | ||
| /// auto-detected protocol version up to the network's current Drive protocol | ||
| /// version (see [`dash_sdk::Sdk::refresh_protocol_version`]). The resulting | ||
| /// protocol version number propagates to every clone of this SDK — including | ||
| /// the `Sdk` clone held by a `PlatformWalletManager` — because the version is | ||
| /// stored in a shared `Arc<AtomicU32>`. | ||
| /// | ||
| /// Call this on app start and after every network switch so fee-sensitive | ||
| /// flows (shielded pool shield/unshield/transfer/withdraw) reserve against the | ||
| /// network's actual protocol version instead of the SDK's seed version. | ||
| /// | ||
| /// # Parameters | ||
| /// * `sdk_handle` - Handle to the SDK instance. | ||
| /// | ||
| /// # Returns | ||
| /// * On success, a `DashSDKResult` carrying a heap-allocated C string with the | ||
| /// decimal protocol version number (e.g. `"12"`). | ||
| /// * On failure, a `DashSDKResult` carrying an error. | ||
| /// | ||
| /// # Safety | ||
| /// - `sdk_handle` must be a valid, non-null pointer to an initialized `SDKHandle`. | ||
| /// - The function does not retain references to the input pointer beyond the duration of the call. | ||
| /// - On success, the returned `DashSDKResult` contains a heap-allocated C string; the caller must | ||
| /// free it using the SDK's string-free routine to avoid leaks. | ||
| /// - Passing a dangling or invalid pointer for `sdk_handle` results in undefined behavior. | ||
| #[no_mangle] | ||
| pub unsafe extern "C" fn dash_sdk_refresh_protocol_version( | ||
| sdk_handle: *const SDKHandle, | ||
| ) -> DashSDKResult { | ||
| if sdk_handle.is_null() { | ||
| return DashSDKResult::error(DashSDKError::new( | ||
| DashSDKErrorCode::InvalidParameter, | ||
| "SDK handle is null".to_string(), | ||
| )); | ||
| } | ||
|
|
||
| let wrapper = &*(sdk_handle as *const SDKWrapper); | ||
|
|
||
| let result = wrapper | ||
| .runtime | ||
| .block_on(wrapper.sdk.refresh_protocol_version()); | ||
|
|
||
| match result { | ||
| Ok(version) => match CString::new(version.to_string()) { | ||
| Ok(c_str) => DashSDKResult::success_string(c_str.into_raw()), | ||
| Err(e) => DashSDKResult::error(DashSDKError::new( | ||
| DashSDKErrorCode::InternalError, | ||
| format!("Failed to create CString: {}", e), | ||
| )), | ||
| }, | ||
| Err(e) => DashSDKResult::error(DashSDKError::new( | ||
| DashSDKErrorCode::InternalError, | ||
| format!("Failed to refresh protocol version: {}", e), | ||
| )), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn test_refresh_protocol_version_null_handle() { | ||
| unsafe { | ||
| let result = dash_sdk_refresh_protocol_version(std::ptr::null()); | ||
| assert!(!result.error.is_null()); | ||
| } | ||
| } | ||
| } |
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.
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.