Skip to content

Commit

Permalink
split two logics combined into one fn
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Dec 2, 2024
1 parent 02d0528 commit 2bf2a7a
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions cmd/soroban-cli/src/commands/contract/arg_parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,15 @@ pub fn build_host_function_parameters(
.map(|i| {
let name = i.name.to_utf8_string()?;
if let Some(mut val) = matches_.get_raw(&name) {
let mut s = val.next().unwrap().to_string_lossy().to_string();
let mut s = val
.next()
.unwrap()
.to_string_lossy()
.trim_matches('"')
.to_string();
if matches!(i.type_, ScSpecTypeDef::Address) {
let (addr, signer) = resolve_sc_address(&s, config)?;
let addr = resolve_address(&s, config)?;
let signer = resolve_signer(&s, config);
s = addr;
if let Some(signer) = signer {
signers.push(signer);
Expand Down Expand Up @@ -247,26 +253,26 @@ pub fn output_to_string(
Ok(TxnResult::Res(res_str))
}

fn resolve_sc_address(
addr_or_alias: &str,
config: &config::Args,
) -> Result<(String, Option<SigningKey>), Error> {
let addr_or_alias = addr_or_alias.trim_matches('"');
fn resolve_address(addr_or_alias: &str, config: &config::Args) -> Result<String, Error> {
let sc_address: ScAddress = addr_or_alias.parse().unwrap();
let account = match sc_address {
ScAddress::Address(addr) => return Ok((addr.to_string(), None)),
ScAddress::Address(addr) => addr.to_string(),
addr @ ScAddress::Alias(_) => {
let addr = addr.resolve(&config.locator, &config.get_network()?.network_passphrase)?;
match addr {
xdr::ScAddress::Account(account) => account.to_string(),
contract @ xdr::ScAddress::Contract(_) => return Ok((contract.to_string(), None)),
contract @ xdr::ScAddress::Contract(_) => contract.to_string(),
}
}
};
Ok(account)
}

fn resolve_signer(addr_or_alias: &str, config: &config::Args) -> Option<SigningKey> {
let cmd = crate::commands::keys::address::Cmd {
name: addr_or_alias.to_string(),
hd_path: Some(0),
locator: config.locator.clone(),
};
Ok((account, cmd.private_key().ok()))
cmd.private_key().ok()
}

0 comments on commit 2bf2a7a

Please sign in to comment.