Skip to content
Closed
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
59 changes: 0 additions & 59 deletions packages/rs-platform-wallet-ffi/src/asset_lock/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,65 +313,6 @@ pub unsafe extern "C" fn asset_lock_manager_catch_up_blocking(
}
}

/// Recover a tracked asset lock from a serialized transaction.
///
/// Re-tracks the asset lock in memory so it can be resumed later.
/// The transaction must be a valid asset lock transaction with a
/// special transaction payload.
#[no_mangle]
#[allow(clippy::too_many_arguments)]
pub unsafe extern "C" fn asset_lock_manager_recover(
handle: Handle,
tx_bytes: *const u8,
tx_bytes_len: usize,
amount_duffs: u64,
account_index: u32,
funding_type: u32,
identity_index: u32,
txid: *const [u8; 32],
vout: u32,
proof_bytes: *const u8,
proof_len: usize,
) -> PlatformWalletFFIResult {
check_ptr!(tx_bytes);
check_ptr!(txid);

// Parse transaction
let tx_data = std::slice::from_raw_parts(tx_bytes, tx_bytes_len);
let tx: dashcore::Transaction =
unwrap_result_or_return!(dashcore::consensus::deserialize(tx_data));

let funding = unwrap_option_or_return!(super::build::parse_funding_type(funding_type));

let out_point = parse_outpoint(txid, vout);

// Parse optional proof
let proof = if !proof_bytes.is_null() && proof_len > 0 {
let data = std::slice::from_raw_parts(proof_bytes, proof_len);
let (p, _) = unwrap_result_or_return!(dpp::bincode::decode_from_slice(
data,
dpp::bincode::config::standard()
));
Some(p)
} else {
None
};

let option = ASSET_LOCK_MANAGER_STORAGE.with_item(handle, |manager| {
manager.recover_asset_lock_blocking(
tx,
amount_duffs,
account_index,
funding,
identity_index,
out_point,
proof,
);
});
unwrap_option_or_return!(option);
PlatformWalletFFIResult::ok()
}

#[cfg(test)]
mod tests {
use super::{
Expand Down
70 changes: 0 additions & 70 deletions packages/rs-platform-wallet-ffi/src/contact.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use crate::contact_request::CONTACT_REQUEST_STORAGE;
use crate::error::*;
use crate::handle::*;
use crate::identity_manager::ffi_noop_persister;
use crate::types::*;
use crate::{check_ptr, unwrap_option_or_return, unwrap_result_or_return};

Expand Down Expand Up @@ -95,74 +93,6 @@ pub unsafe extern "C" fn managed_identity_is_contact_established(
PlatformWalletFFIResult::ok()
}

/// Send a contact request from this identity to another
/// The request will be added to sent_contact_requests
/// If there's already an incoming request from the recipient, the contact will be automatically established
#[no_mangle]
pub unsafe extern "C" fn managed_identity_send_contact_request(
identity_handle: Handle,
request_handle: Handle,
) -> PlatformWalletFFIResult {
let request_result = CONTACT_REQUEST_STORAGE.with_item(request_handle, |req| req.clone());

let request = unwrap_option_or_return!(request_result);

let option = MANAGED_IDENTITY_STORAGE.with_item_mut(identity_handle, |identity| {
// Return the persist result so a failure surfaces through the FFI
// result instead of being swallowed — correct for any persister on this
// handle path (today the infallible `ffi_noop_persister`).
identity.add_sent_contact_request(request, &ffi_noop_persister())
});
unwrap_result_or_return!(unwrap_option_or_return!(option));
PlatformWalletFFIResult::ok()
}

/// Accept an incoming contact request
/// This will add the request to incoming_contact_requests
/// If there's already a sent request to the sender, the contact will be automatically established
#[no_mangle]
pub unsafe extern "C" fn managed_identity_accept_contact_request(
identity_handle: Handle,
request_handle: Handle,
) -> PlatformWalletFFIResult {
let request_result = CONTACT_REQUEST_STORAGE.with_item(request_handle, |req| req.clone());

let request = unwrap_option_or_return!(request_result);

let option = MANAGED_IDENTITY_STORAGE.with_item_mut(identity_handle, |identity| {
// Return the persist result so a failure surfaces through the FFI
// result instead of being swallowed — correct for any persister on this
// handle path (today the infallible `ffi_noop_persister`).
identity.add_incoming_contact_request(request, &ffi_noop_persister())
});
unwrap_result_or_return!(unwrap_option_or_return!(option));
PlatformWalletFFIResult::ok()
}

/// Ignore a contact sender (per-sender mute, = block, reversible).
///
/// Local in-memory path on a managed-identity handle (no persister) —
/// drops the sender's pending incoming request and records them in
/// `ignored_senders`. The durable, persisted path is the wallet-scoped
/// `platform_wallet_ignore_contact_sender`.
#[no_mangle]
pub unsafe extern "C" fn managed_identity_ignore_contact_sender(
identity_handle: Handle,
sender_id: *const u8,
) -> PlatformWalletFFIResult {
let id = unwrap_result_or_return!(unsafe { read_identifier(sender_id) });

let option = MANAGED_IDENTITY_STORAGE.with_item_mut(identity_handle, |identity| {
// `ignore_sender` returns a `ContactChangeSet`, not a `Result` — there is
// no error to surface. This handle has no persister, so the changeset is
// intentionally dropped; the durable `platform_wallet_ignore_contact_sender`
// path persists it.
drop(identity.ignore_sender(&id));
});
unwrap_option_or_return!(option);
PlatformWalletFFIResult::ok()
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
41 changes: 0 additions & 41 deletions packages/rs-platform-wallet-ffi/src/contact_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,6 @@ lazy_static::lazy_static! {
pub static ref CONTACT_REQUEST_STORAGE: HandleStorage<ContactRequest> = HandleStorage::new();
}

/// Create a new contact request
#[no_mangle]
pub unsafe extern "C" fn contact_request_create(
sender_id: *const u8,
recipient_id: *const u8,
sender_key_index: u32,
recipient_key_index: u32,
account_reference: u32,
encrypted_public_key_bytes: *const std::os::raw::c_uchar,
encrypted_public_key_len: usize,
core_height_created_at: u32,
created_at: u64,
out_handle: *mut Handle,
) -> PlatformWalletFFIResult {
check_ptr!(encrypted_public_key_bytes);
check_ptr!(out_handle);

let sender = unwrap_result_or_return!(unsafe { read_identifier(sender_id) });
let recipient = unwrap_result_or_return!(unsafe { read_identifier(recipient_id) });

let encrypted_key =
unsafe { std::slice::from_raw_parts(encrypted_public_key_bytes, encrypted_public_key_len) }
.to_vec();

let contact_request = ContactRequest::new(
sender,
recipient,
sender_key_index,
recipient_key_index,
account_reference,
encrypted_key,
core_height_created_at,
created_at,
);

let handle = CONTACT_REQUEST_STORAGE.insert(contact_request);
unsafe { *out_handle = handle };

PlatformWalletFFIResult::ok()
}

/// Create a contact request handle from a managed identity's sent request
#[no_mangle]
pub unsafe extern "C" fn managed_identity_get_sent_contact_request(
Expand Down
23 changes: 20 additions & 3 deletions packages/rs-platform-wallet-ffi/src/core_wallet_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,23 @@ mod tests {
}

/// The FFI entry carries the platform HTTP port gated by

/// Release a heap `MasternodeEntryFFI` array the way the removed
/// `platform_wallet_manager_free_masternodes` export used to. The v1
/// struct is still part of the ABI (V2 embeds it), so these layout
/// pins keep building one — they just no longer need a public free
/// routine to hand it back.
unsafe fn free_v1_entries(entries: *mut MasternodeEntryFFI, count: usize) {
if entries.is_null() || count == 0 {
return;
}
let slice = std::slice::from_raw_parts_mut(entries, count);
for entry in slice.iter() {
crate::wallet::free_masternode_entry_strings(entry);
}
let _ = Box::from_raw(std::ptr::slice_from_raw_parts_mut(entries, count));
}

/// `has_platform_http_port`, and releases its heap C strings through the
/// public free routine.
#[test]
Expand All @@ -1986,9 +2003,9 @@ mod tests {
!entry.platform_ownership_checked,
"default record: unchecked"
);
// Release the entry's heap C strings through the public free routine.
// Release the entry's heap C strings.
let entries = Box::into_raw(vec![entry].into_boxed_slice()) as *mut MasternodeEntryFFI;
unsafe { crate::wallet::platform_wallet_manager_free_masternodes(entries, 1) };
unsafe { free_v1_entries(entries, 1) };
}

/// Pin the original array element layout used by already-built C/Swift
Expand Down Expand Up @@ -2066,7 +2083,7 @@ mod tests {
.unwrap(),
"2.2.2.2:9999"
);
unsafe { crate::wallet::platform_wallet_manager_free_masternodes(v1, 2) };
unsafe { free_v1_entries(v1, 2) };

let v2 = vec![
masternode_entry_v2_ffi(&first, dashcore::Network::Testnet),
Expand Down
74 changes: 3 additions & 71 deletions packages/rs-platform-wallet-ffi/src/dpns_marketplace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,73 +770,18 @@ pub unsafe extern "C" fn platform_wallet_dpns_purchase_name(
// On-demand sync
// ---------------------------------------------------------------------------

/// Run one marketplace sync pass on THIS wallet and report its delta.
/// Run one marketplace sync pass on THIS wallet and retain the complete
/// delta and completion timestamp.
///
/// Refreshes owned-name rows (price / sale state), adds newly observed
/// names to the identity label lists, detects names that LEFT an
/// identity (sold or transferred away), and refreshes the balances of
/// identities that sold a name. All four out-params are optional — pass
/// `null` to ignore any of them:
///
/// * `out_names_tracked`: owned-name rows written this pass.
/// * `out_names_added`: labels newly observed on a wallet identity.
/// * `out_names_departed`: names that left a wallet identity.
/// * `out_prices_changed`: listed-price changes since the last pass.
/// identities that sold a name.
///
/// This is the per-wallet, on-demand entry point (pull-to-refresh). The
/// recurring cross-wallet sweep is the manager-level coordinator in
/// [`crate::dpns_sync`].
#[no_mangle]
pub unsafe extern "C" fn platform_wallet_dpns_marketplace_sync(
wallet_handle: Handle,
out_names_tracked: *mut u32,
out_names_added: *mut u32,
out_names_departed: *mut u32,
out_prices_changed: *mut u32,
) -> PlatformWalletFFIResult {
// Optional out-params: define every non-null slot before the fallible
// work so an error return leaves well-defined zeros, not garbage.
unsafe {
for slot in [
out_names_tracked,
out_names_added,
out_names_departed,
out_prices_changed,
] {
if !slot.is_null() {
*slot = 0;
}
}
}

let option = PLATFORM_WALLET_STORAGE.with_item(wallet_handle, |wallet| {
let identity = wallet.identity().clone();
block_on_worker(async move { identity.sync_dpns_marketplace().await })
});
let result = unwrap_option_or_return!(option);
let summary = unwrap_result_or_return!(result);

unsafe {
if !out_names_tracked.is_null() {
*out_names_tracked = summary.names_tracked;
}
if !out_names_added.is_null() {
*out_names_added = summary.names_added.len() as u32;
}
if !out_names_departed.is_null() {
*out_names_departed = summary.names_departed.len() as u32;
}
if !out_prices_changed.is_null() {
*out_prices_changed = summary.prices_changed.len() as u32;
}
}
PlatformWalletFFIResult::ok()
}

/// Run one marketplace sync pass and retain the complete delta and completion
/// timestamp. This is the lossless companion to the original counts-only
/// [`platform_wallet_dpns_marketplace_sync`] entry point.
#[no_mangle]
pub unsafe extern "C" fn platform_wallet_dpns_marketplace_sync_detailed(
wallet_handle: Handle,
out_summary: *mut DpnsMarketplaceSyncSummaryFFI,
Expand Down Expand Up @@ -1383,19 +1328,6 @@ mod tests {
};
assert_eq!(r.code, PlatformWalletFFIResultCode::NotFound);

// All four sync out-params are optional — a null-only call must
// still reach the handle lookup.
let r = unsafe {
platform_wallet_dpns_marketplace_sync(
bogus,
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
ptr::null_mut(),
)
};
assert_eq!(r.code, PlatformWalletFFIResultCode::NotFound);

// Required out-pointer missing: rejected before the handle lookup.
let c = CString::new("alice").unwrap();
let r = unsafe {
Expand Down
2 changes: 1 addition & 1 deletion packages/rs-platform-wallet-ffi/src/dpns_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
//! completion timestamp through out-params; all three are optional —
//! pass null to ignore any of them. For a single wallet's delta (names
//! tracked / added / departed / re-priced) use the per-wallet
//! [`platform_wallet_dpns_marketplace_sync`](crate::dpns_marketplace::platform_wallet_dpns_marketplace_sync)
//! [`platform_wallet_dpns_marketplace_sync_detailed`](crate::dpns_marketplace::platform_wallet_dpns_marketplace_sync_detailed)
//! instead.
//!
//! Not auto-started. The host lifecycle calls
Expand Down
Loading
Loading