Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.

Commit 51eb1c8

Browse files
committed
feat(seed): split wallet and identity seed files
1 parent 61b8c5b commit 51eb1c8

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

crates/maker/src/main.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ async fn main() -> Result<()> {
6464
"CFDs created with this release will settle after {settlement_interval_hours} hours"
6565
);
6666

67-
let seed = RandomSeed::initialize(&data_dir.join(seed::MAKER_WALLET_SEED_FILE)).await?;
67+
let wallet_seed_file = &data_dir.join(seed::MAKER_WALLET_SEED_FILE);
68+
let wallet_seed = RandomSeed::initialize(wallet_seed_file).await?;
6869

6970
let bitcoin_network = opts.network.bitcoin_network();
7071

@@ -76,7 +77,7 @@ async fn main() -> Result<()> {
7677
}
7778
wallet_xprv
7879
}
79-
None => seed.derive_extended_priv_key(bitcoin_network)?,
80+
None => wallet_seed.derive_extended_priv_key(bitcoin_network)?,
8081
};
8182

8283
let mut tasks = Tasks::default();
@@ -104,7 +105,16 @@ async fn main() -> Result<()> {
104105
return Ok(());
105106
}
106107

107-
let identities = seed.derive_identities();
108+
let identity_seed_file = &data_dir.join(seed::MAKER_IDENTITY_SEED_FILE);
109+
if !identity_seed_file.exists() {
110+
tracing::info!("Copying wallet seed file for identity seed file");
111+
// copy wallet seed file for backwards compatibility.
112+
tokio::fs::copy(&wallet_seed_file, &identity_seed_file).await?;
113+
}
114+
115+
// generate a new seed for the libp2p identity.
116+
let identity_seed = RandomSeed::initialize(identity_seed_file).await?;
117+
let identities = identity_seed.derive_identities();
108118

109119
let peer_id = identities.peer_id();
110120
let hex_pk = hex::encode(identities.identity_pk.to_bytes());

crates/taker/src/lib.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,22 @@ pub async fn run(opts: Opts) -> Result<()> {
352352

353353
let bitcoin_network = network.bitcoin_network();
354354

355-
let seed: Arc<ThreadSafeSeed> = match opts.app_seed {
355+
let wallet_seed_file = &data_dir.join(seed::TAKER_WALLET_SEED_FILE);
356+
let wallet_seed: Arc<ThreadSafeSeed> = match opts.app_seed {
356357
Some(seed_bytes) => Arc::new(AppSeed::from(seed_bytes)),
357-
None => Arc::new(RandomSeed::initialize(&data_dir.join(seed::TAKER_WALLET_SEED_FILE)).await?),
358+
None => Arc::new(RandomSeed::initialize(wallet_seed_file).await?),
358359
};
359360

360-
let identities = seed.derive_identities();
361+
let identity_seed_file = &data_dir.join(seed::TAKER_IDENTITY_SEED_FILE);
362+
if !identity_seed_file.exists() {
363+
tracing::info!("Copying wallet seed file for identity seed file");
364+
// copy wallet seed file for backwards compatibility.
365+
tokio::fs::copy(&wallet_seed_file, &identity_seed_file).await?;
366+
}
367+
368+
// use a different seed for the libp2p identity.
369+
let identity_seed = RandomSeed::initialize(identity_seed_file).await?;
370+
let identities = identity_seed.derive_identities();
361371

362372
let ext_priv_key = match opts.wallet_xprv {
363373
Some(wallet_xprv) => {
@@ -367,7 +377,7 @@ pub async fn run(opts: Opts) -> Result<()> {
367377
}
368378
wallet_xprv
369379
}
370-
None => seed.derive_extended_priv_key(bitcoin_network)?,
380+
None => wallet_seed.derive_extended_priv_key(bitcoin_network)?,
371381
};
372382

373383
let mut tasks = Tasks::default();

0 commit comments

Comments
 (0)