diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2fb125b..876a227 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -108,7 +108,7 @@ jobs: sleep 10s # Wait for maker to start\ # The maker-id is generated from the makers seed found in daemon/util/testnet_seeds/maker_seed - target/debug/taker --data-dir=/tmp/taker --generate-seed --maker-id 10d4ba2ac3f7a22da4009d813ff1bc3f404dfe2cc93a32bedf1512aa9951c95e testnet & + target/debug/taker --data-dir=/tmp/taker --maker-id 10d4ba2ac3f7a22da4009d813ff1bc3f404dfe2cc93a32bedf1512aa9951c95e testnet & sleep 10s # Wait for taker to start curl --fail http://localhost:8000/api/alive diff --git a/daemon/src/maker.rs b/daemon/src/maker.rs index bd31bf2..defbd77 100644 --- a/daemon/src/maker.rs +++ b/daemon/src/maker.rs @@ -44,10 +44,6 @@ struct Opts { #[clap(long)] data_dir: Option, - /// Generate a seed file within the data directory. - #[clap(long)] - generate_seed: bool, - /// If enabled logs will be in json format #[clap(short, long)] json: bool, @@ -160,7 +156,7 @@ async fn main() -> Result<()> { tokio::fs::create_dir_all(&data_dir).await?; } - let seed = Seed::initialize(&data_dir.join("maker_seed"), opts.generate_seed).await?; + let seed = Seed::initialize(&data_dir.join("maker_seed")).await?; let bitcoin_network = opts.network.bitcoin_network(); let ext_priv_key = seed.derive_extended_priv_key(bitcoin_network)?; diff --git a/daemon/src/seed.rs b/daemon/src/seed.rs index 7ab6193..e9a299e 100644 --- a/daemon/src/seed.rs +++ b/daemon/src/seed.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; use bdk::bitcoin::util::bip32::ExtendedPrivKey; use bdk::bitcoin::Network; use hkdf::Hkdf; @@ -11,23 +11,16 @@ pub struct Seed([u8; 256]); impl Seed { /// Initialize a [`Seed`] from a path. - /// - /// Fails if the file does not exist or it exists but would be overwritten. - pub async fn initialize(seed_file: &Path, generate: bool) -> Result { - let exists = seed_file.exists(); - - let seed = match (exists, generate) { - (true, false) => Seed::read_from(seed_file).await?, - (false, true) => { - let seed = Seed::default(); - seed.write_to(seed_file).await?; - - seed - } - (true, true) => bail!("Refusing to overwrite seed at {}", seed_file.display()), - (false, false) => bail!("Seed file at {} does not exist", seed_file.display()), + /// Generates new seed if there was no seed found in the given path + pub async fn initialize(seed_file: &Path) -> Result { + let seed = if !seed_file.exists() { + tracing::info!("No seed found. Generating new seed"); + let seed = Seed::default(); + seed.write_to(seed_file).await?; + seed + } else { + Seed::read_from(seed_file).await? }; - Ok(seed) } diff --git a/daemon/src/taker.rs b/daemon/src/taker.rs index 5b66125..d34c6f7 100644 --- a/daemon/src/taker.rs +++ b/daemon/src/taker.rs @@ -43,10 +43,6 @@ struct Opts { #[clap(long)] data_dir: Option, - /// Generate a seed file within the data directory. - #[clap(long)] - generate_seed: bool, - /// If enabled logs will be in json format #[clap(short, long)] json: bool, @@ -159,7 +155,7 @@ async fn main() -> Result<()> { tokio::fs::create_dir_all(&data_dir).await?; } - let seed = Seed::initialize(&data_dir.join("taker_seed"), opts.generate_seed).await?; + let seed = Seed::initialize(&data_dir.join("taker_seed")).await?; let bitcoin_network = opts.network.bitcoin_network(); let ext_priv_key = seed.derive_extended_priv_key(bitcoin_network)?;