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