Clarify url vs addr
This commit is contained in:
parent
e3ef4f25d3
commit
c2b1010f18
|
@ -13,5 +13,5 @@ pub fn create_client_with_timeout(
|
|||
timeout: Duration,
|
||||
) -> ThinClient {
|
||||
let (_, transactions_socket) = solana_netutil::bind_in_range(range).unwrap();
|
||||
ThinClient::new_with_timeout(rpc, tpu, transactions_socket, timeout)
|
||||
ThinClient::new_socket_with_timeout(rpc, tpu, transactions_socket, timeout)
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ pub const SIGNATURE: &str =
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct MockRpcClient {
|
||||
pub addr: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
impl MockRpcClient {
|
||||
pub fn new(addr: String) -> Self {
|
||||
MockRpcClient { addr }
|
||||
pub fn new(url: String) -> Self {
|
||||
MockRpcClient { url }
|
||||
}
|
||||
|
||||
pub fn retry_get_balance(
|
||||
|
@ -45,7 +45,7 @@ impl MockRpcClient {
|
|||
params: Option<Value>,
|
||||
mut _retries: usize,
|
||||
) -> Result<Value, Box<dyn error::Error>> {
|
||||
if self.addr == "fails" {
|
||||
if self.url == "fails" {
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
let val = match request {
|
||||
|
@ -61,14 +61,14 @@ impl MockRpcClient {
|
|||
}
|
||||
}
|
||||
RpcRequest::GetBalance => {
|
||||
let n = if self.addr == "airdrop" { 0 } else { 50 };
|
||||
let n = if self.url == "airdrop" { 0 } else { 50 };
|
||||
Value::Number(Number::from(n))
|
||||
}
|
||||
RpcRequest::GetRecentBlockhash => Value::String(PUBKEY.to_string()),
|
||||
RpcRequest::GetSignatureStatus => {
|
||||
let str = if self.addr == "account_in_use" {
|
||||
let str = if self.url == "account_in_use" {
|
||||
"AccountInUse"
|
||||
} else if self.addr == "bad_sig_status" {
|
||||
} else if self.url == "bad_sig_status" {
|
||||
"Nonexistent"
|
||||
} else {
|
||||
"Confirmed"
|
||||
|
|
|
@ -13,27 +13,27 @@ use solana_sdk::pubkey::Pubkey;
|
|||
#[derive(Clone)]
|
||||
pub struct RpcClient {
|
||||
pub client: reqwest::Client,
|
||||
pub addr: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
impl RpcClient {
|
||||
pub fn new(addr: String) -> Self {
|
||||
pub fn new(url: String) -> Self {
|
||||
RpcClient {
|
||||
client: reqwest::Client::new(),
|
||||
addr,
|
||||
url,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new_with_timeout(addr: SocketAddr, timeout: Duration) -> Self {
|
||||
let addr = get_rpc_request_str(addr, false);
|
||||
pub fn new_socket_with_timeout(addr: SocketAddr, timeout: Duration) -> Self {
|
||||
let url = get_rpc_request_str(addr, false);
|
||||
let client = reqwest::Client::builder()
|
||||
.timeout(timeout)
|
||||
.build()
|
||||
.expect("build rpc client");
|
||||
RpcClient { client, addr }
|
||||
RpcClient { client, url }
|
||||
}
|
||||
|
||||
pub fn new_from_socket(addr: SocketAddr) -> Self {
|
||||
pub fn new_socket(addr: SocketAddr) -> Self {
|
||||
Self::new(get_rpc_request_str(addr, false))
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ impl RpcClient {
|
|||
loop {
|
||||
match self
|
||||
.client
|
||||
.post(&self.addr)
|
||||
.post(&self.url)
|
||||
.header(CONTENT_TYPE, "application/json")
|
||||
.body(request_json.to_string())
|
||||
.send()
|
||||
|
@ -269,7 +269,7 @@ mod tests {
|
|||
});
|
||||
|
||||
let rpc_addr = receiver.recv().unwrap();
|
||||
let rpc_client = RpcClient::new_from_socket(rpc_addr);
|
||||
let rpc_client = RpcClient::new_socket(rpc_addr);
|
||||
|
||||
let balance = rpc_client.make_rpc_request(
|
||||
1,
|
||||
|
@ -318,7 +318,7 @@ mod tests {
|
|||
});
|
||||
|
||||
let rpc_addr = receiver.recv().unwrap();
|
||||
let rpc_client = RpcClient::new_from_socket(rpc_addr);
|
||||
let rpc_client = RpcClient::new_socket(rpc_addr);
|
||||
|
||||
let balance = rpc_client.retry_make_rpc_request(
|
||||
1,
|
||||
|
|
|
@ -45,17 +45,17 @@ impl ThinClient {
|
|||
rpc_addr,
|
||||
transactions_addr,
|
||||
transactions_socket,
|
||||
RpcClient::new_from_socket(rpc_addr),
|
||||
RpcClient::new_socket(rpc_addr),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn new_with_timeout(
|
||||
pub fn new_socket_with_timeout(
|
||||
rpc_addr: SocketAddr,
|
||||
transactions_addr: SocketAddr,
|
||||
transactions_socket: UdpSocket,
|
||||
timeout: Duration,
|
||||
) -> Self {
|
||||
let rpc_client = RpcClient::new_with_timeout(rpc_addr, timeout);
|
||||
let rpc_client = RpcClient::new_socket_with_timeout(rpc_addr, timeout);
|
||||
Self::new_from_client(rpc_addr, transactions_addr, transactions_socket, rpc_client)
|
||||
}
|
||||
|
||||
|
|
|
@ -354,7 +354,7 @@ impl Replicator {
|
|||
let rpc_peers = cluster_info.rpc_peers();
|
||||
debug!("rpc peers: {:?}", rpc_peers);
|
||||
let node_idx = thread_rng().gen_range(0, rpc_peers.len());
|
||||
RpcClient::new_from_socket(rpc_peers[node_idx].rpc)
|
||||
RpcClient::new_socket(rpc_peers[node_idx].rpc)
|
||||
};
|
||||
let storage_blockhash = rpc_client
|
||||
.make_rpc_request(2, RpcRequest::GetStorageBlockhash, None)
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct RemoteVoteSigner {
|
|||
|
||||
impl RemoteVoteSigner {
|
||||
pub fn new(signer: SocketAddr) -> Self {
|
||||
let rpc_client = RpcClient::new_from_socket(signer);
|
||||
let rpc_client = RpcClient::new_socket(signer);
|
||||
Self { rpc_client }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -140,7 +140,7 @@ fn test_transaction_count() {
|
|||
let addr = "0.0.0.0:1234".parse().unwrap();
|
||||
let transactions_socket = UdpSocket::bind("0.0.0.0:0").unwrap();
|
||||
let mut client =
|
||||
ThinClient::new_with_timeout(addr, addr, transactions_socket, Duration::from_secs(2));
|
||||
ThinClient::new_socket_with_timeout(addr, addr, transactions_socket, Duration::from_secs(2));
|
||||
assert_eq!(client.transaction_count(), 0);
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ fn test_wallet_deploy_program() {
|
|||
run_local_drone(alice, sender);
|
||||
let drone_addr = receiver.recv().unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let mut config = WalletConfig::default();
|
||||
config.drone_port = drone_addr.port();
|
||||
|
|
|
@ -27,7 +27,7 @@ fn test_wallet_timestamp_tx() {
|
|||
run_local_drone(alice, sender);
|
||||
let drone_addr = receiver.recv().unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let mut config_payer = WalletConfig::default();
|
||||
config_payer.drone_port = drone_addr.port();
|
||||
|
@ -87,7 +87,7 @@ fn test_wallet_witness_tx() {
|
|||
run_local_drone(alice, sender);
|
||||
let drone_addr = receiver.recv().unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let mut config_payer = WalletConfig::default();
|
||||
config_payer.drone_port = drone_addr.port();
|
||||
|
@ -144,7 +144,7 @@ fn test_wallet_cancel_tx() {
|
|||
run_local_drone(alice, sender);
|
||||
let drone_addr = receiver.recv().unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let mut config_payer = WalletConfig::default();
|
||||
config_payer.drone_port = drone_addr.port();
|
||||
|
|
|
@ -21,7 +21,7 @@ fn test_wallet_request_airdrop() {
|
|||
let sig_response = process_command(&bob_config);
|
||||
sig_response.unwrap();
|
||||
|
||||
let rpc_client = RpcClient::new_from_socket(leader_data.rpc);
|
||||
let rpc_client = RpcClient::new_socket(leader_data.rpc);
|
||||
|
||||
let balance = rpc_client
|
||||
.retry_get_balance(1, &bob_config.id.pubkey(), 1)
|
||||
|
|
Loading…
Reference in New Issue