mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-01-21 03:21:08 +03:00
Remove cloning and various formating/efficiency improvements (#321)
This commit is contained in:
parent
c76ee7c803
commit
047ea9372f
6 changed files with 22 additions and 25 deletions
|
@ -236,10 +236,10 @@ fn comments() -> HashMap<String, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_key(line: &str) -> String {
|
fn get_key(line: &str) -> String {
|
||||||
if line.contains("[") && line.contains("]") {
|
if line.contains('[') && line.contains(']') {
|
||||||
return line.to_owned();
|
return line.to_owned();
|
||||||
} else if line.contains("=") {
|
} else if line.contains('=') {
|
||||||
return line.split("=").collect::<Vec<&str>>()[0].trim().to_owned();
|
return line.split('=').collect::<Vec<&str>>()[0].trim().to_owned();
|
||||||
} else {
|
} else {
|
||||||
return "NOT_FOUND".to_owned();
|
return "NOT_FOUND".to_owned();
|
||||||
}
|
}
|
||||||
|
@ -247,7 +247,7 @@ fn get_key(line: &str) -> String {
|
||||||
|
|
||||||
pub fn insert_comments(orig: String) -> String {
|
pub fn insert_comments(orig: String) -> String {
|
||||||
let comments = comments();
|
let comments = comments();
|
||||||
let lines: Vec<&str> = orig.split("\n").collect();
|
let lines: Vec<&str> = orig.split('\n').collect();
|
||||||
let mut out_lines = vec![];
|
let mut out_lines = vec![];
|
||||||
for l in lines {
|
for l in lines {
|
||||||
let key = get_key(l);
|
let key = get_key(l);
|
||||||
|
@ -261,5 +261,5 @@ pub fn insert_comments(orig: String) -> String {
|
||||||
for l in out_lines {
|
for l in out_lines {
|
||||||
ret_val.push_str(&l);
|
ret_val.push_str(&l);
|
||||||
}
|
}
|
||||||
ret_val.to_owned()
|
ret_val
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,15 +32,15 @@ use crate::types::{TorConfig, WalletConfig};
|
||||||
use crate::util::logger::LoggingConfig;
|
use crate::util::logger::LoggingConfig;
|
||||||
|
|
||||||
/// Wallet configuration file name
|
/// Wallet configuration file name
|
||||||
pub const WALLET_CONFIG_FILE_NAME: &'static str = "grin-wallet.toml";
|
pub const WALLET_CONFIG_FILE_NAME: &str = "grin-wallet.toml";
|
||||||
const WALLET_LOG_FILE_NAME: &'static str = "grin-wallet.log";
|
const WALLET_LOG_FILE_NAME: &str = "grin-wallet.log";
|
||||||
const GRIN_HOME: &'static str = ".grin";
|
const GRIN_HOME: &str = ".grin";
|
||||||
/// Wallet data directory
|
/// Wallet data directory
|
||||||
pub const GRIN_WALLET_DIR: &'static str = "wallet_data";
|
pub const GRIN_WALLET_DIR: &str = "wallet_data";
|
||||||
/// Node API secret
|
/// Node API secret
|
||||||
pub const API_SECRET_FILE_NAME: &'static str = ".api_secret";
|
pub const API_SECRET_FILE_NAME: &str = ".api_secret";
|
||||||
/// Owner API secret
|
/// Owner API secret
|
||||||
pub const OWNER_API_SECRET_FILE_NAME: &'static str = ".owner_api_secret";
|
pub const OWNER_API_SECRET_FILE_NAME: &str = ".owner_api_secret";
|
||||||
|
|
||||||
fn get_grin_path(
|
fn get_grin_path(
|
||||||
chain_type: &global::ChainTypes,
|
chain_type: &global::ChainTypes,
|
||||||
|
@ -123,7 +123,7 @@ fn check_api_secret_file(
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => get_grin_path(chain_type, false)?,
|
None => get_grin_path(chain_type, false)?,
|
||||||
};
|
};
|
||||||
let mut api_secret_path = grin_path.clone();
|
let mut api_secret_path = grin_path;
|
||||||
api_secret_path.push(file_name);
|
api_secret_path.push(file_name);
|
||||||
if !api_secret_path.exists() {
|
if !api_secret_path.exists() {
|
||||||
init_api_secret(&api_secret_path)
|
init_api_secret(&api_secret_path)
|
||||||
|
@ -150,7 +150,7 @@ pub fn initial_setup_wallet(
|
||||||
(path, GlobalWalletConfig::new(p.to_str().unwrap())?)
|
(path, GlobalWalletConfig::new(p.to_str().unwrap())?)
|
||||||
} else {
|
} else {
|
||||||
// Check if grin dir exists
|
// Check if grin dir exists
|
||||||
let grin_path = match data_path.clone() {
|
let grin_path = match data_path {
|
||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => get_grin_path(chain_type, create_path)?,
|
None => get_grin_path(chain_type, create_path)?,
|
||||||
};
|
};
|
||||||
|
@ -265,7 +265,7 @@ impl GlobalWalletConfig {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.clone(),
|
.clone(),
|
||||||
),
|
),
|
||||||
String::from(format!("{}", e)),
|
format!("{}", e),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -311,10 +311,7 @@ impl GlobalWalletConfig {
|
||||||
match encoded {
|
match encoded {
|
||||||
Ok(enc) => return Ok(enc),
|
Ok(enc) => return Ok(enc),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
return Err(ConfigError::SerializationError(String::from(format!(
|
return Err(ConfigError::SerializationError(format!("{}", e)));
|
||||||
"{}",
|
|
||||||
e
|
|
||||||
))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl WalletConfig {
|
||||||
/// Use value from config file, defaulting to sensible value if missing.
|
/// Use value from config file, defaulting to sensible value if missing.
|
||||||
pub fn owner_api_listen_port(&self) -> u16 {
|
pub fn owner_api_listen_port(&self) -> u16 {
|
||||||
self.owner_api_listen_port
|
self.owner_api_listen_port
|
||||||
.unwrap_or(WalletConfig::default_owner_api_listen_port())
|
.unwrap_or_else(WalletConfig::default_owner_api_listen_port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Owner API listen address
|
/// Owner API listen address
|
||||||
|
@ -166,7 +166,7 @@ impl From<io::Error> for ConfigError {
|
||||||
fn from(error: io::Error) -> ConfigError {
|
fn from(error: io::Error) -> ConfigError {
|
||||||
ConfigError::FileIOError(
|
ConfigError::FileIOError(
|
||||||
String::from(""),
|
String::from(""),
|
||||||
String::from(format!("Error loading config file: {}", error)),
|
format!("Error loading config file: {}", error),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -451,7 +451,7 @@ pub fn tx_messages(tx: &TxLogEntry, dark_background_color_scheme: bool) -> Resul
|
||||||
|
|
||||||
let msgs = match tx.messages.clone() {
|
let msgs = match tx.messages.clone() {
|
||||||
None => {
|
None => {
|
||||||
writeln!(t, "{}", "None").unwrap();
|
writeln!(t, "None").unwrap();
|
||||||
t.reset().unwrap();
|
t.reset().unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -459,7 +459,7 @@ pub fn tx_messages(tx: &TxLogEntry, dark_background_color_scheme: bool) -> Resul
|
||||||
};
|
};
|
||||||
|
|
||||||
if msgs.messages.is_empty() {
|
if msgs.messages.is_empty() {
|
||||||
writeln!(t, "{}", "None").unwrap();
|
writeln!(t, "None").unwrap();
|
||||||
t.reset().unwrap();
|
t.reset().unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -529,7 +529,7 @@ pub fn payment_proof(tx: &TxLogEntry) -> Result<(), Error> {
|
||||||
|
|
||||||
let pp = match &tx.payment_proof {
|
let pp = match &tx.payment_proof {
|
||||||
None => {
|
None => {
|
||||||
writeln!(t, "{}", "None").unwrap();
|
writeln!(t, "None").unwrap();
|
||||||
t.reset().unwrap();
|
t.reset().unwrap();
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,7 +129,7 @@ impl ParticipantMessageData {
|
||||||
|
|
||||||
impl fmt::Display for ParticipantMessageData {
|
impl fmt::Display for ParticipantMessageData {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
writeln!(f, "")?;
|
writeln!(f)?;
|
||||||
write!(f, "Participant ID {} ", self.id)?;
|
write!(f, "Participant ID {} ", self.id)?;
|
||||||
if self.id == 0 {
|
if self.id == 0 {
|
||||||
writeln!(f, "(Sender)")?;
|
writeln!(f, "(Sender)")?;
|
||||||
|
|
|
@ -57,7 +57,7 @@ impl OnionV3Address {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let d_pub_key: DalekPublicKey = (&d_skey).into();
|
let d_pub_key: DalekPublicKey = (&d_skey).into();
|
||||||
Ok(OnionV3Address(d_pub_key.as_bytes().clone()))
|
Ok(OnionV3Address(*d_pub_key.as_bytes()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// return dalek public key
|
/// return dalek public key
|
||||||
|
|
Loading…
Reference in a new issue