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

Commit 58c2786

Browse files
committed
feat(seed): split wallet and identity seed files
1 parent 5347f50 commit 58c2786

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

crates/maker/src/main.rs

+12-2
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 seed = RandomSeed::initialize(wallet_seed_file).await?;
6869

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

@@ -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

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

353353
let bitcoin_network = network.bitcoin_network();
354354

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

362-
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();
363371

364372
let ext_priv_key = match opts.wallet_xprv {
365373
Some(wallet_xprv) => {

0 commit comments

Comments
 (0)