From 1c21fc5babbccf46e6c416da2965b66e501e1956 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Tue, 4 Jun 2024 16:38:03 -0700 Subject: [PATCH] Read contract id from alias. --- .../src/commands/contract/invoke.rs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/cmd/soroban-cli/src/commands/contract/invoke.rs b/cmd/soroban-cli/src/commands/contract/invoke.rs index 37b06514d..5952705e6 100644 --- a/cmd/soroban-cli/src/commands/contract/invoke.rs +++ b/cmd/soroban-cli/src/commands/contract/invoke.rs @@ -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 { + 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 + } } }