v0.5.2-pre.007
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
// file: ks-wallet/src/wallet.rs
|
||||
// version: 11
|
||||
// version: 12
|
||||
|
||||
//! Local wallet storage and signing primitives.
|
||||
|
||||
@@ -158,11 +158,17 @@ impl crate::TemporaryWallet {
|
||||
}
|
||||
|
||||
/// Filesystem-backed store for development and integration-test wallets.
|
||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct TemporaryWalletStore {
|
||||
directory: std::path::PathBuf,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for crate::TemporaryWalletStore {
|
||||
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
return formatter.debug_struct("TemporaryWalletStore").finish();
|
||||
}
|
||||
}
|
||||
|
||||
impl crate::TemporaryWalletStore {
|
||||
/// Creates a wallet store rooted at the supplied directory.
|
||||
pub fn new(directory: impl std::convert::Into<std::path::PathBuf>) -> ks_core::Result<Self> {
|
||||
@@ -193,7 +199,7 @@ impl crate::TemporaryWalletStore {
|
||||
std::result::Result::Ok(exists) => std::result::Result::Ok(exists),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_exists_check_failed",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
)),
|
||||
};
|
||||
}
|
||||
@@ -218,7 +224,6 @@ impl crate::TemporaryWalletStore {
|
||||
action = "create_temporary_wallet",
|
||||
wallet_alias = alias.as_str(),
|
||||
public_key = %keypair.pubkey(),
|
||||
wallet_path = %path.display(),
|
||||
"created persistent temporary wallet"
|
||||
);
|
||||
return std::result::Result::Ok(crate::TemporaryWallet {
|
||||
@@ -240,7 +245,6 @@ impl crate::TemporaryWalletStore {
|
||||
action = "load_temporary_wallet",
|
||||
wallet_alias = alias.as_str(),
|
||||
public_key = %keypair.pubkey(),
|
||||
wallet_path = %path.display(),
|
||||
"loaded persistent temporary wallet"
|
||||
);
|
||||
return std::result::Result::Ok(crate::TemporaryWallet {
|
||||
@@ -279,7 +283,7 @@ async fn prepare_wallet_directory(directory: &std::path::Path) -> ks_core::Resul
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_directory_create_failed",
|
||||
format!("{}: {error}", directory.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
},
|
||||
}
|
||||
@@ -292,7 +296,7 @@ async fn prepare_wallet_directory(directory: &std::path::Path) -> ks_core::Resul
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_directory_permissions_failed",
|
||||
format!("{}: {error}", directory.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
},
|
||||
}
|
||||
@@ -335,10 +339,7 @@ async fn write_new_keypair(
|
||||
} else {
|
||||
"wallet_file_create_failed"
|
||||
};
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
code,
|
||||
format!("{}: {error}", task_path.display()),
|
||||
));
|
||||
return std::result::Result::Err(ks_core::Error::new(code, error.to_string()));
|
||||
},
|
||||
};
|
||||
if let std::result::Result::Err(error) = file.write_all(encoded.as_slice()) {
|
||||
@@ -346,7 +347,7 @@ async fn write_new_keypair(
|
||||
let _ = std::fs::remove_file(&task_path);
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_write_failed",
|
||||
format!("{}: {error}", task_path.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
}
|
||||
encoded.zeroize();
|
||||
@@ -354,7 +355,7 @@ async fn write_new_keypair(
|
||||
let _ = std::fs::remove_file(&task_path);
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_sync_failed",
|
||||
format!("{}: {error}", task_path.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
}
|
||||
return std::result::Result::Ok(());
|
||||
@@ -364,7 +365,7 @@ async fn write_new_keypair(
|
||||
std::result::Result::Ok(result) => result,
|
||||
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_task_failed",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
)),
|
||||
};
|
||||
}
|
||||
@@ -379,7 +380,7 @@ async fn read_keypair(path: &std::path::Path) -> ks_core::Result<solana_keypair:
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_read_failed",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
},
|
||||
};
|
||||
@@ -390,7 +391,7 @@ async fn read_keypair(path: &std::path::Path) -> ks_core::Result<solana_keypair:
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_keypair_json_invalid",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
},
|
||||
};
|
||||
@@ -400,8 +401,7 @@ async fn read_keypair(path: &std::path::Path) -> ks_core::Result<solana_keypair:
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_keypair_length_invalid",
|
||||
format!(
|
||||
"{} contains {length} bytes instead of {}",
|
||||
path.display(),
|
||||
"wallet keypair contains {length} bytes instead of {}",
|
||||
crate::SOLANA_KEYPAIR_LENGTH
|
||||
),
|
||||
));
|
||||
@@ -412,7 +412,7 @@ async fn read_keypair(path: &std::path::Path) -> ks_core::Result<solana_keypair:
|
||||
std::result::Result::Ok(keypair) => std::result::Result::Ok(keypair),
|
||||
std::result::Result::Err(error) => std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_keypair_invalid",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
)),
|
||||
};
|
||||
}
|
||||
@@ -423,14 +423,14 @@ async fn validate_wallet_file_metadata(path: &std::path::Path) -> ks_core::Resul
|
||||
std::result::Result::Err(error) => {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_metadata_failed",
|
||||
format!("{}: {error}", path.display()),
|
||||
error.to_string(),
|
||||
));
|
||||
},
|
||||
};
|
||||
if metadata.file_type().is_symlink() || !metadata.is_file() {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_type_invalid",
|
||||
format!("{} must be a regular file and not a symlink", path.display()),
|
||||
"wallet file must be a regular file and not a symlink",
|
||||
));
|
||||
}
|
||||
#[cfg(unix)]
|
||||
@@ -440,7 +440,7 @@ async fn validate_wallet_file_metadata(path: &std::path::Path) -> ks_core::Resul
|
||||
if mode & 0o077 != 0 {
|
||||
return std::result::Result::Err(ks_core::Error::new(
|
||||
"wallet_file_permissions_too_open",
|
||||
format!("{} has mode {mode:o}; expected no group or other access", path.display()),
|
||||
format!("wallet file has mode {mode:o}; expected no group or other access"),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user