Clarify url vs addr
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user