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

Feat/add rpc header arg #1618

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1c4af14
Add rpc-header as an optional arg for network add
elizabethengelman Sep 20, 2024
c6e5ba2
Use --rpc-header in the rest of the commands
elizabethengelman Sep 20, 2024
b2e1722
Update generated docs
elizabethengelman Sep 24, 2024
79e12b3
Update doc strings for rpc-header
elizabethengelman Sep 25, 2024
cd598db
Merge branch 'main' into feat/add-rpc-header-arg
elizabethengelman Sep 25, 2024
fc56739
Wip: use rpc::Client::new_with_headers in events command
elizabethengelman Sep 26, 2024
c10f903
Start to create an RpcClient wrapper
elizabethengelman Sep 26, 2024
45b5504
use RpcClient wrapper in contract extend
elizabethengelman Sep 26, 2024
946bb62
User RpcClient wrapper in contract install
elizabethengelman Sep 26, 2024
12cc842
User RpcClient wrapper in contract invoke
elizabethengelman Sep 26, 2024
4e2804d
User RpcClient wrapper in contract read
elizabethengelman Sep 26, 2024
18c2b60
User RpcClient wrapper in cotract restore
elizabethengelman Sep 26, 2024
d59d982
User RpcClient wrapper in deploy asset
elizabethengelman Sep 26, 2024
d67a607
User RpcClient wrapper in deploy wasm
elizabethengelman Sep 26, 2024
12275bc
User RpcClient wrapper in tx send
elizabethengelman Sep 26, 2024
e8f32ea
User RpcClient wrapper in tx simulate
elizabethengelman Sep 26, 2024
59a96f2
Make crate imports consistent
elizabethengelman Sep 26, 2024
1534839
Merge branch 'main' into feat/add-rpc-header-arg
elizabethengelman Sep 27, 2024
d90bc5d
Use RpcClient wrapper in wasm
elizabethengelman Sep 27, 2024
4fb8679
Use RpcClient wrapper in info shared
elizabethengelman Sep 27, 2024
0ce2ed8
Use RpcClient wrapper in config mod
elizabethengelman Sep 27, 2024
88cd056
Validate passed in headers
elizabethengelman Sep 27, 2024
781901f
Allow for multiple rpc_headers
elizabethengelman Sep 27, 2024
ddd05cf
Merge branch 'main' into feat/add-rpc-header-arg
elizabethengelman Sep 30, 2024
baaa7ba
Change value_delimiter to newline
elizabethengelman Sep 30, 2024
8808af6
Cleanup
elizabethengelman Sep 30, 2024
b44da09
Check in generate docs
elizabethengelman Sep 30, 2024
5febc73
Fix: make sure to use rpc-headers / STELLAR_RPC_HEADERS
elizabethengelman Sep 30, 2024
ec4b7d4
Clippy
elizabethengelman Sep 30, 2024
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
27 changes: 27 additions & 0 deletions FULL_HELP_DOCS.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions cmd/crates/soroban-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl TestEnv {
config::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
rpc_header: None,
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
Expand Down
7 changes: 5 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use crate::{
NetworkRunnable,
},
config::{self, data, network},
rpc::{Client, Error as SorobanRpcError},
rpc::Error as SorobanRpcError,
rpc_client::{Error as RpcClientError, RpcClient},
utils::{contract_id_hash_from_asset, parsing::parse_asset},
};

Expand All @@ -44,6 +45,8 @@ pub enum Error {
Data(#[from] data::Error),
#[error(transparent)]
Network(#[from] network::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -93,7 +96,7 @@ impl NetworkRunnable for Cmd {
let asset = parse_asset(&self.asset)?;

let network = config.get_network()?;
let client = Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
7 changes: 5 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ use soroban_env_host::{
use crate::{
commands::{contract::install, HEADING_RPC},
config::{self, data, locator, network},
rpc::{self, Client},
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
utils, wasm,
};
use crate::{
Expand Down Expand Up @@ -115,6 +116,8 @@ pub enum Error {
InvalidAliasFormat { alias: String },
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl Cmd {
Expand Down Expand Up @@ -208,7 +211,7 @@ impl NetworkRunnable for Cmd {
None => rand::thread_rng().gen::<[u8; 32]>(),
};

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

Expand Down Expand Up @@ -86,6 +86,8 @@ pub enum Error {
Network(#[from] network::Error),
#[error(transparent)]
Locator(#[from] locator::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

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

Expand Down
12 changes: 7 additions & 5 deletions cmd/soroban-cli/src/commands/contract/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use std::{fmt::Debug, fs, io};

use clap::{arg, command, Parser};

use crate::commands::{global, NetworkRunnable};
use crate::config::{
self, locator,
network::{self, Network},
use crate::{
commands::{global, NetworkRunnable},
config::{
self, locator,
network::{self, Network},
},
wasm, Pwd,
};
use crate::{wasm, Pwd};

#[derive(Parser, Debug, Default, Clone)]
#[allow(clippy::struct_excessive_bools)]
Expand Down
18 changes: 11 additions & 7 deletions cmd/soroban-cli/src/commands/contract/info/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::path::PathBuf;

use clap::arg;
use soroban_env_host::xdr;
use soroban_rpc::Client;

use crate::commands::contract::info::shared::Error::InvalidWasmHash;
use crate::config::{locator, network};
use crate::utils::rpc::get_remote_wasm_from_hash;
use crate::wasm;
use crate::wasm::Error::ContractIsStellarAsset;
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},
};

#[derive(Debug, clap::Args, Clone, Default)]
#[command(group(
Expand Down Expand Up @@ -56,6 +57,8 @@ 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 @@ -71,7 +74,8 @@ pub async fn fetch_wasm(args: &Args) -> Result<Option<Vec<u8>>, Error> {

let hash = xdr::Hash(hash);

let client = Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;

client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
24 changes: 16 additions & 8 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ use soroban_env_host::xdr::{
};

use super::restore;
use crate::commands::txn_result::{TxnEnvelopeResult, TxnResult};
use crate::commands::{global, NetworkRunnable};
use crate::config::{self, data, network};
use crate::key;
use crate::print::Print;
use crate::rpc::{self, Client};
use crate::{utils, wasm};
use crate::{
commands::{
global,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, network},
key,
print::Print,
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
utils, wasm,
};

const CONTRACT_META_SDK_KEY: &str = "rssdkver";
const PUBLIC_NETWORK_PASSPHRASE: &str = "Public Global Stellar Network ; September 2015";
Expand Down Expand Up @@ -70,6 +76,8 @@ pub enum Error {
Network(#[from] network::Error),
#[error(transparent)]
Data(#[from] data::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

impl Cmd {
Expand Down Expand Up @@ -100,7 +108,7 @@ impl NetworkRunnable for Cmd {
let config = config.unwrap_or(&self.config);
let contract = self.wasm.read()?;
let network = config.get_network()?;
let client = Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
21 changes: 13 additions & 8 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@ use soroban_spec::read::FromWasmError;

use super::super::events;
use super::arg_parsing;
use crate::commands::contract::arg_parsing::{build_host_function_parameters, output_to_string};
use crate::commands::txn_result::{TxnEnvelopeResult, TxnResult};
use crate::commands::NetworkRunnable;
use crate::get_spec::{self, get_remote_contract_spec};
use crate::print;
use crate::{
commands::global,
commands::{
contract::arg_parsing::{build_host_function_parameters, output_to_string},
global,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, locator, network},
rpc, Pwd,
get_spec::{self, get_remote_contract_spec},
print, rpc,
rpc_client::{Error as RpcClientError, RpcClient},
Pwd,
};
use soroban_spec_tools::contract;

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

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

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

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

impl Cmd {
Expand Down Expand Up @@ -134,7 +136,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 = Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
let key = config.source_account()?;

// Get the account sequence number
Expand Down
11 changes: 8 additions & 3 deletions cmd/soroban-cli/src/commands/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ use std::io;
use soroban_env_host::xdr::{self, Limits, ReadXdr};

use super::{global, NetworkRunnable};
use crate::config::{self, locator, network};
use crate::rpc;
use crate::{
config::{self, locator, network},
rpc,
rpc_client::{Error as RpcClientError, RpcClient},
};

#[derive(Parser, Debug, Clone)]
#[group(skip)]
Expand Down Expand Up @@ -119,6 +122,8 @@ 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 @@ -207,7 +212,7 @@ impl NetworkRunnable for Cmd {
self.network.get(&self.locator)
}?;

let client = rpc::Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
11 changes: 8 additions & 3 deletions cmd/soroban-cli/src/commands/tx/send.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use async_trait::async_trait;
use soroban_rpc::GetTransactionResponse;

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

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand All @@ -16,6 +19,8 @@ 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 @@ -52,7 +57,7 @@ impl NetworkRunnable for Cmd {
} else {
self.network.get(&self.locator)?
};
let client = crate::rpc::Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
let tx_env = super::xdr::tx_envelope_from_stdin()?;
Ok(client.send_transaction_polling(&tx_env).await?)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/soroban-cli/src/commands/tx/simulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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 @@ -14,6 +15,8 @@ pub enum Error {
Rpc(#[from] crate::rpc::Error),
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
RpcClient(#[from] RpcClientError),
}

/// Command to simulate a transaction envelope via rpc
Expand Down Expand Up @@ -48,7 +51,7 @@ impl NetworkRunnable for Cmd {
) -> Result<Self::Result, Self::Error> {
let config = config.unwrap_or(&self.config);
let network = config.get_network()?;
let client = crate::rpc::Client::new(&network.rpc_url)?;
let client = RpcClient::new(network.clone())?;
let tx = super::xdr::unwrap_envelope_v1(super::xdr::tx_envelope_from_stdin()?)?;
Ok(client.simulate_and_assemble_transaction(&tx).await?)
}
Expand Down
Loading
Loading