Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Dec 3, 2024
1 parent 74fa05b commit 8366b5c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
19 changes: 9 additions & 10 deletions cmd/soroban-cli/src/commands/keys/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Cmd {
warning. It can be suppressed with -q flag.",
);
}
let secret = self.secret(print)?;
let secret = self.secret(&print)?;
self.config_locator.write_identity(&self.name, &secret)?;

if !self.no_fund {
Expand All @@ -115,14 +115,14 @@ impl Cmd {
Ok(())
}

fn secret(&self, print: Print) -> Result<Secret, Error> {
fn secret(&self, print: &Print) -> Result<Secret, Error> {
let seed_phrase = self.seed_phrase()?;
Ok(if self.as_secret {
seed_phrase.private_key(self.hd_path)?.into()
} else if self.secure_store {
// secure_store:org.stellar.cli:<key name>
let entry_name_with_prefix = format!(
"{}{}-{}",
"{}{}-{:?}",
keyring::SECURE_STORE_ENTRY_PREFIX,
keyring::SECURE_STORE_ENTRY_SERVICE,
self.name.to_string()
Expand All @@ -132,7 +132,7 @@ impl Cmd {
let secret: Secret = entry_name_with_prefix.parse()?;

if let Secret::SecureStore { entry_name } = &secret {
self.write_to_secure_store(entry_name.clone(), seed_phrase, print)?;
Self::write_to_secure_store(entry_name, &seed_phrase, print)?;
}

secret
Expand All @@ -150,13 +150,12 @@ impl Cmd {
}

fn write_to_secure_store(
&self,
entry_name: String,
seed_phrase: Secret,
print: Print,
entry_name: &String,
seed_phrase: &Secret,
print: &Print,
) -> Result<(), Error> {
println!("Writing to secure store: {entry_name}");
let entry = StellarEntry::new(&entry_name)?;
print.infoln(format!("Writing to secure store: {entry_name}"));
let entry = StellarEntry::new(entry_name)?;
if let Ok(key) = entry.get_public_key() {
print.warnln(format!("A key for {entry_name} already exists in your operating system's secure store: {key}"));
} else {
Expand Down
19 changes: 8 additions & 11 deletions cmd/soroban-cli/src/config/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,14 @@ impl Secret {
}

pub fn public_key(&self, index: Option<usize>) -> Result<PublicKey, Error> {
match self {
Secret::SecureStore { entry_name } => {
let entry = keyring::StellarEntry::new(entry_name)?;
Ok(entry.get_public_key()?)
}
_ => {
let key = self.key_pair(index)?;
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
key.verifying_key().as_bytes(),
)?)
}
if let Secret::SecureStore { entry_name } = self {
let entry = keyring::StellarEntry::new(entry_name)?;
Ok(entry.get_public_key()?)
} else {
let key = self.key_pair(index)?;
Ok(stellar_strkey::ed25519::PublicKey::from_payload(
key.verifying_key().as_bytes(),
)?)
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl SecureStoreEntry {
let entry = StellarEntry::new(&self.name)?;
let signed_tx_env = entry.sign_data(tx_env.to_xdr_base64(Limits::none())?.as_bytes())?;
let hint = SignatureHint(entry.get_public_key()?.0[28..].try_into()?);
let signature = Signature(signed_tx_env.to_vec().try_into()?);
let signature = Signature(signed_tx_env.clone().try_into()?);
Ok(DecoratedSignature { hint, signature })
}
}

0 comments on commit 8366b5c

Please sign in to comment.