Skip to content

Commit

Permalink
refactor to be similar to fetch for network retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
BlaineHeffron committed May 17, 2024
1 parent 3e3e20b commit 87a9f02
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
1 change: 0 additions & 1 deletion cmd/crates/soroban-test/tests/it/integration/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@ async fn invoke_test_generate_typescript_bindings() {
files.count() > 0,
"No files generated in the output directory"
);

}
9 changes: 4 additions & 5 deletions cmd/soroban-cli/src/commands/contract/bindings/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl NetworkRunnable for Cmd {
async fn run_against_rpc_server(
&self,
global_args: Option<&global::Args>,
_config: Option<&config::Args>,
config: Option<&config::Args>,
) -> Result<(), Error> {
let spec = if let Some(wasm) = &self.wasm {
let wasm: wasm::Args = wasm.into();
Expand All @@ -93,11 +93,10 @@ impl NetworkRunnable for Cmd {
.map_err(|e| Error::CannotParseContractId(self.contract_id.clone(), e))?;
let spec_entries = get_remote_contract_spec(
&contract_id,
self.network
.rpc_url
.as_deref()
.ok_or(Error::MissingRpcUrl)?,
self.locator.clone(),
self.network.clone(),
global_args,
config,
)
.await
.map_err(Error::from)?;
Expand Down
13 changes: 10 additions & 3 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl NetworkRunnable for Cmd {
global_args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<TxnResult<String>, Error> {
let c = config;
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
tracing::trace!(?network);
Expand All @@ -346,9 +347,15 @@ impl NetworkRunnable for Cmd {
let sequence: i64 = account_details.seq_num.into();
let AccountId(PublicKey::PublicKeyTypeEd25519(account_id)) = account_details.account_id;

let spec_entries = get_remote_contract_spec(&contract_id, &network.rpc_url, global_args)
.await
.map_err(Error::from)?;
let spec_entries = get_remote_contract_spec(
&contract_id,
config.locator.clone(),
config.network.clone(),
global_args,
c,
)
.await
.map_err(Error::from)?;

// Get the ledger footprint
let (function, spec, host_function_params, signers) =
Expand Down
17 changes: 15 additions & 2 deletions cmd/soroban-cli/src/get_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use soroban_env_host::xdr::{
use soroban_spec::read::FromWasmError;
pub use soroban_spec_tools::contract as contract_spec;

use crate::commands::config::{self, locator};
use crate::commands::network::{self, Network};
use crate::commands::{config::data, global};
use crate::rpc;

Expand All @@ -22,16 +24,27 @@ pub enum Error {
Data(#[from] data::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
Config(#[from] config::Error),
}

///
/// # Errors
pub async fn get_remote_contract_spec(
contract_id: &[u8; 32],
rpc_url: &str,
locator: locator::Args,
network: network::Args,
global_args: Option<&global::Args>,
config: Option<&config::Args>,
) -> Result<Vec<ScSpecEntry>, Error> {
let client = rpc::Client::new(rpc_url)?;
fn net(network: network::Args, locator: locator::Args) -> Result<Network, Error> {
Ok(network.get(&locator)?)
}
let network = config.map_or_else(|| net(network, locator), |c| Ok(c.get_network()?))?;
tracing::trace!(?network);
let client = rpc::Client::new(&network.rpc_url)?;
// Get contract data
let r = client.get_contract_data(&contract_id).await?;
tracing::trace!("{r:?}");
Expand Down

0 comments on commit 87a9f02

Please sign in to comment.