Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet): fix wallet_setting keys #4976

Merged
merged 3 commits into from
Nov 30, 2022
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Your SQL goes here
UPDATE wallet_settings SET key = 'NodeFeatures' WHERE key = 'Nod features';
UPDATE wallet_settings SET key = 'ClientKey.recovery_data' WHERE key = 'ClientKey: "recovery_data"';
UPDATE wallet_settings SET key = 'ClientKey.console_wallet_custom_base_node_public_key' WHERE key = 'ClientKey: "console_wallet_custom_base_node_public_key"';
UPDATE wallet_settings SET key = 'ClientKey.console_wallet_custom_base_node_address' WHERE key = 'ClientKey: "console_wallet_custom_base_node_address"';
UPDATE wallet_settings SET key = 'BaseNodeChainMetadata' WHERE key = 'Last seen Chain metadata from basw node';
2 changes: 1 addition & 1 deletion base_layer/wallet/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub enum WalletStorageError {
DieselConnectionError(#[from] diesel::ConnectionError),
#[error("Database migration error")]
DatabaseMigrationError(String),
#[error("Value not found: `{0}`")]
#[error("Value not found: `{}`", .0.to_key_string())]
ValueNotFound(DbKey),
#[error("Unexpected result: `{0}`")]
UnexpectedResult(String),
Expand Down
42 changes: 23 additions & 19 deletions base_layer/wallet/src/storage/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ pub enum DbKey {
WalletBirthday,
}

impl DbKey {
pub fn to_key_string(&self) -> String {
match self {
DbKey::MasterSeed => "MasterSeed".to_string(),
DbKey::CommsAddress => "CommsAddress".to_string(),
DbKey::CommsFeatures => "NodeFeatures".to_string(),
DbKey::TorId => "TorId".to_string(),
DbKey::ClientKey(k) => format!("ClientKey.{}", k),
DbKey::BaseNodeChainMetadata => "BaseNodeChainMetadata".to_string(),
DbKey::PassphraseHash => "PassphraseHash".to_string(),
DbKey::EncryptionSalt => "EncryptionSalt".to_string(),
DbKey::WalletBirthday => "WalletBirthday".to_string(),
DbKey::CommsIdentitySignature => "CommsIdentitySignature".to_string(),
}
}
}

pub enum DbValue {
CommsAddress(Multiaddr),
CommsFeatures(PeerFeatures),
Expand Down Expand Up @@ -320,23 +337,6 @@ where T: WalletBackend + 'static
}
}

impl Display for DbKey {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self {
DbKey::MasterSeed => f.write_str("MasterSeed"),
DbKey::CommsAddress => f.write_str("CommsAddress"),
DbKey::CommsFeatures => f.write_str("Nod features"),
DbKey::TorId => f.write_str("TorId"),
DbKey::ClientKey(k) => f.write_str(&format!("ClientKey: {:?}", k)),
DbKey::BaseNodeChainMetadata => f.write_str("Last seen Chain metadata from basw node"),
DbKey::PassphraseHash => f.write_str("PassphraseHash"),
DbKey::EncryptionSalt => f.write_str("EncryptionSalt"),
DbKey::WalletBirthday => f.write_str("WalletBirthday"),
DbKey::CommsIdentitySignature => f.write_str("CommsIdentitySignature"),
}
}
}

impl Display for DbValue {
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
match self {
Expand All @@ -359,14 +359,18 @@ fn log_error<T>(req: DbKey, err: WalletStorageError) -> Result<T, WalletStorageE
error!(
target: LOG_TARGET,
"Database access error on request: {}: {}",
req,
req.to_key_string(),
err.to_string()
);
Err(err)
}

fn unexpected_result<T>(req: DbKey, res: DbValue) -> Result<T, WalletStorageError> {
let msg = format!("Unexpected result for database query {}. Response: {}", req, res);
let msg = format!(
"Unexpected result for database query {}. Response: {}",
req.to_key_string(),
res
);
error!(target: LOG_TARGET, "{}", msg);
Err(WalletStorageError::UnexpectedResult(msg))
}
Expand Down
Loading