From 86b2372a7eb6b09e6eae53fafbf4ce270dbab7d4 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Mon, 24 Jun 2024 16:49:11 -0700 Subject: [PATCH] Add support for alias on `stellar events`. --- .../src/commands/config/locator.rs | 15 ++++++++++-- cmd/soroban-cli/src/commands/events.rs | 24 +++++++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cmd/soroban-cli/src/commands/config/locator.rs b/cmd/soroban-cli/src/commands/config/locator.rs index d32ff5e1d2..ec5897af59 100644 --- a/cmd/soroban-cli/src/commands/config/locator.rs +++ b/cmd/soroban-cli/src/commands/config/locator.rs @@ -280,15 +280,26 @@ impl Args { Ok(alias_data.ids.get(network_passphrase).cloned()) } - pub fn resolve_contract_id( + pub fn resolve_contract_id_as_string( &self, alias_or_contract_id: &str, network_passphrase: &str, - ) -> Result<[u8; 32], Error> { + ) -> Result { let contract_id = self .get_contract_id(alias_or_contract_id, network_passphrase)? .unwrap_or_else(|| alias_or_contract_id.to_string()); + Ok(contract_id) + } + + pub fn resolve_contract_id( + &self, + alias_or_contract_id: &str, + network_passphrase: &str, + ) -> Result<[u8; 32], Error> { + let contract_id = + self.resolve_contract_id_as_string(alias_or_contract_id, network_passphrase)?; + soroban_spec_tools::utils::contract_id_from_str(&contract_id) .map_err(|e| Error::CannotParseContractId(contract_id.clone(), e)) } diff --git a/cmd/soroban-cli/src/commands/events.rs b/cmd/soroban-cli/src/commands/events.rs index 23cd07e9d6..83b5b84b9e 100644 --- a/cmd/soroban-cli/src/commands/events.rs +++ b/cmd/soroban-cli/src/commands/events.rs @@ -7,7 +7,7 @@ use super::{ config::{self, locator}, global, network, NetworkRunnable, }; -use crate::{rpc, utils}; +use crate::rpc; #[derive(Parser, Debug, Clone)] #[group(skip)] @@ -159,12 +159,12 @@ impl Cmd { } } + let network = self.network.get(&self.locator)?; + // Validate contract_ids - for id in &mut self.contract_ids { - utils::contract_id_from_str(id).map_err(|e| Error::InvalidContractId { - contract_id: id.clone(), - error: e, - })?; + for id in &self.contract_ids { + self.locator + .resolve_contract_id(id, &network.network_passphrase)?; } let response = self.run_against_rpc_server(None, None).await?; @@ -226,11 +226,21 @@ impl NetworkRunnable for Cmd { client .verify_network_passphrase(Some(&network.network_passphrase)) .await?; + + let contract_ids: Vec = self + .contract_ids + .iter() + .map(|id| { + self.locator + .resolve_contract_id_as_string(id, &network.network_passphrase) + }) + .collect::, _>>()?; + Ok(client .get_events( start, Some(self.event_type), - &self.contract_ids, + &contract_ids, &self.topic_filters, Some(self.count), )