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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ strum = { version = "0.26.1", features = ["derive"] }
bs58 = "0.5.0"
base64 = "0.22.1"
copypasta = "0.10.1"
dash-sdk = { git = "https://github.com/dashpay/platform", rev = "c49af53698bad1070fcfc344ccaf6b3cc404e516" }
dash-sdk = { git = "https://github.com/dashpay/platform", rev = "f78f152403d789cdd091f3e88165671e975a6d63" }
thiserror = "1"
serde = "1.0.197"
serde_json = "1.0.120"
Expand Down
5 changes: 4 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ impl App for AppState {
BackendTaskSuccessResult::RegisteredIdentity(_) => {
self.visible_screen_mut().display_task_result(message);
}
BackendTaskSuccessResult::ToppedUpIdentity(_) => {
self.visible_screen_mut().display_task_result(message);
}
},
TaskResult::Error(message) => {
self.visible_screen_mut()
Expand Down Expand Up @@ -457,7 +460,7 @@ impl App for AppState {
let core_item =
CoreItem::ReceivedAvailableUTXOTransaction(tx.clone(), utxos);
self.visible_screen_mut()
.display_task_result(core_item.into());
.display_task_result(BackendTaskSuccessResult::CoreItem(core_item));
}
Err(e) => {
eprintln!("Failed to store asset lock: {}", e);
Expand Down
2 changes: 0 additions & 2 deletions src/backend_task/core/start_dash_qt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use crate::context::AppContext;
use dash_sdk::dpp::dashcore::Network;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::sync::Arc;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use std::{env, io};

impl AppContext {
Expand Down
7 changes: 4 additions & 3 deletions src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,21 @@ use crate::model::qualified_identity::PrivateKeyTarget::{
self, PrivateKeyOnMainIdentity, PrivateKeyOnVoterIdentity,
};
use crate::model::qualified_identity::{DPNSNameInfo, IdentityType, QualifiedIdentity};
use crate::model::wallet::WalletSeedHash;
use dash_sdk::dashcore_rpc::dashcore::key::Secp256k1;
use dash_sdk::dashcore_rpc::dashcore::PrivateKey;
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::document::DocumentV0Getters;
use dash_sdk::dpp::identifier::MasternodeIdentifiers;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
use dash_sdk::dpp::identity::{KeyType, SecurityLevel};
use dash_sdk::dpp::identity::SecurityLevel;
use dash_sdk::dpp::platform_value::string_encoding::Encoding;
use dash_sdk::dpp::platform_value::Value;
use dash_sdk::drive::query::{WhereClause, WhereOperator};
use dash_sdk::platform::{Document, DocumentQuery, Fetch, FetchMany, Identifier, Identity};
use dash_sdk::Sdk;
use egui::ahash::HashMap;
use std::collections::{BTreeMap, HashSet};
use std::collections::BTreeMap;

impl AppContext {
pub(super) async fn load_identity(
Expand Down Expand Up @@ -295,6 +294,8 @@ impl AppContext {
.iter()
.map(|wallet| (wallet.read().unwrap().seed_hash(), wallet.clone()))
.collect(),
wallet_index: None, //todo
Comment thread
ogabrielides marked this conversation as resolved.
top_ups: Default::default(),
};

// Insert qualified identity into the database
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 @@ -7,7 +7,7 @@ use crate::model::qualified_identity::qualified_identity_public_key::QualifiedId
use crate::model::qualified_identity::{
DPNSNameInfo, IdentityType, PrivateKeyTarget, QualifiedIdentity,
};
use crate::model::wallet::{Wallet, WalletArcRef};
use crate::model::wallet::WalletArcRef;
use dash_sdk::dpp::dashcore::bip32::{DerivationPath, KeyDerivationType};
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::document::DocumentV0Getters;
Expand Down Expand Up @@ -137,6 +137,8 @@ impl AppContext {
wallet_arc_ref.wallet.read().unwrap().seed_hash(),
wallet_arc_ref.wallet.clone(),
)]),
wallet_index: Some(identity_index),
top_ups: Default::default(),
};

// Insert qualified identity into the database
Expand Down
35 changes: 31 additions & 4 deletions src/backend_task/identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod load_identity_from_wallet;
mod refresh_identity;
mod register_dpns_name;
mod register_identity;
mod top_up_identity;
mod transfer;
mod withdraw_from_identity;

Expand All @@ -19,7 +20,7 @@ use dash_sdk::dashcore_rpc::dashcore::key::Secp256k1;
use dash_sdk::dashcore_rpc::dashcore::{Address, PrivateKey, TxOut};
use dash_sdk::dpp::balances::credits::Duffs;
use dash_sdk::dpp::dashcore::hashes::Hash;
use dash_sdk::dpp::dashcore::{OutPoint, PublicKey, Transaction};
use dash_sdk::dpp::dashcore::{OutPoint, Transaction};
use dash_sdk::dpp::fee::Credits;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
Expand Down Expand Up @@ -191,30 +192,52 @@ impl IdentityKeys {
}

pub type IdentityIndex = u32;
pub type TopUpIndex = u32;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum IdentityRegistrationMethod {
pub enum RegisterIdentityFundingMethod {
UseAssetLock(Address, AssetLockProof, Transaction),
FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex),
FundWithWallet(Duffs, IdentityIndex),
}
Comment on lines +197 to 201
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor Suggestion: Reduce Duplication in Funding Method Enums

The RegisterIdentityFundingMethod and TopUpIdentityFundingMethod enums share similar variants with slight differences. To improve maintainability and reduce code duplication, consider combining them into a single enum or abstracting common functionality.

Here's a possible refactor:

 #[derive(Debug, Clone, PartialEq, Eq)]
-pub enum RegisterIdentityFundingMethod {
+pub enum IdentityFundingMethod {
     UseAssetLock(Address, AssetLockProof, Transaction),
-    FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex),
-    FundWithWallet(Duffs, IdentityIndex),
+    FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, Option<TopUpIndex>),
+    FundWithWallet(Duffs, IdentityIndex, Option<TopUpIndex>),
 }

 #[derive(Debug, Clone, PartialEq, Eq)]
-pub enum TopUpIdentityFundingMethod {
-    UseAssetLock(Address, AssetLockProof, Transaction),
-    FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, TopUpIndex),
-    FundWithWallet(Duffs, IdentityIndex, TopUpIndex),
-}

By adding an optional TopUpIndex parameter, you can use IdentityFundingMethod for both registration and top-up processes.

Committable suggestion skipped: line range outside the PR's diff.


#[derive(Debug, Clone, PartialEq, Eq)]
pub enum TopUpIdentityFundingMethod {
UseAssetLock(Address, AssetLockProof, Transaction),
FundWithUtxo(OutPoint, TxOut, Address, IdentityIndex, TopUpIndex),
FundWithWallet(Duffs, IdentityIndex, TopUpIndex),
}

#[derive(Debug, Clone)]
pub struct IdentityRegistrationInfo {
pub alias_input: String,
pub keys: IdentityKeys,
pub wallet: Arc<RwLock<Wallet>>,
pub wallet_identity_index: u32,
pub identity_registration_method: IdentityRegistrationMethod,
pub identity_funding_method: RegisterIdentityFundingMethod,
}

impl PartialEq for IdentityRegistrationInfo {
fn eq(&self, other: &Self) -> bool {
self.alias_input == other.alias_input
&& self.identity_registration_method == other.identity_registration_method
&& self.identity_funding_method == other.identity_funding_method
&& self.keys == other.keys
}
}

#[derive(Debug, Clone)]
pub struct IdentityTopUpInfo {
pub qualified_identity: QualifiedIdentity,
pub wallet: Arc<RwLock<Wallet>>,
pub identity_funding_method: TopUpIdentityFundingMethod,
}

impl PartialEq for IdentityTopUpInfo {
fn eq(&self, other: &Self) -> bool {
self.qualified_identity == other.qualified_identity
&& self.identity_funding_method == other.identity_funding_method
}
}

#[derive(Debug, Clone, PartialEq)]
pub struct RegisterDpnsNameInput {
pub qualified_identity: QualifiedIdentity,
Expand All @@ -226,6 +249,7 @@ pub(crate) enum IdentityTask {
LoadIdentity(IdentityInputToLoad),
SearchIdentityFromWallet(WalletArcRef, IdentityIndex),
RegisterIdentity(IdentityRegistrationInfo),
TopUpIdentity(IdentityTopUpInfo),
AddKeyToIdentity(QualifiedIdentity, QualifiedIdentityPublicKey, [u8; 32]),
WithdrawFromIdentity(QualifiedIdentity, Option<Address>, Credits, Option<KeyID>),
Transfer(QualifiedIdentity, Identifier, Credits, Option<KeyID>),
Expand Down Expand Up @@ -440,6 +464,9 @@ impl AppContext {
self.load_user_identity_from_wallet(sdk, wallet, identity_index)
.await
}
IdentityTask::TopUpIdentity(top_up_info) => {
self.top_up_identity(top_up_info, sender).await
}
}
}
}
Loading