Skip to content
Merged
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ humantime = "2.2.0"
which = { version = "8.0.0" }
tz-rs = { version = "0.7.0" }
tempfile = "3.20.0"
arc-swap = "1"

[target.'cfg(not(target_os = "windows"))'.dependencies]
zmq = "0.10.0"
Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/identity/discover_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl AppContext {

const AUTH_KEY_LOOKUP_WINDOW: u32 = 12;

let sdk = self.sdk.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.load().as_ref().clone();
let seed_hash = wallet.read().map_err(|e| e.to_string())?.seed_hash();

tracing::info!(
Expand Down
7 changes: 1 addition & 6 deletions src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,7 @@ impl AppContext {
start: None,
};

let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};

let maybe_owned_dpns_names = Document::fetch_many(&sdk_guard, dpns_names_document_query)
let maybe_owned_dpns_names = Document::fetch_many(sdk, dpns_names_document_query)
.await
.map(|document_map| {
document_map
Expand Down
7 changes: 1 addition & 6 deletions src/backend_task/identity/load_identity_from_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,7 @@ impl AppContext {
start: None,
};

let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};

let maybe_owned_dpns_names = Document::fetch_many(&sdk_guard, dpns_names_document_query)
let maybe_owned_dpns_names = Document::fetch_many(sdk, dpns_names_document_query)
.await
.map(|document_map| {
document_map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ impl AppContext {
.load_local_qualified_identities()
.map_err(|e| format!("Error refreshing owned DPNS names: Database error: {}", e))?;

let sdk = self.sdk.load().as_ref().clone();

for mut qualified_identity in qualified_identities {
let identity_id = qualified_identity.identity.id();

Expand All @@ -34,12 +36,7 @@ impl AppContext {
start: None,
};

let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};

let owned_dpns_names = Document::fetch_many(&sdk_guard, dpns_names_document_query)
let owned_dpns_names = Document::fetch_many(&sdk, dpns_names_document_query)
.await
.map(|document_map| {
document_map
Expand Down
9 changes: 2 additions & 7 deletions src/backend_task/identity/register_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,7 @@ impl AppContext {
start: None,
};

let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};

let owned_dpns_names = Document::fetch_many(&sdk_guard, dpns_names_document_query)
let owned_dpns_names = Document::fetch_many(sdk, dpns_names_document_query)
.await
.map(|document_map| {
document_map
Expand Down Expand Up @@ -222,7 +217,7 @@ impl AppContext {
// Calculate actual fee paid
// Note: We need to re-fetch the identity to get the updated balance
let refreshed_identity = dash_sdk::platform::Identity::fetch_by_identifier(
&sdk_guard,
sdk,
qualified_identity.identity.id(),
)
.await
Expand Down
10 changes: 2 additions & 8 deletions src/backend_task/identity/register_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ impl AppContext {
identity_funding_method,
} = input;

let sdk = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

let (_, metadata) = ExtendedEpochInfo::fetch_with_metadata(&sdk, 0, None)
.await
Expand Down Expand Up @@ -646,10 +643,7 @@ impl AppContext {
) -> Result<BackendTaskSuccessResult, String> {
use dash_sdk::platform::transition::put_identity::PutIdentity;

let sdk = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

let public_keys = keys.to_public_keys_map();

Expand Down
5 changes: 1 addition & 4 deletions src/backend_task/identity/top_up_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ impl AppContext {
identity_funding_method,
} = input;

let sdk = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

let (_, metadata) = ExtendedEpochInfo::fetch_with_metadata(&sdk, 0, None)
.await
Expand Down
7 changes: 2 additions & 5 deletions src/backend_task/identity/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ impl AppContext {
credits: Credits,
id: Option<KeyID>,
) -> Result<BackendTaskSuccessResult, String> {
let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

// Track balance before transfer for fee calculation
let balance_before = qualified_identity.identity.balance();
Expand All @@ -31,7 +28,7 @@ impl AppContext {
.identity
.clone()
.transfer_credits(
&sdk_guard,
&sdk,
to_identifier,
credits,
id.and_then(|key_id| qualified_identity.identity.get_public_key_by_id(key_id)),
Expand Down
9 changes: 3 additions & 6 deletions src/backend_task/identity/withdraw_from_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ impl AppContext {
credits: Credits,
id: Option<KeyID>,
) -> Result<BackendTaskSuccessResult, String> {
let sdk_guard = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

// First, refresh the identity from Platform to get the latest revision and balance
tracing::info!(
Expand All @@ -34,7 +31,7 @@ impl AppContext {
);

let refreshed_identity =
Identity::fetch_by_identifier(&sdk_guard, qualified_identity.identity.id())
Identity::fetch_by_identifier(&sdk, qualified_identity.identity.id())
.await
.map_err(|e| format!("Failed to fetch identity from Platform: {}", e))?
.ok_or_else(|| "Identity not found on Platform".to_string())?;
Expand Down Expand Up @@ -89,7 +86,7 @@ impl AppContext {
.identity
.clone()
.withdraw(
&sdk_guard,
&sdk,
to_address,
credits,
Some(1),
Expand Down
7 changes: 2 additions & 5 deletions src/backend_task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,7 @@ impl AppContext {
task: BackendTask,
sender: SenderAsync<TaskResult>,
) -> Result<BackendTaskSuccessResult, String> {
let sdk = {
let guard = self.sdk.read().unwrap();
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();
match task {
BackendTask::ContractTask(contract_task) => {
self.run_contract_task(*contract_task, &sdk, sender).await
Expand Down Expand Up @@ -345,7 +342,7 @@ impl AppContext {
mnlist::run_mnlist_task(self, mnlist_task).await
}
BackendTask::PlatformInfo(platform_info_task) => {
self.run_platform_info_task(platform_info_task).await
self.run_platform_info_task(platform_info_task, &sdk).await
}
BackendTask::GroveSTARKTask(grovestark_task) => {
grovestark::run_grovestark_task(grovestark_task, &sdk).await
Expand Down
23 changes: 10 additions & 13 deletions src/backend_task/platform_info.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::backend_task::BackendTaskSuccessResult;
use crate::context::AppContext;
use dash_sdk::Sdk;
use dash_sdk::dashcore_rpc::RpcApi;
use dash_sdk::dpp::block::extended_epoch_info::{v0::ExtendedEpochInfoV0Getters, ExtendedEpochInfo};
use dash_sdk::dpp::core_types::validator_set::v0::ValidatorSetV0Getters;
Expand Down Expand Up @@ -332,12 +333,8 @@ impl AppContext {
pub async fn run_platform_info_task(
&self,
request: PlatformInfoTaskRequestType,
sdk: &Sdk,
) -> Result<BackendTaskSuccessResult, String> {
let sdk = {
let sdk_guard = self.sdk.read().unwrap();
sdk_guard.clone()
};

match request {
PlatformInfoTaskRequestType::BasicPlatformInfo => {
// Get platform version from SDK
Expand Down Expand Up @@ -365,7 +362,7 @@ impl AppContext {
))
}
PlatformInfoTaskRequestType::CurrentEpochInfo => {
match ExtendedEpochInfo::fetch_current(&sdk).await {
match ExtendedEpochInfo::fetch_current(sdk).await {
Ok(epoch_info) => {
// Cache the fee multiplier for UI fee estimation
let fee_multiplier = epoch_info.fee_multiplier_permille();
Expand All @@ -385,7 +382,7 @@ impl AppContext {
}
}
PlatformInfoTaskRequestType::TotalCreditsOnPlatform => {
match TotalCreditsInPlatform::fetch_current(&sdk).await {
match TotalCreditsInPlatform::fetch_current(sdk).await {
Ok(total_credits) => {
let dash_amount = total_credits.0 as f64 * 10f64.powf(-11.0);
let formatted = format!(
Expand All @@ -402,7 +399,7 @@ impl AppContext {
}
}
PlatformInfoTaskRequestType::CurrentVersionVotingState => {
match ProtocolVersionVoteCount::fetch_many(&sdk, ()).await {
match ProtocolVersionVoteCount::fetch_many(sdk, ()).await {
Ok(votes) => {
let votes: ProtocolVersionUpgrades = votes;
let votes_info = votes
Expand All @@ -428,7 +425,7 @@ impl AppContext {
}
}
PlatformInfoTaskRequestType::CurrentValidatorSetInfo => {
match CurrentQuorumsInfo::fetch_unproved(&sdk, NoParamQuery {}).await {
match CurrentQuorumsInfo::fetch_unproved(sdk, NoParamQuery {}).await {
Ok(Some(current_quorums_info)) => {
let formatted = format_current_quorums_info(&current_quorums_info);
Ok(BackendTaskSuccessResult::PlatformInfo(
Expand Down Expand Up @@ -461,13 +458,13 @@ impl AppContext {
start: None,
};

match Document::fetch_many(&sdk, queued_document_query.clone()).await {
match Document::fetch_many(sdk, queued_document_query.clone()).await {
Ok(documents) => {
let withdrawal_docs: Vec<Document> =
documents.values().filter_map(|a| a.clone()).collect();

// Try to get total credits for daily limit calculation
match TotalCreditsInPlatform::fetch_current(&sdk).await {
match TotalCreditsInPlatform::fetch_current(sdk).await {
Ok(total_credits) => {
let formatted = format_withdrawal_documents_with_daily_limit(
&withdrawal_docs,
Expand Down Expand Up @@ -526,7 +523,7 @@ impl AppContext {
start: None,
};

match Document::fetch_many(&sdk, completed_document_query).await {
match Document::fetch_many(sdk, completed_document_query).await {
Ok(documents) => {
let mut withdrawal_docs: Vec<Document> =
documents.values().filter_map(|a| a.clone()).collect();
Expand Down Expand Up @@ -633,7 +630,7 @@ impl AppContext {
// Fetch the address info using FetchMany with BTreeSet
let mut addresses = std::collections::BTreeSet::new();
addresses.insert(platform_address);
match AddressInfo::fetch_many(&sdk, addresses).await {
match AddressInfo::fetch_many(sdk, addresses).await {
Ok(address_infos) => {
// The result is a map of PlatformAddress -> Option<AddressInfo>
let result: Option<&Option<AddressInfo>> =
Expand Down
5 changes: 1 addition & 4 deletions src/backend_task/wallet/fetch_platform_address_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl AppContext {
};

// Sync using SDK's privacy-preserving method
let sdk = {
let guard = self.sdk.read().map_err(|e| e.to_string())?;
guard.clone()
};
let sdk = self.sdk.load().as_ref().clone();

let (_checkpoint_height, highest_block_processed) = if needs_full_sync {
tracing::info!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl AppContext {
.ok_or_else(|| "Wallet not found".to_string())?
};
let wallet = wallet_arc.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.load().as_ref().clone();

// Get the private key for the asset lock address
let private_key = wallet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl AppContext {
};

let wallet = wallet_arc.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.load().as_ref().clone();
(wallet, sdk, change_platform_address)
};

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/wallet/transfer_platform_credits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl AppContext {
.ok_or_else(|| "Wallet not found".to_string())?
};
let wallet = wallet_arc.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.load().as_ref().clone();
(wallet, sdk)
};

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/wallet/withdraw_from_platform_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl AppContext {
.ok_or_else(|| "Wallet not found".to_string())?
};
let wallet = wallet_arc.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.read().map_err(|e| e.to_string())?.clone();
let sdk = self.sdk.load().as_ref().clone();
(wallet, sdk)
};

Expand Down
3 changes: 2 additions & 1 deletion src/context/connection_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ impl ConnectionStatus {
}

// Update DAPI endpoint status
if let Ok(sdk) = app_context.sdk.read() {
{
let sdk = app_context.sdk.load();
let address_list = sdk.address_list();
let total = address_list.len() as u16;
// get_live_address() returns Option<&Uri>, so count it as 1 if available, 0 if not
Expand Down
Loading
Loading