Skip to content

Commit 168b926

Browse files
actually setup xpubs from file
1 parent 7efc764 commit 168b926

5 files changed

Lines changed: 30 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
Cargo.lock
33
# ignores perf data and generated performance graphs
44
perf.*
5-
*.svg
5+
*.svg
6+
config.toml

src/cli.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::path::PathBuf;
2-
31
use clap::{arg, command, Parser, Subcommand, ValueEnum};
2+
43
#[derive(Clone, Debug, ValueEnum)]
54
pub enum Network {
65
Bitcoin,
@@ -28,7 +27,7 @@ impl std::fmt::Display for Network {
2827
pub struct Cli {
2928
/// Sets a custom config file
3029
#[arg(short, long, value_name = "FILE")]
31-
pub config_file: Option<PathBuf>,
30+
pub config_file: Option<String>,
3231
/// Which network should we use
3332
#[arg(short, long, default_value_t=Network::Bitcoin)]
3433
pub network: Network,

src/config_file.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ pub struct ConfigFile {
2424
pub wallet: Wallet,
2525
pub misc: Misc,
2626
}
27+
impl ConfigFile {
28+
pub fn from_file(filename: &str) -> Result<Self, crate::error::Error> {
29+
let file = std::fs::read_to_string(filename)?;
30+
Ok(toml::from_str(file.as_str())?)
31+
}
32+
}

src/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ pub enum Error {
1414
ValidationError(bitcoin::blockdata::script::Error),
1515
ChainError(BlockchainError),
1616
SerdeJsonError(serde_json::Error),
17+
TomlParsingError(toml::de::Error),
1718
WalletInputError(crate::wallet_input::ParsingError),
1819
}
1920

@@ -32,6 +33,7 @@ impl std::fmt::Display for Error {
3233
Error::ChainError(err) => write!(f, "Error with our blockchain backend: {:?}", err),
3334
Error::SerdeJsonError(err) => write!(f, "Error serializing object {err}"),
3435
Error::WalletInputError(err) => write!(f, "Error while parsing user input {:?}", err),
36+
Error::TomlParsingError(err) => write!(f, "Error deserializing toml file {err}"),
3537
}
3638
}
3739
}
@@ -47,6 +49,7 @@ impl_from_error!(ValidationError, bitcoin::blockdata::script::Error);
4749
impl_from_error!(ChainError, BlockchainError);
4850
impl_from_error!(SerdeJsonError, serde_json::Error);
4951
impl_from_error!(WalletInputError, crate::wallet_input::ParsingError);
52+
impl_from_error!(TomlParsingError, toml::de::Error);
5053

5154
impl std::error::Error for Error {}
5255
#[macro_export]

src/main.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn main() {
6868
.init();
6969

7070
let params = Cli::parse();
71-
let data = ConfigFile::default();
71+
let data = ConfigFile::from_file(&params.config_file.unwrap()).expect("Invalid config file");
7272
match params.command {
7373
Commands::Run {
7474
data_dir,
@@ -82,16 +82,17 @@ fn main() {
8282
} => {
8383
let data_dir = get_one_or_another(
8484
data_dir,
85-
dirs::home_dir().map(|x: PathBuf| x.to_str().unwrap_or_default().to_owned()),
85+
dirs::home_dir().map(|x: PathBuf| {
86+
x.to_str().unwrap_or_default().to_owned() + "/.utreexo_wallet/"
87+
}),
8688
"wallet".into(),
8789
);
8890
debug!("Loading wallet");
8991
let mut wallet = load_wallet(&data_dir);
9092
wallet.setup().expect("Could not initialize wallet");
9193
debug!("Done loading wallet");
92-
9394
let result = setup_wallet(
94-
get_one_or_another(wallet_xpub, data.wallet.xpubs, vec![]),
95+
get_both_vec(wallet_xpub, data.wallet.xpubs),
9596
&mut wallet,
9697
params.network.clone(),
9798
);
@@ -198,6 +199,7 @@ fn setup_wallet<D: AddressCacheDatabase>(
198199
wallet: &mut AddressCache<D>,
199200
network: cli::Network,
200201
) -> Result<(), crate::error::Error> {
202+
println!("{:?}", xpubs);
201203
if xpubs.is_empty() {
202204
return Ok(());
203205
}
@@ -265,3 +267,14 @@ where
265267

266268
default
267269
}
270+
271+
fn get_both_vec<T>(a: Option<Vec<T>>, b: Option<Vec<T>>) -> Vec<T> {
272+
let mut result: Vec<T> = vec![];
273+
if let Some(a) = a {
274+
result.extend(a.into_iter());
275+
}
276+
if let Some(b) = b {
277+
result.extend(b.into_iter());
278+
}
279+
result
280+
}

0 commit comments

Comments
 (0)