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

Merged
merged 43 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
43 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
479687c
Merge branch 'main' into feat/add-rpc-header-arg
elizabethengelman Oct 3, 2024
9ecb45f
Fixes after merging main
elizabethengelman Oct 3, 2024
6032085
More fixes after merge
elizabethengelman Oct 7, 2024
c240a54
Add an rpc_client fn to Network impl
elizabethengelman Oct 7, 2024
799027c
Remove RpcClient and use network.rpc_client() instead
elizabethengelman Oct 7, 2024
b13f732
Clean up tests
elizabethengelman Oct 7, 2024
15e6991
Merge branch 'main' into feat/add-rpc-header-arg
elizabethengelman Oct 11, 2024
fdbd9b8
Cleanup after merging in main
elizabethengelman Oct 11, 2024
7e60f2e
update rs-stellar-rpc-client ref
leighmcculloch Oct 14, 2024
2ecc362
updated docs and renamed arg
leighmcculloch Oct 14, 2024
34545d3
clippy tweaks
leighmcculloch Oct 14, 2024
79197fc
trim whitespace
leighmcculloch Oct 14, 2024
d51c6f3
tweak error
leighmcculloch Oct 14, 2024
52a1f5f
fix
leighmcculloch Oct 14, 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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 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 @@ -235,6 +235,7 @@ impl TestEnv {
config::Args {
network: network::Args {
rpc_url: Some(self.rpc_url.clone()),
rpc_headers: [].to_vec(),
network_passphrase: Some(LOCAL_NETWORK_PASSPHRASE.to_string()),
network: None,
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
NetworkRunnable,
},
config::{self, data, network},
rpc::{Client, Error as SorobanRpcError},
rpc::Error as SorobanRpcError,
tx::builder,
utils::contract_id_hash_from_asset,
};
Expand Down Expand Up @@ -88,7 +88,7 @@ impl NetworkRunnable for Cmd {
let asset = &self.asset;

let network = config.get_network()?;
let client = Client::new(&network.rpc_url)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
5 changes: 2 additions & 3 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ use crate::{
assembled::simulate_and_assemble_transaction,
commands::{contract::install, HEADING_RPC},
config::{self, data, locator, network},
rpc::{self, Client},
utils, wasm,
rpc, utils, wasm,
};
use crate::{
commands::{
Expand Down Expand Up @@ -208,7 +207,7 @@ impl NetworkRunnable for Cmd {
None => rand::thread_rng().gen::<[u8; 32]>(),
};

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

const MAX_LEDGERS_TO_EXTEND: u32 = 535_679;
Expand Down Expand Up @@ -132,7 +130,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 = network.rpc_client()?;
let source_account = 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
15 changes: 8 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,13 @@ use std::path::PathBuf;

use crate::xdr;
use clap::arg;
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},
utils::rpc::get_remote_wasm_from_hash,
wasm::{self, Error::ContractIsStellarAsset},
};

#[derive(Debug, clap::Args, Clone, Default)]
#[command(group(
Expand Down Expand Up @@ -71,7 +71,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 = network.rpc_client()?;

client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
25 changes: 15 additions & 10 deletions cmd/soroban-cli/src/commands/contract/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ use crate::xdr::{
use clap::{command, Parser};

use super::restore;
use crate::assembled::simulate_and_assemble_transaction;
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::tx::builder::{self, TxExt};
use crate::{utils, wasm};
use crate::{
assembled::simulate_and_assemble_transaction,
commands::{
global,
txn_result::{TxnEnvelopeResult, TxnResult},
NetworkRunnable,
},
config::{self, data, network},
key,
print::Print,
rpc,
tx::builder::{self, TxExt},
utils, wasm,
};

const CONTRACT_META_SDK_KEY: &str = "rssdkver";
const PUBLIC_NETWORK_PASSPHRASE: &str = "Public Global Stellar Network ; September 2015";
Expand Down Expand Up @@ -103,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 = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
35 changes: 18 additions & 17 deletions cmd/soroban-cli/src/commands/contract/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,30 @@ use std::{fmt::Debug, fs, io};

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

use crate::xdr::{
self, AccountEntry, AccountEntryExt, AccountId, ContractEvent, ContractEventType,
DiagnosticEvent, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, LedgerEntryData,
Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions, PublicKey, ScSpecEntry,
SequenceNumber, String32, StringM, Thresholds, Transaction, TransactionExt, Uint256, VecM,
WriteXdr,
};

use soroban_rpc::{SimulateHostFunctionResult, SimulateTransactionResponse};
use soroban_spec::read::FromWasmError;

use super::super::events;
use super::arg_parsing;
use crate::assembled::simulate_and_assemble_transaction;
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,
assembled::simulate_and_assemble_transaction,
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,
xdr::{
self, AccountEntry, AccountEntryExt, AccountId, ContractEvent, ContractEventType,
DiagnosticEvent, HostFunction, InvokeContractArgs, InvokeHostFunctionOp, LedgerEntryData,
Limits, Memo, MuxedAccount, Operation, OperationBody, Preconditions, PublicKey,
ScSpecEntry, SequenceNumber, String32, StringM, Thresholds, Transaction, TransactionExt,
Uint256, VecM, WriteXdr,
},
Pwd,
};
use soroban_spec_tools::contract;

Expand Down Expand Up @@ -203,7 +204,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 = network.rpc_client()?;
let account_details = if self.is_view {
default_account_entry()
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/soroban-cli/src/commands/contract/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
commands::{global, NetworkRunnable},
config::{self, locator},
key,
rpc::{self, Client, FullLedgerEntries, FullLedgerEntry},
rpc::{self, FullLedgerEntries, FullLedgerEntry},
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -181,7 +181,7 @@ impl NetworkRunnable for Cmd {
let network = self.config.network.get(&locator)?;

tracing::trace!(?network);
let client = Client::new(&network.rpc_url)?;
let client = network.rpc_client()?;
let keys = self.key.parse_keys(&locator, &network)?;
Ok(client.get_full_ledger_entries(&keys).await?)
}
Expand Down
6 changes: 2 additions & 4 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::{self, Client},
wasm, Pwd,
key, rpc, wasm, Pwd,
};

#[derive(Parser, Debug, Clone)]
Expand Down Expand Up @@ -134,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 = Client::new(&network.rpc_url)?;
let client = network.rpc_client()?;
let source_account = config.source_account()?;

// Get the account sequence number
Expand Down
8 changes: 5 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,10 @@ use std::io;
use crate::xdr::{self, Limits, ReadXdr};

use super::{global, NetworkRunnable};
use crate::config::{self, locator, network};
use crate::rpc;
use crate::{
config::{self, locator, network},
rpc,
};

#[derive(Parser, Debug, Clone)]
#[group(skip)]
Expand Down Expand Up @@ -207,7 +209,7 @@ impl NetworkRunnable for Cmd {
self.network.get(&self.locator)
}?;

let client = rpc::Client::new(&network.rpc_url)?;
let client = network.rpc_client()?;
client
.verify_network_passphrase(Some(&network.network_passphrase))
.await?;
Expand Down
8 changes: 5 additions & 3 deletions cmd/soroban-cli/src/commands/tx/send.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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},
};

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

/// Command to simulate a transaction envelope via rpc
Expand Down Expand Up @@ -50,7 +52,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 = network.rpc_client()?;
let tx = super::xdr::unwrap_envelope_v1(super::xdr::tx_envelope_from_stdin()?)?;
let tx = simulate_and_assemble_transaction(&client, &tx).await?;
Ok(tx)
Expand Down
6 changes: 2 additions & 4 deletions cmd/soroban-cli/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use address::Address;
use clap::{arg, command};
use serde::{Deserialize, Serialize};

use soroban_rpc::Client;

use crate::{
print::Print,
signer::{self, LocalKey, Signer, SignerKind},
Expand Down Expand Up @@ -98,7 +96,7 @@ impl Args {
) -> Result<Option<Transaction>, Error> {
let network = self.get_network()?;
let source_key = self.key_pair()?;
let client = Client::new(&network.rpc_url)?;
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 @@ -116,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 = Client::new(&network.rpc_url)?;
let client = network.rpc_client()?;
Ok((client.get_account(account_str).await?.seq_num.0 + 1).into())
}
}
Expand Down
Loading
Loading