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 7ff1f6a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 27 deletions.
28 changes: 14 additions & 14 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 Expand Up @@ -191,7 +190,7 @@ mod tests {
config_locator: locator.clone(),
hd_path: None,
default_seed: false,
network: Default::default(),
network: super::network::Args::default(),
fund: false,
overwrite: false,
};
Expand All @@ -200,9 +199,10 @@ mod tests {
}

fn global_args() -> super::global::Args {
let mut global_args = super::global::Args::default();
global_args.quiet = true;
global_args
super::global::Args {
quiet: true,
..Default::default()
}
}

#[tokio::test]
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 })
}
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/signer/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ mod test {
let entry = StellarEntry::new("test").unwrap();
entry.set_password(&key_pair.to_bytes()).unwrap();

let tx_xdr = r#"AAAAAgAAAADh6eOnZEq1xQgKioffuH7/8D8x8+OdGFEkiYC6QKMWzQAAAGQAAACuAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAYAAAAAQAAAAAAAAAAAAAAAOHp46dkSrXFCAqKh9+4fv/wPzHz450YUSSJgLpAoxbNoFT1s8jZPCv9IJ2DsqGTA8pOtavv58JF53aDycpRPcEAAAAA+N2m5zc3EfWUmLvigYPOHKXhSy8OrWfVibc6y6PrQoYAAAAAAAAAAAAAAAA"#;
let tx_xdr = r"AAAAAgAAAADh6eOnZEq1xQgKioffuH7/8D8x8+OdGFEkiYC6QKMWzQAAAGQAAACuAAAAAQAAAAAAAAAAAAAAAQAAAAAAAAAYAAAAAQAAAAAAAAAAAAAAAOHp46dkSrXFCAqKh9+4fv/wPzHz450YUSSJgLpAoxbNoFT1s8jZPCv9IJ2DsqGTA8pOtavv58JF53aDycpRPcEAAAAA+N2m5zc3EfWUmLvigYPOHKXhSy8OrWfVibc6y6PrQoYAAAAAAAAAAAAAAAA";

let sign_tx_env_result = entry.sign_data(tx_xdr.as_bytes());
assert!(sign_tx_env_result.is_ok());
Expand Down

0 comments on commit 7ff1f6a

Please sign in to comment.