Skip to content

Commit

Permalink
Remove RpcClient and use network.rpc_client() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
elizabethengelman committed Oct 7, 2024
1 parent c240a54 commit 799027c
Show file tree
Hide file tree
Showing 15 changed files with 25 additions and 191 deletions.
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use crate::{
},
config::{self, data, network},
rpc::Error as SorobanRpcError,
rpc_client::{Error as RpcClientError, RpcClient},
tx::builder,
utils::contract_id_hash_from_asset,
};
Expand All @@ -45,8 +44,6 @@ pub enum Error {
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
#[error(transparent)]
Builder(#[from] builder::Error),
}

Expand Down Expand Up @@ -97,7 +94,7 @@ impl NetworkRunnable for Cmd {
let asset = &self.asset;

let network = config.get_network()?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
8 changes: 2 additions & 6 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use soroban_env_host::{
use crate::{
commands::{contract::install, HEADING_RPC},
config::{self, data, locator, network},
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
utils, wasm,
rpc, utils, wasm,
};
use crate::{
commands::{
Expand Down Expand Up @@ -116,8 +114,6 @@ pub enum Error {
InvalidAliasFormat { alias: String },
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
#[error("Only ed25519 accounts are allowed")]
OnlyEd25519AccountsAllowed,
}
Expand Down Expand Up @@ -215,7 +211,7 @@ impl NetworkRunnable for Cmd {
None => rand::thread_rng().gen::<[u8; 32]>(),
};

let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
8 changes: 2 additions & 6 deletions cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use crate::{
NetworkRunnable,
},
config::{self, data, locator, network},
key, rpc,
rpc_client::{Error as RpcClientError, RpcClient},
wasm, Pwd,
key, rpc, wasm, Pwd,
};

const MAX_LEDGERS_TO_EXTEND: u32 = 535_679;
Expand Down Expand Up @@ -86,8 +84,6 @@ pub enum Error {
Network(#[from] network::Error),
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl Cmd {
Expand Down Expand Up @@ -133,7 +129,7 @@ impl NetworkRunnable for Cmd {
let network = config.get_network()?;
tracing::trace!(?network);
let keys = self.key.parse_keys(&config.locator, &network)?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let source_account = config.source_account()?;
let extend_to = self.ledgers_to_extend();

Expand Down
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/commands/contract/info/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use soroban_env_host::xdr;
use crate::{
commands::contract::info::shared::Error::InvalidWasmHash,
config::{locator, network},
rpc_client::{Error as RpcClientError, RpcClient},
utils::rpc::get_remote_wasm_from_hash,
wasm::{self, Error::ContractIsStellarAsset},
};
Expand Down Expand Up @@ -57,8 +56,6 @@ pub enum Error {
InvalidWasmHash(String),
#[error(transparent)]
Rpc(#[from] soroban_rpc::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

pub async fn fetch_wasm(args: &Args) -> Result<Option<Vec<u8>>, Error> {
Expand All @@ -74,7 +71,7 @@ pub async fn fetch_wasm(args: &Args) -> Result<Option<Vec<u8>>, Error> {

let hash = xdr::Hash(hash);

let client = RpcClient::new(network)?;
let client = network.rpc_client()?;

client
.verify_network_passphrase(Some(&network.network_passphrase))
Expand Down
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
key,
print::Print,
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
tx::builder::{self, TxExt},
utils, wasm,
};
Expand Down Expand Up @@ -77,8 +76,6 @@ pub enum Error {
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
#[error(transparent)]
Builder(#[from] builder::Error),
}

Expand Down Expand Up @@ -110,7 +107,7 @@ impl NetworkRunnable for Cmd {
let config = config.unwrap_or(&self.config);
let contract = self.wasm.read()?;
let network = config.get_network()?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
8 changes: 2 additions & 6 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ use crate::{
},
config::{self, data, locator, network},
get_spec::{self, get_remote_contract_spec},
print, rpc,
rpc_client::{Error as RpcClientError, RpcClient},
Pwd,
print, rpc, Pwd,
};
use soroban_spec_tools::contract;

Expand Down Expand Up @@ -131,8 +129,6 @@ pub enum Error {
GetSpecError(#[from] get_spec::Error),
#[error(transparent)]
ArgParsing(#[from] arg_parsing::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -214,7 +210,7 @@ impl NetworkRunnable for Cmd {
// For testing wasm arg parsing
let _ = build_host_function_parameters(&contract_id, &self.slop, spec_entries, config)?;
}
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let account_details = if self.is_view {
default_account_entry()
} else {
Expand Down
5 changes: 2 additions & 3 deletions cmd/soroban-cli/src/commands/contract/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::{
config::{self, locator},
key,
rpc::{self, FullLedgerEntries, FullLedgerEntry},
rpc_client::{Error as RpcClientError, RpcClient},
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -91,7 +90,7 @@ pub enum Error {
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
Network(#[from] config::network::Error),
}

impl Cmd {
Expand Down Expand Up @@ -188,7 +187,7 @@ impl NetworkRunnable for Cmd {
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
tracing::trace!(?network);
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let keys = self.key.parse_keys(&config.locator, &network)?;
Ok(client.get_full_ledger_entries(&keys).await?)
}
Expand Down
8 changes: 2 additions & 6 deletions cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ use crate::{
NetworkRunnable,
},
config::{self, data, locator, network},
key, rpc,
rpc_client::{Error as RpcClientError, RpcClient},
wasm, Pwd,
key, rpc, wasm, Pwd,
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -89,8 +87,6 @@ pub enum Error {
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl Cmd {
Expand Down Expand Up @@ -136,7 +132,7 @@ impl NetworkRunnable for Cmd {
let network = config.get_network()?;
tracing::trace!(?network);
let entry_keys = self.key.parse_keys(&config.locator, &network)?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let source_account = config.source_account()?;

// Get the account sequence number
Expand Down
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use super::{global, NetworkRunnable};
use crate::{
config::{self, locator, network},
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -122,8 +121,6 @@ pub enum Error {
Locator(#[from] locator::Error),
#[error(transparent)]
Config(#[from] config::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, clap::ValueEnum)]
Expand Down Expand Up @@ -212,7 +209,7 @@ impl NetworkRunnable for Cmd {
self.network.get(&self.locator)
}?;

let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
5 changes: 1 addition & 4 deletions cmd/soroban-cli/src/commands/tx/send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use soroban_rpc::GetTransactionResponse;
use crate::{
commands::{global, NetworkRunnable},
config::{self, locator, network},
rpc_client::{Error as RpcClientError, RpcClient},
};

#[derive(thiserror::Error, Debug)]
Expand All @@ -19,8 +18,6 @@ pub enum Error {
Rpc(#[from] crate::rpc::Error),
#[error(transparent)]
SerdeJson(#[from] serde_json::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

#[derive(Debug, clap::Parser, Clone)]
Expand Down Expand Up @@ -57,7 +54,7 @@ impl NetworkRunnable for Cmd {
} else {
self.network.get(&self.locator)?
};
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let tx_env = super::xdr::tx_envelope_from_stdin()?;
Ok(client.send_transaction_polling(&tx_env).await?)
}
Expand Down
5 changes: 2 additions & 3 deletions cmd/soroban-cli/src/commands/tx/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use async_trait::async_trait;
use soroban_rpc::Assembled;

use crate::commands::{config, global, NetworkRunnable};
use crate::rpc_client::{Error as RpcClientError, RpcClient};

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -16,7 +15,7 @@ pub enum Error {
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
Network(#[from] config::network::Error),
}

/// Command to simulate a transaction envelope via rpc
Expand Down Expand Up @@ -51,7 +50,7 @@ impl NetworkRunnable for Cmd {
) -> Result<Self::Result, Self::Error> {
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let tx = super::xdr::unwrap_envelope_v1(super::xdr::tx_envelope_from_stdin()?)?;
Ok(client.simulate_and_assemble_transaction(&tx).await?)
}
Expand Down
7 changes: 2 additions & 5 deletions cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use serde::{Deserialize, Serialize};

use crate::{
print::Print,
rpc_client::{Error as RpcClientError, RpcClient},
signer::{self, LocalKey, Signer, SignerKind},
xdr::{self, SequenceNumber, Transaction, TransactionEnvelope},
Pwd,
Expand Down Expand Up @@ -36,8 +35,6 @@ pub enum Error {
#[error(transparent)]
StellarStrkey(#[from] stellar_strkey::DecodeError),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
#[error(transparent)]
Address(#[from] address::Error),
}

Expand Down Expand Up @@ -99,7 +96,7 @@ impl Args {
) -> Result<Option<Transaction>, Error> {
let network = self.get_network()?;
let source_key = self.key_pair()?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
let latest_ledger = client.get_latest_ledger().await?.sequence;
let seq_num = latest_ledger + 60; // ~ 5 min
Ok(signer::sign_soroban_authorizations(
Expand All @@ -117,7 +114,7 @@ impl Args {

pub async fn next_sequence_number(&self, account_str: &str) -> Result<SequenceNumber, Error> {
let network = self.get_network()?;
let client = RpcClient::new(&network)?;
let client = network.rpc_client()?;
Ok((client.get_account(account_str).await?.seq_num.0 + 1).into())
}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/soroban-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pub mod get_spec;
pub mod key;
pub mod log;
pub mod print;
pub mod rpc_client;
pub mod signer;
pub mod toid;
pub mod tx;
Expand Down
Loading

0 comments on commit 799027c

Please sign in to comment.