Skip to content

Commit

Permalink
fix: only resolve contract alias if needed (#1575)
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal authored Aug 29, 2024
1 parent f7b007e commit 34e8a5d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
6 changes: 1 addition & 5 deletions cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ impl NetworkRunnable for Cmd {
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
tracing::trace!(?network);
let contract = config.locator.resolve_contract_id(
self.key.contract_id.as_ref().unwrap(),
&network.network_passphrase,
)?;
let keys = self.key.parse_keys(contract)?;
let keys = self.key.parse_keys(&config.locator, &network)?;
let network = &config.get_network()?;
let client = Client::new(&network.rpc_url)?;
let key = config.key_pair()?;
Expand Down
6 changes: 1 addition & 5 deletions cmd/soroban-cli/src/commands/contract/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ impl NetworkRunnable for Cmd {
let network = config.get_network()?;
tracing::trace!(?network);
let client = Client::new(&network.rpc_url)?;
let contract = config.locator.resolve_contract_id(
self.key.contract_id.as_ref().unwrap(),
&network.network_passphrase,
)?;
let keys = self.key.parse_keys(contract)?;
let keys = self.key.parse_keys(&config.locator, &network)?;
Ok(client.get_full_ledger_entries(&keys).await?)
}
}
6 changes: 1 addition & 5 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ impl NetworkRunnable for Cmd {
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
tracing::trace!(?network);
let contract = config.locator.resolve_contract_id(
self.key.contract_id.as_ref().unwrap(),
&network.network_passphrase,
)?;
let entry_keys = self.key.parse_keys(contract)?;
let entry_keys = self.key.parse_keys(&config.locator, &network)?;
let client = Client::new(&network.rpc_url)?;
let key = config.key_pair()?;

Expand Down
20 changes: 16 additions & 4 deletions cmd/soroban-cli/src/key.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
commands::contract::Durability,
config::{locator, network::Network},
wasm,
};
use clap::arg;
use soroban_env_host::xdr::{
self, LedgerKey, LedgerKeyContractCode, LedgerKeyContractData, Limits, ReadXdr, ScAddress,
ScVal,
};
use std::path::PathBuf;
use stellar_strkey::Contract;

use crate::{commands::contract::Durability, wasm};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -18,6 +20,8 @@ pub enum Error {
CannotParseContractId(String, stellar_strkey::DecodeError),
#[error(transparent)]
Wasm(#[from] wasm::Error),
#[error(transparent)]
Locator(#[from] locator::Error),
}

#[derive(Debug, clap::Args, Clone)]
Expand Down Expand Up @@ -61,7 +65,13 @@ pub struct Args {
}

impl Args {
pub fn parse_keys(&self, contract: Contract) -> Result<Vec<LedgerKey>, Error> {
pub fn parse_keys(
&self,
locator: &locator::Args,
Network {
network_passphrase, ..
}: &Network,
) -> Result<Vec<LedgerKey>, Error> {
let keys = if let Some(keys) = &self.key {
keys.iter()
.map(|key| {
Expand All @@ -87,6 +97,8 @@ impl Args {
} else {
vec![ScVal::LedgerKeyContractInstance]
};
let contract =
locator.resolve_contract_id(self.contract_id.as_ref().unwrap(), network_passphrase)?;

Ok(keys
.into_iter()
Expand Down

0 comments on commit 34e8a5d

Please sign in to comment.