Skip to content

Commit 67eb22a

Browse files
committed
Remove unneeded separation of wallet and name
1 parent 309c45d commit 67eb22a

File tree

1 file changed

+11
-38
lines changed

1 file changed

+11
-38
lines changed

crates/signer/src/manager/dirk.rs

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ enum Account {
3333
}
3434

3535
impl Account {
36-
pub fn full_name(&self) -> String {
36+
pub fn name(&self) -> &str {
3737
match self {
38-
Account::Simple(account) => format!("{}/{}", account.wallet, account.name),
39-
Account::Distributed(account) => format!("{}/{}", account.wallet, account.name),
38+
Account::Simple(account) => &account.name,
39+
Account::Distributed(account) => &account.name,
4040
}
4141
}
4242
}
@@ -45,7 +45,6 @@ impl Account {
4545
struct SimpleAccount {
4646
public_key: BlsPublicKey,
4747
connection: Channel,
48-
wallet: String,
4948
name: String,
5049
}
5150

@@ -54,7 +53,6 @@ struct DistributedAccount {
5453
composite_public_key: BlsPublicKey,
5554
participants: HashMap<u32, Channel>,
5655
threshold: u32,
57-
wallet: String,
5856
name: String,
5957
}
6058

@@ -269,10 +267,7 @@ impl DirkManager {
269267
.sign(SignRequest {
270268
data: object_root.to_vec(),
271269
domain: compute_domain(self.chain, COMMIT_BOOST_DOMAIN).to_vec(),
272-
id: Some(sign_request::Id::Account(format!(
273-
"{}/{}",
274-
account.wallet, account.name
275-
))),
270+
id: Some(sign_request::Id::Account(account.name.clone())),
276271
})
277272
.map(|res| (res, *id))
278273
.await
@@ -368,7 +363,7 @@ impl DirkManager {
368363

369364
let response = AccountManagerClient::new(consensus.connection.clone())
370365
.generate(GenerateRequest {
371-
account: format!("{}/{}/{module}/{uuid}", consensus.wallet, consensus.name),
366+
account: format!("{}/{module}/{uuid}", consensus.name),
372367
passphrase: password.as_bytes().to_vec(),
373368
participants: 1,
374369
signing_threshold: 1,
@@ -394,7 +389,6 @@ impl DirkManager {
394389
inner: Account::Simple(SimpleAccount {
395390
public_key: proxy_key,
396391
connection: consensus.connection.clone(),
397-
wallet: consensus.wallet.clone(),
398392
name: format!("{}/{module}/{uuid}", consensus.name),
399393
}),
400394
};
@@ -426,7 +420,7 @@ impl DirkManager {
426420
for (id, channel) in consensus.participants.iter() {
427421
let Ok(response) = AccountManagerClient::new(channel.clone())
428422
.generate(GenerateRequest {
429-
account: format!("{}/{}/{module}/{uuid}", consensus.wallet, consensus.name),
423+
account: format!("{}/{module}/{uuid}", consensus.name),
430424
passphrase: password.as_bytes().to_vec(),
431425
participants: consensus.participants.len() as u32,
432426
signing_threshold: consensus.threshold,
@@ -455,7 +449,6 @@ impl DirkManager {
455449
composite_public_key: proxy_key,
456450
participants: consensus.participants.clone(),
457451
threshold: consensus.threshold,
458-
wallet: consensus.wallet.clone(),
459452
name: format!("{}/{module}/{uuid}", consensus.name),
460453
}),
461454
};
@@ -482,8 +475,8 @@ impl DirkManager {
482475

483476
/// Store the password for a proxy account in disk
484477
fn store_password(&self, account: &ProxyAccount, password: String) -> eyre::Result<()> {
485-
let full_name = account.inner.full_name();
486-
let (parent, name) = full_name.rsplit_once('/').ok_or_eyre("Invalid account name")?;
478+
let name = account.inner.name();
479+
let (parent, name) = name.rsplit_once('/').ok_or_eyre("Invalid account name")?;
487480
let parent_path = self.secrets_path.join(parent);
488481

489482
std::fs::create_dir_all(parent_path.clone())?;
@@ -506,7 +499,7 @@ impl DirkManager {
506499
let request = async move {
507500
let response = AccountManagerClient::new(channel.clone())
508501
.unlock(UnlockAccountRequest {
509-
account: account.full_name(),
502+
account: account.name().to_string(),
510503
passphrase: password.as_bytes().to_vec(),
511504
})
512505
.await;
@@ -560,35 +553,21 @@ async fn connect(
560553
.map_err(eyre::Error::from)
561554
}
562555

563-
/// Decompose a full account name into wallet and name
564-
fn decompose_name(full_name: &str) -> eyre::Result<(String, String)> {
565-
full_name
566-
.split_once('/')
567-
.map(|(wallet, name)| (wallet.to_string(), name.to_string()))
568-
.ok_or_else(|| eyre::eyre!("Invalid account name"))
569-
}
570-
571556
/// Load `SimpleAccount`s into the consensus accounts map
572557
fn load_simple_accounts(
573558
accounts: Vec<crate::proto::v1::Account>,
574559
channel: &Channel,
575560
consensus_accounts: &mut HashMap<BlsPublicKey, Account>,
576561
) {
577562
for account in accounts {
578-
let Ok((wallet, name)) = decompose_name(&account.name) else {
579-
warn!("Invalid account name {}", account.name);
580-
continue;
581-
};
582-
583563
match BlsPublicKey::try_from(account.public_key.as_slice()) {
584564
Ok(public_key) => {
585565
consensus_accounts.insert(
586566
public_key,
587567
Account::Simple(SimpleAccount {
588568
public_key,
589569
connection: channel.clone(),
590-
wallet,
591-
name,
570+
name: account.name,
592571
}),
593572
);
594573
}
@@ -631,11 +610,6 @@ fn load_distributed_accounts(
631610
participants.insert(participant_id as u32, channel.clone());
632611
}
633612
None => {
634-
let Ok((wallet, name)) = decompose_name(&account.name) else {
635-
warn!("Invalid account name {}", account.name);
636-
continue;
637-
};
638-
639613
let mut participants = HashMap::with_capacity(account.participants.len());
640614
participants.insert(participant_id as u32, channel.clone());
641615

@@ -645,8 +619,7 @@ fn load_distributed_accounts(
645619
composite_public_key: public_key,
646620
participants,
647621
threshold: account.signing_threshold,
648-
wallet,
649-
name,
622+
name: account.name,
650623
}),
651624
);
652625
}

0 commit comments

Comments
 (0)