Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 src/backend_task/identity/load_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ impl AppContext {
wallet_index: None, //todo
top_ups: Default::default(),
status: IdentityStatus::Active,
network: self.network,
};
let wallet_info = qualified_identity.determine_wallet_info()?;

Expand Down
1 change: 1 addition & 0 deletions src/backend_task/identity/load_identity_from_wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl AppContext {
wallet_index: Some(identity_index),
top_ups: Default::default(),
status: IdentityStatus::Active,
network: self.network,
};

// Insert qualified identity into the database
Expand Down
1 change: 1 addition & 0 deletions src/backend_task/identity/register_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ impl AppContext {
wallet_index: Some(wallet_identity_index),
top_ups: Default::default(),
status: IdentityStatus::PendingCreation,
network: self.network,
};

if !alias_input.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/backend_task/system_task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl AppContext {
theme_mode: ThemeMode,
) -> Result<BackendTaskSuccessResult, String> {
let _guard = self.invalidate_settings_cache();

self.db
.update_theme_preference(theme_mode)
.map_err(|e| e.to_string())?;
Expand Down
9 changes: 7 additions & 2 deletions src/database/identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ impl Database {
identity.wallet_index = wallet_index;

identity.status = IdentityStatus::from_u8(status);
identity.network = app_context.network;

// Associate wallets
identity.associated_wallets = wallets.clone(); //todo: use less wallets
Expand Down Expand Up @@ -232,6 +233,7 @@ impl Database {
let mut identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
identity.alias = alias;
identity.wallet_index = wallet_index;
identity.network = app_context.network;

// Associate wallets
identity.associated_wallets = wallets.clone(); //todo: use less wallets
Expand Down Expand Up @@ -287,6 +289,7 @@ impl Database {
let mut identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
identity.alias = alias;
identity.wallet_index = wallet_index;
identity.network = app_context.network;

// Associate wallets
identity.associated_wallets = wallets.clone(); //todo: use less wallets
Expand Down Expand Up @@ -326,7 +329,8 @@ impl Database {
)?;
let identity_iter = stmt.query_map(params![network], |row| {
let data: Vec<u8> = row.get(0)?;
let identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
let mut identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
identity.network = app_context.network;

Ok(identity)
})?;
Expand All @@ -353,7 +357,8 @@ impl Database {
stmt.query_map(params![network], |row| {
let data: Vec<u8> = row.get(0)?;
let wallet_id: Option<WalletSeedHash> = row.get(1)?;
let identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
let mut identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&data);
identity.network = app_context.network;

Ok((identity, wallet_id))
})?
Expand Down
1 change: 1 addition & 0 deletions src/database/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ impl Database {
if let Some(wallet) = wallets_map.get_mut(&wallet_seed_hash_array) {
let mut identity: QualifiedIdentity = QualifiedIdentity::from_bytes(&identity_data);
identity.wallet_index = Some(wallet_index);
identity.network = *network;

tracing::trace!(
wallet_seed = ?wallet_seed_hash_array,
Expand Down
3 changes: 3 additions & 0 deletions src/model/qualified_identity/encrypted_key_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use bincode::de::{BorrowDecoder, Decoder};
use bincode::enc::Encoder;
use bincode::error::{DecodeError, EncodeError};
use bincode::{BorrowDecode, Decode, Encode};
use dash_sdk::dashcore_rpc::dashcore::Network;
use dash_sdk::dashcore_rpc::dashcore::bip32::DerivationPath;
use dash_sdk::dpp::dashcore::bip32::ChildNumber;
use dash_sdk::dpp::identity::identity_public_key::accessors::v0::IdentityPublicKeyGettersV0;
Expand Down Expand Up @@ -277,6 +278,7 @@ impl KeyStorage {
&self,
key: &(PrivateKeyTarget, KeyID),
wallets: &[Arc<RwLock<Wallet>>],
network: Network,
) -> Result<Option<(QualifiedIdentityPublicKey, [u8; 32])>, String> {
self.private_keys
.get(key)
Expand All @@ -296,6 +298,7 @@ impl KeyStorage {
wallets,
*wallet_seed_hash,
derivation_path,
network,
)?
.ok_or(format!(
"Wallet for key at derivation path {} not present, we have {} wallets",
Expand Down
21 changes: 3 additions & 18 deletions src/model/qualified_identity/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ pub struct QualifiedIdentity {
pub wallet_index: Option<u32>,
pub top_ups: BTreeMap<u32, u64>,
pub status: IdentityStatus,
pub network: Network,
}

impl AsRef<QualifiedIdentity> for QualifiedIdentity {
Expand Down Expand Up @@ -286,6 +287,7 @@ impl Decode for QualifiedIdentity {
wallet_index: None,
top_ups: Default::default(),
status: IdentityStatus::Unknown, // Loaded from the database, not encoded
network: Network::Dash, // Loaded from the database, not encoded
})
}
}
Expand All @@ -308,6 +310,7 @@ impl Signer for QualifiedIdentity {
.cloned()
.collect::<Vec<_>>()
.as_slice(),
self.network,
)
.map_err(ProtocolError::Generic)?
.ok_or(ProtocolError::Generic(format!(
Expand Down Expand Up @@ -616,21 +619,3 @@ impl QualifiedIdentity {
Ok(wallet_info)
}
}
impl From<Identity> for QualifiedIdentity {
fn from(value: Identity) -> Self {
QualifiedIdentity {
identity: value,
associated_voter_identity: None,
associated_operator_identity: None,
associated_owner_key_id: None,
identity_type: IdentityType::User,
alias: None,
private_keys: Default::default(),
dpns_names: vec![],
associated_wallets: BTreeMap::new(),
wallet_index: None,
top_ups: Default::default(),
status: IdentityStatus::Unknown,
}
}
}
6 changes: 4 additions & 2 deletions src/model/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ impl Wallet {
slice: &[Arc<RwLock<Wallet>>],
wallet_seed_hash: WalletSeedHash,
derivation_path: &DerivationPath,
network: Network,
) -> Result<Option<[u8; 32]>, String> {
for wallet in slice {
// Attempt to read the wallet from the RwLock
Expand All @@ -344,7 +345,7 @@ impl Wallet {
if wallet_ref.seed_hash() == wallet_seed_hash {
// Attempt to derive the private key using the provided derivation path
let extended_private_key = derivation_path
.derive_priv_ecdsa_for_master_seed(wallet_ref.seed_bytes()?, Network::Dash)
.derive_priv_ecdsa_for_master_seed(wallet_ref.seed_bytes()?, network)
.map_err(|e| e.to_string())?;
return Ok(Some(extended_private_key.private_key.secret_bytes()));
}
Expand All @@ -356,9 +357,10 @@ impl Wallet {
pub fn private_key_at_derivation_path(
&self,
derivation_path: &DerivationPath,
network: Network,
) -> Result<PrivateKey, String> {
let extended_private_key = derivation_path
.derive_priv_ecdsa_for_master_seed(self.seed_bytes()?, Network::Dash)
.derive_priv_ecdsa_for_master_seed(self.seed_bytes()?, network)
.map_err(|e| e.to_string())?;
Ok(extended_private_key.to_priv())
}
Expand Down
2 changes: 2 additions & 0 deletions src/ui/identities/keys/key_info_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ impl ScreenLike for KeyInfoScreen {
self.selected_wallet.as_ref().unwrap().read().unwrap();
match wallet.private_key_at_derivation_path(
&derivation_path.derivation_path,
self.app_context.network,
) {
Ok(private_key) => {
let private_key_wif = private_key.to_wif();
Expand Down Expand Up @@ -365,6 +366,7 @@ impl ScreenLike for KeyInfoScreen {
self.selected_wallet.as_ref().unwrap().read().unwrap();
match wallet.private_key_at_derivation_path(
&derivation_path.derivation_path,
self.app_context.network,
) {
Ok(private_key) => {
let private_key_wif = private_key.to_wif();
Expand Down
7 changes: 3 additions & 4 deletions src/ui/tokens/tokens_screen/my_tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,9 @@ impl TokensScreen {
.token_configuration
.conventions()
.plural_form_by_language_code_or_default("en");
let reward_amount = Amount::new(
explanation.total_amount,
decimal_places,
).with_unit_name(unit_name);
let reward_amount =
Amount::new(explanation.total_amount, decimal_places)
.with_unit_name(unit_name);

ui.label(format!("Total Estimated Rewards: {}", reward_amount));
ui.separator();
Expand Down