Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for alias on stellar events. #1405

Merged
merged 5 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions cmd/soroban-cli/src/commands/config/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
path::{Path, PathBuf},
str::FromStr,
};
use stellar_strkey::DecodeError;
use stellar_strkey::{Contract, DecodeError};

use crate::{utils::find_config_dir, Pwd};

Expand Down Expand Up @@ -284,13 +284,15 @@ impl Args {
&self,
alias_or_contract_id: &str,
network_passphrase: &str,
) -> Result<[u8; 32], Error> {
) -> Result<Contract, Error> {
let contract_id = self
.get_contract_id(alias_or_contract_id, network_passphrase)?
.unwrap_or_else(|| alias_or_contract_id.to_string());

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

Expand Down
3 changes: 2 additions & 1 deletion cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ impl NetworkRunnable for Cmd {

let contract_id = self
.locator
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?;
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?
.0;

get_remote_contract_spec(
&contract_id,
Expand Down
3 changes: 2 additions & 1 deletion cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ impl Cmd {
let network = self.network()?;
Ok(self
.locator
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?)
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?
.0)
}
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ impl NetworkRunnable for Cmd {
let contract_id = self
.config
.locator
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?;
.resolve_contract_id(&self.contract_id, &network.network_passphrase)?
.0;
let spec_entries = self.spec_entries()?;
if let Some(spec_entries) = &spec_entries {
// For testing wasm arg parsing
Expand Down
25 changes: 15 additions & 10 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -159,14 +159,6 @@ impl Cmd {
}
}

// 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,
})?;
}

let response = self.run_against_rpc_server(None, None).await?;

for event in &response.events {
Expand Down Expand Up @@ -226,11 +218,24 @@ impl NetworkRunnable for Cmd {
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;

let contract_ids: Vec<String> = self
.contract_ids
.iter()
.map(|id| {
Ok::<String, Error>(
self.locator
.resolve_contract_id(id, &network.network_passphrase)?
.to_string(),
)
})
.collect::<Result<Vec<_>, _>>()?;
fnando marked this conversation as resolved.
Show resolved Hide resolved

Ok(client
.get_events(
start,
Some(self.event_type),
&self.contract_ids,
&contract_ids,
&self.topic_filters,
Some(self.count),
)
Expand Down
Loading