Skip to content

Commit

Permalink
Read contract id from alias.
Browse files Browse the repository at this point in the history
  • Loading branch information
fnando committed Jun 4, 2024
1 parent da28bdf commit 1c21fc5
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,33 @@ impl Cmd {

impl Cmd {
fn contract_id(&self) -> Result<[u8; 32], Error> {
soroban_spec_tools::utils::contract_id_from_str(&self.contract_id)
.map_err(|e| Error::CannotParseContractId(self.contract_id.clone(), e))
let contract_id = match self.load_contract_id() {
Some(id) => id,
None => self.contract_id.clone(),
};

soroban_spec_tools::utils::contract_id_from_str(&contract_id)
.map_err(|e| Error::CannotParseContractId(contract_id.clone(), e))
}

fn load_contract_id(&self) -> Option<String> {
let file_name = format!("{}.txt", self.contract_id);

let path = self
.config
.config_dir()
.unwrap()
.join("contract-ids")
.join(file_name);

if path.exists() {
match fs::read_to_string(path) {
Ok(content) => Some(content),
_ => None,
}
} else {
None
}
}
}

Expand Down

0 comments on commit 1c21fc5

Please sign in to comment.