Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/data_contract/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub unsafe extern "C" fn dash_sdk_data_contract_put_to_platform(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let data_contract = &*(data_contract_handle as *const DataContract);
let identity_public_key = &*(identity_public_key_handle as *const IdentityPublicKey);
let signer = &*(signer_handle as *const VTableSigner);
Expand Down Expand Up @@ -86,7 +86,7 @@ pub unsafe extern "C" fn dash_sdk_data_contract_put_to_platform_and_wait(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let data_contract = &*(data_contract_handle as *const DataContract);
let identity_public_key = &*(identity_public_key_handle as *const IdentityPublicKey);
let signer = &*(signer_handle as *const VTableSigner);
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/document/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub unsafe extern "C" fn dash_sdk_document_create(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

let contract_id_str = match CStr::from_ptr(params.data_contract_id).to_str() {
Ok(s) => s,
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub unsafe extern "C" fn dash_sdk_document_delete(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

// Parse document ID
let document_id_str = match CStr::from_ptr(document_id).to_str() {
Expand Down Expand Up @@ -218,7 +218,7 @@ pub unsafe extern "C" fn dash_sdk_document_delete_and_wait(

info!("[DOCUMENT DELETE] starting document delete operation");

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

// Parse document ID
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub unsafe extern "C" fn dash_sdk_document_update_price_of_document(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -195,7 +195,7 @@ pub unsafe extern "C" fn dash_sdk_document_update_price_of_document_and_wait(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub unsafe extern "C" fn dash_sdk_document_purchase(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -226,7 +226,7 @@ pub unsafe extern "C" fn dash_sdk_document_purchase_and_wait(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub unsafe extern "C" fn dash_sdk_document_put_to_platform(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let identity_public_key = &*(identity_public_key_handle as *const IdentityPublicKey);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);
Expand Down Expand Up @@ -228,7 +228,7 @@ pub unsafe extern "C" fn dash_sdk_document_put_to_platform_and_wait(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let identity_public_key = &*(identity_public_key_handle as *const IdentityPublicKey);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/document/queries/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub unsafe extern "C" fn dash_sdk_document_fetch_by_contract_id(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

let contract_id_str = match CStr::from_ptr(contract_id).to_str() {
Ok(s) => s,
Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub unsafe extern "C" fn dash_sdk_document_replace_on_platform(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -206,7 +206,7 @@ pub unsafe extern "C" fn dash_sdk_document_replace_on_platform_and_wait(

info!("[DOCUMENT REPLACE] starting document replace operation");

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down
4 changes: 2 additions & 2 deletions packages/rs-sdk-ffi/src/document/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub unsafe extern "C" fn dash_sdk_document_transfer_to_identity(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
// Parse data contract ID
let contract_id_str = match CStr::from_ptr(data_contract_id).to_str() {
Expand Down Expand Up @@ -237,7 +237,7 @@ pub unsafe extern "C" fn dash_sdk_document_transfer_to_identity_and_wait(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let document = &*(document_handle as *const Document);
// Parse data contract ID
let contract_id_str = match CStr::from_ptr(data_contract_id).to_str() {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/identity/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub unsafe extern "C" fn dash_sdk_identity_create(sdk_handle: *mut SDKHandle) ->
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

let result: Result<Identity, FFIError> = wrapper.runtime.block_on(async {
// For now, create a random identity
Expand Down
8 changes: 4 additions & 4 deletions packages/rs-sdk-ffi/src/identity/put.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub unsafe extern "C" fn dash_sdk_identity_put_to_platform_with_instant_lock(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let identity = &*(identity_handle as *const Identity);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -140,7 +140,7 @@ pub unsafe extern "C" fn dash_sdk_identity_put_to_platform_with_instant_lock_and
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let identity = &*(identity_handle as *const Identity);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -225,7 +225,7 @@ pub unsafe extern "C" fn dash_sdk_identity_put_to_platform_with_chain_lock(
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let identity = &*(identity_handle as *const Identity);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down Expand Up @@ -302,7 +302,7 @@ pub unsafe extern "C" fn dash_sdk_identity_put_to_platform_with_chain_lock_and_w
));
}

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);
let identity = &*(identity_handle as *const Identity);
let signer = &*(signer_handle as *const crate::signer::VTableSigner);

Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/identity/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub unsafe extern "C" fn dash_sdk_identity_transfer_credits(
signer_handle
);

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

// SAFETY: Null check was performed above. Caller must guarantee the pointer is valid
// and points to a live Identity. We cannot detect dangling pointers without a handle
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/identity/withdraw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub unsafe extern "C" fn dash_sdk_identity_withdraw(
core_fee_per_byte, public_key_id, "dash_sdk_identity_withdraw: parameters"
);

let wrapper = &mut *(sdk_handle as *mut SDKWrapper);
let wrapper = &*(sdk_handle as *const SDKWrapper);

// SAFETY: Null check was performed above. Caller must guarantee the pointer is valid
// and points to a live Identity. We cannot detect dangling pointers without a handle
Expand Down
16 changes: 16 additions & 0 deletions packages/rs-sdk-ffi/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ fn apply_version(builder: SdkBuilder, platform_version: u32) -> Result<SdkBuilde
}

/// Internal SDK wrapper
///
/// A single `SDKHandle` is used from several threads at once (the Swift SDK
/// runs Platform queries concurrently off the caller's actor), so every FFI
/// entry point that is handed a live handle must borrow it shared:
/// `&*(handle as *const SDKWrapper)`. Nothing here needs `&mut` once the
/// wrapper is built: `Sdk` is `Send + Sync`, `runtime` is an `Arc`, and the
/// trusted provider mutates only through its own interior locks. Taking
/// `&mut SDKWrapper` from a handle another thread may be using would alias a
/// live shared borrow, which is undefined behaviour even if nothing is
/// written. The one exclusive operation is `dash_sdk_destroy`, whose contract
/// is that the caller has already stopped every other use of the handle.
pub(crate) struct SDKWrapper {
pub sdk: Sdk,
pub runtime: Arc<BigStackRuntime>,
Expand Down Expand Up @@ -514,6 +525,11 @@ pub unsafe extern "C" fn dash_sdk_create_trusted(config: *const DashSDKConfig) -
/// # Safety
/// - `handle` must be a valid pointer previously returned by this SDK and not yet destroyed.
/// - It may be null (no-op). After this call the handle must not be used again.
/// - This is the only entry point that takes the wrapper exclusively, so no
/// other call on the same handle may be in flight or start concurrently.
/// The Swift SDK calls it only from `SDK.deinit`, which cannot run while a
/// query holds its `SDK` (`performBlockingQuery` retains `self` across the
/// FFI call).
#[no_mangle]
pub unsafe extern "C" fn dash_sdk_destroy(handle: *mut SDKHandle) {
if !handle.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/burn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub unsafe extern "C" fn dash_sdk_token_burn(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub unsafe extern "C" fn dash_sdk_token_claim(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/config_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub unsafe extern "C" fn dash_sdk_token_update_contract_token_configuration(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };

// Convert transition_owner_id from bytes to Identifier (32 bytes)
let transition_owner_id = {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/destroy_frozen_funds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub unsafe extern "C" fn dash_sdk_token_destroy_frozen_funds(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/emergency_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub unsafe extern "C" fn dash_sdk_token_emergency_action(
// SAFETY: We've verified all pointers are non-null above
// However, we cannot validate if they point to valid memory without dereferencing
// For test safety, we should create proper mock handles instead of using arbitrary values
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/freeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub unsafe extern "C" fn dash_sdk_token_freeze(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };

// Convert transition_owner_id from bytes to Identifier (32 bytes)
let transition_owner_id = {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub unsafe extern "C" fn dash_sdk_token_mint(

eprintln!("🟦 FFI TOKEN MINT: Extracting pointers");
// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/purchase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub unsafe extern "C" fn dash_sdk_token_purchase(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/set_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub unsafe extern "C" fn dash_sdk_token_set_price(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };

// Convert transition_owner_id from bytes to Identifier (32 bytes)
let transition_owner_id = {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub unsafe extern "C" fn dash_sdk_token_transfer(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };
let identity_public_key = unsafe { &*(identity_public_key_handle as *const IdentityPublicKey) };
let signer = unsafe { &*(signer_handle as *const crate::signer::VTableSigner) };
let params = unsafe { &*params };
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-sdk-ffi/src/token/unfreeze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub unsafe extern "C" fn dash_sdk_token_unfreeze(
}

// SAFETY: We've verified all pointers are non-null above
let wrapper = unsafe { &mut *(sdk_handle as *mut SDKWrapper) };
let wrapper = unsafe { &*(sdk_handle as *const SDKWrapper) };

// Convert transition_owner_id from bytes to Identifier (32 bytes)
let transition_owner_id = {
Expand Down
Loading
Loading