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
5 changes: 1 addition & 4 deletions src/backend_task/contested_names/vote_on_dpns_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ impl AppContext {
vote_results.push((name.to_owned(), vote_choice, result));
} else {
return Err(TaskError::NoVotingIdentity {
identity_id: qualified_identity
.identity
.id()
.to_string(Encoding::Base58),
identity_id: qualified_identity.identity.id().to_string(Encoding::Base58),
});
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/backend_task/dashpay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ impl AppContext {
let identity_id = identity.identity.id();
let records = payments::load_payment_history(self, &identity_id, None)
.await
.map_err(|e| crate::backend_task::dashpay::errors::DashPayError::Internal { message: e })?;
.map_err(
|e| crate::backend_task::dashpay::errors::DashPayError::Internal {
message: e,
},
)?;

let network_str = self.network.to_string();
let contacts = self
Expand Down Expand Up @@ -254,7 +258,11 @@ impl AppContext {
let result =
incoming_payments::register_dashpay_addresses_for_identity(self, &identity)
.await
.map_err(|e| crate::backend_task::dashpay::errors::DashPayError::Internal { message: e })?;
.map_err(|e| {
crate::backend_task::dashpay::errors::DashPayError::Internal {
message: e,
}
})?;

Ok(BackendTaskSuccessResult::Message(format!(
"Registered {} DashPay addresses for {} contacts{}",
Expand Down
43 changes: 27 additions & 16 deletions src/backend_task/dashpay/contact_requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,12 +281,16 @@ pub async fn send_contact_request_with_proof(
&wallets,
identity.network,
)
.map_err(|e| TaskError::EncryptionError { detail: format!("Error resolving ENCRYPTION private key: {}", e) })?
.map_err(|e| TaskError::EncryptionError {
detail: format!("Error resolving ENCRYPTION private key: {}", e),
})?
.map(|(_, private_key)| private_key)
.ok_or_else(|| TaskError::DashPay(DashPayError::PrivateKeyResolution {
key_purpose: "ENCRYPTION".to_string(),
reason: "Private key not loaded into Dash Evo Tool".to_string(),
}))?;
.ok_or_else(|| {
TaskError::DashPay(DashPayError::PrivateKeyResolution {
key_purpose: "ENCRYPTION".to_string(),
reason: "Private key not loaded into Dash Evo Tool".to_string(),
})
})?;

let shared_key = generate_ecdh_shared_key(&sender_private_key, recipient_key)
.map_err(|e| TaskError::EncryptionError { detail: e })?;
Expand Down Expand Up @@ -367,7 +371,9 @@ pub async fn send_contact_request_with_proof(
current_height_for_validation,
)
.await
.map_err(|e| DashPayError::ValidationFailed { errors: vec![e.to_string()] })?;
.map_err(|e| DashPayError::ValidationFailed {
errors: vec![e.to_string()],
})?;

// Check if validation passed
if !validation.is_valid {
Expand Down Expand Up @@ -513,10 +519,11 @@ pub async fn send_contact_request_with_proof(

async fn resolve_username_to_identity(sdk: &Sdk, username: &str) -> Result<Identity, TaskError> {
// Parse username (e.g., "alice.dash" -> "alice")
let name = username
.split('.')
.next()
.ok_or_else(|| TaskError::DashPay(DashPayError::InvalidUsername { username: username.to_string() }))?;
let name = username.split('.').next().ok_or_else(|| {
TaskError::DashPay(DashPayError::InvalidUsername {
username: username.to_string(),
})
})?;

// Query DPNS for the username
let dpns_contract_id = Identifier::from_string(
Expand Down Expand Up @@ -547,13 +554,17 @@ async fn resolve_username_to_identity(sdk: &Sdk, username: &str) -> Result<Ident

let results = Document::fetch_many(sdk, query).await?;

let (_, document) = results
.into_iter()
.next()
.ok_or_else(|| TaskError::DashPay(DashPayError::UsernameResolutionFailed { username: username.to_string() }))?;
let (_, document) = results.into_iter().next().ok_or_else(|| {
TaskError::DashPay(DashPayError::UsernameResolutionFailed {
username: username.to_string(),
})
})?;

let document = document
.ok_or_else(|| TaskError::DashPay(DashPayError::InvalidDocument { reason: format!("Invalid DPNS document for '{}'", username) }))?;
let document = document.ok_or_else(|| {
TaskError::DashPay(DashPayError::InvalidDocument {
reason: format!("Invalid DPNS document for '{}'", username),
})
})?;

// Get the identity ID from the DPNS document
let identity_id = document.owner_id();
Expand Down
4 changes: 1 addition & 3 deletions src/backend_task/dashpay/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,7 @@ pub enum DashPayError {
MissingAuthenticationKey,

/// A contact request has already been sent to this recipient.
#[error(
"You have already sent a contact request to '{to}'. Please wait for them to respond."
)]
#[error("You have already sent a contact request to '{to}'. Please wait for them to respond.")]
ContactRequestAlreadySent { to: String },
}

Expand Down
7 changes: 3 additions & 4 deletions src/backend_task/dashpay/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,11 @@ pub async fn search_profiles(
let normalized_query = query_trimmed.to_lowercase();

// Search DPNS for usernames starting with the query
let mut dpns_query = DocumentQuery::new(dpns_contract, "domain").map_err(|e| {
DashPayError::QueryCreation {
let mut dpns_query =
DocumentQuery::new(dpns_contract, "domain").map_err(|e| DashPayError::QueryCreation {
query_target: "DPNS domain",
source: Box::new(e),
}
})?;
})?;

dpns_query = dpns_query
.with_where(WhereClause {
Expand Down
34 changes: 11 additions & 23 deletions src/backend_task/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use dash_sdk::Error as SdkError;
use dash_sdk::dashcore_rpc;
use dash_sdk::dpp::ProtocolError;
use dash_sdk::dpp::dashcore;
use dash_sdk::dpp::consensus::ConsensusError;
use dash_sdk::dpp::consensus::basic::basic_error::BasicError;
use dash_sdk::dpp::consensus::state::state_error::StateError;
use dash_sdk::dpp::dashcore;
use dash_sdk::dpp::platform_value::string_encoding::Encoding;
use thiserror::Error;

Expand Down Expand Up @@ -399,21 +399,15 @@ pub enum TaskError {
SdkInitializationFailed { detail: String },

/// An RPC context provider or Core RPC client could not be constructed.
#[error(
"Could not set up the Dash Core connection. Please check your settings and retry."
)]
#[error("Could not set up the Dash Core connection. Please check your settings and retry.")]
RpcProviderCreationFailed { detail: String },

/// The Core wallet name supplied by the user is syntactically invalid.
#[error(
"The Core wallet name '{name}' is invalid. Please check your wallet configuration."
)]
#[error("The Core wallet name '{name}' is invalid. Please check your wallet configuration.")]
InvalidCoreWalletName { name: String },

/// Dash Core has no wallets loaded — required for wallet-scoped RPC calls.
#[error(
"No wallets are loaded in Dash Core. Please open a wallet in Dash Core and retry."
)]
#[error("No wallets are loaded in Dash Core. Please open a wallet in Dash Core and retry.")]
NoCoreWalletsLoaded,

// ──────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -482,9 +476,7 @@ pub enum TaskError {
},

/// The wallet has no UTXOs available to cover the payment.
#[error(
"Your wallet has no available funds to spend. Please receive some Dash first."
)]
#[error("Your wallet has no available funds to spend. Please receive some Dash first.")]
NoUtxosAvailable,

/// The wallet balance is too low to cover the requested amount plus fees.
Expand Down Expand Up @@ -560,28 +552,24 @@ pub enum TaskError {
NoMatchingWalletKeys,

/// The derivation path for the queried identity key was not found in the wallet.
#[error("Could not locate this identity key's information in your wallet. Please check your wallet configuration.")]
#[error(
"Could not locate this identity key's information in your wallet. Please check your wallet configuration."
)]
WalletKeyDerivationPathNotFound,

/// Wallet scan completed but no identities were found up to the requested index.
#[error(
"No identities found up to wallet index {max_index}. Try a higher search range."
)]
#[error("No identities found up to wallet index {max_index}. Try a higher search range.")]
NoWalletIdentitiesFound { max_index: u32 },

// ──────────────────────────────────────────────────────────────────────────
// Key input validation errors
// ──────────────────────────────────────────────────────────────────────────
/// A raw private-key input string failed format validation.
#[error(
"The {key_name} key is invalid: {detail}. Please check the key format and retry."
)]
#[error("The {key_name} key is invalid: {detail}. Please check the key format and retry.")]
KeyInputValidationFailed { key_name: String, detail: String },

/// The identity's public keys could not be converted to the platform format.
#[error(
"Could not process the identity keys. Please check your key configuration and retry."
)]
#[error("Could not process the identity keys. Please check your key configuration and retry.")]
PublicKeyMapBuildFailed { detail: String },

/// The wallet-binding information for an identity could not be determined.
Expand Down
10 changes: 4 additions & 6 deletions src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ impl AppContext {
})?;

// Verify the voting private key
let voting_private_key_bytes =
verify_key_input(voting_private_key_input, "Voting").map_err(|e| {
TaskError::KeyInputValidationFailed {
key_name: "Voting".to_string(),
detail: e,
}
let voting_private_key_bytes = verify_key_input(voting_private_key_input, "Voting")
.map_err(|e| TaskError::KeyInputValidationFailed {
key_name: "Voting".to_string(),
detail: e,
})?;

let payout_address_private_key_bytes =
Expand Down
4 changes: 3 additions & 1 deletion src/backend_task/identity/load_identity_from_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ impl AppContext {
}

if loaded_indices.is_empty() {
return Err(TaskError::NoWalletIdentitiesFound { max_index: max_identity_index });
return Err(TaskError::NoWalletIdentitiesFound {
max_index: max_identity_index,
});
}

let summary = if loaded_indices.len() == 1 {
Expand Down
21 changes: 16 additions & 5 deletions src/backend_task/identity/register_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,13 @@ impl AppContext {
Err(e) => {
// Reload UTXOs (RPC: fetches from Core; SPV: no-op).
// Only retry if something actually changed.
if !wallet.reload_utxos(self).map_err(|e| TaskError::UtxoUpdateFailed { detail: e })? {
return Err(TaskError::AssetLockTransactionBuildFailed { detail: e });
if !wallet
.reload_utxos(self)
.map_err(|e| TaskError::UtxoUpdateFailed { detail: e })?
{
return Err(TaskError::AssetLockTransactionBuildFailed {
detail: e,
});
}
wallet
.registration_asset_lock_transaction(
Expand All @@ -115,7 +120,9 @@ impl AppContext {
true,
identity_index,
)
.map_err(|e| TaskError::AssetLockTransactionBuildFailed { detail: e })?
.map_err(|e| TaskError::AssetLockTransactionBuildFailed {
detail: e,
})?
}
}
};
Expand Down Expand Up @@ -222,7 +229,9 @@ impl AppContext {
.create_identifier()
.map_err(|e| TaskError::from(dash_sdk::Error::Protocol(e)))?;

let public_keys = keys.to_public_keys_map().map_err(|e| TaskError::PublicKeyMapBuildFailed { detail: e })?;
let public_keys = keys
.to_public_keys_map()
.map_err(|e| TaskError::PublicKeyMapBuildFailed { detail: e })?;

// Debug: Log the keys being registered to verify contract bounds are set
for (key_id, key) in &public_keys {
Expand Down Expand Up @@ -523,7 +532,9 @@ impl AppContext {

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

let public_keys = keys.to_public_keys_map().map_err(|e| TaskError::PublicKeyMapBuildFailed { detail: e })?;
let public_keys = keys
.to_public_keys_map()
.map_err(|e| TaskError::PublicKeyMapBuildFailed { detail: e })?;

// Calculate fee estimate for identity creation from platform addresses
let key_count = public_keys.len();
Expand Down
17 changes: 13 additions & 4 deletions src/backend_task/identity/top_up_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,13 @@ impl AppContext {
Err(e) => {
// Reload UTXOs (RPC: fetches from Core; SPV: no-op).
// Only retry if something actually changed.
if !wallet.reload_utxos(self).map_err(|e| TaskError::UtxoUpdateFailed { detail: e })? {
return Err(TaskError::AssetLockTransactionBuildFailed { detail: e });
if !wallet
.reload_utxos(self)
.map_err(|e| TaskError::UtxoUpdateFailed { detail: e })?
{
return Err(TaskError::AssetLockTransactionBuildFailed {
detail: e,
});
}
wallet
.top_up_asset_lock_transaction(
Expand All @@ -125,7 +130,9 @@ impl AppContext {
identity_index,
top_up_index,
)
.map_err(|e| TaskError::AssetLockTransactionBuildFailed { detail: e })?
.map_err(|e| TaskError::AssetLockTransactionBuildFailed {
detail: e,
})?
}
};
(
Expand Down Expand Up @@ -177,7 +184,9 @@ impl AppContext {
identity_index,
top_up_index,
)
.map_err(|e| TaskError::AssetLockTransactionBuildFailed { detail: e })?;
.map_err(|e| TaskError::AssetLockTransactionBuildFailed {
detail: e,
})?;
(tx_result.0, tx_result.1, seed_hash)
};

Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/tokens/query_my_token_balances.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Query token balances from Platform

use crate::backend_task::error::TaskError;
use crate::backend_task::BackendTaskSuccessResult;
use crate::backend_task::error::TaskError;
use crate::context::AppContext;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::platform::tokens::identity_token_balances::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ impl AppContext {
// Get the private key for the asset lock address
let private_key = wallet
.private_key_for_address(&asset_lock_address, self.network)
.map_err(|e| crate::backend_task::error::TaskError::WalletKeyLookupFailed { detail: e })?
.map_err(
|e| crate::backend_task::error::TaskError::WalletKeyLookupFailed { detail: e },
)?
.ok_or(crate::backend_task::error::TaskError::AssetLockAddressNotFound)?;

(wallet, sdk, private_key)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ impl AppContext {
Err(e) => {
// Reload UTXOs (RPC: fetches from Core; SPV: no-op).
// Only retry if something actually changed.
if !wallet.reload_utxos(self).map_err(|e| TaskError::UtxoUpdateFailed { detail: e })? {
if !wallet
.reload_utxos(self)
.map_err(|e| TaskError::UtxoUpdateFailed { detail: e })?
{
return Err(TaskError::AssetLockTransactionBuildFailed { detail: e });
}
let (tx, private_key, address, _change, utxos) = wallet
Expand Down
12 changes: 10 additions & 2 deletions src/backend_task/wallet/generate_receive_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ impl AppContext {
.spv_manager
.next_bip44_receive_address(seed_hash, 0)
.await
.map_err(|e| crate::backend_task::error::TaskError::WalletAddressDerivationFailed { detail: e })?;
.map_err(|e| {
crate::backend_task::error::TaskError::WalletAddressDerivationFailed {
detail: e,
}
})?;

let _ = self.register_spv_address(
&wallet_arc,
Expand All @@ -37,7 +41,11 @@ impl AppContext {
let mut wallet = wallet_arc.write()?;
wallet
.receive_address(self.network, true, Some(self))
.map_err(|e| crate::backend_task::error::TaskError::WalletAddressDerivationFailed { detail: e })?
.map_err(|e| {
crate::backend_task::error::TaskError::WalletAddressDerivationFailed {
detail: e,
}
})?
.to_string()
};

Expand Down
Loading
Loading