add-rpc_client.get_account (#4218)
This commit is contained in:
@ -222,31 +222,7 @@ impl RpcClient {
|
|||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_account_data(&self, pubkey: &Pubkey) -> io::Result<Vec<u8>> {
|
pub fn get_account(&self, pubkey: &Pubkey) -> io::Result<Account> {
|
||||||
let params = json!([format!("{}", pubkey)]);
|
|
||||||
let response = self
|
|
||||||
.client
|
|
||||||
.send(&RpcRequest::GetAccountInfo, Some(params), 0);
|
|
||||||
match response {
|
|
||||||
Ok(account_json) => {
|
|
||||||
let account: Account =
|
|
||||||
serde_json::from_value(account_json).expect("deserialize account");
|
|
||||||
Ok(account.data)
|
|
||||||
}
|
|
||||||
Err(error) => {
|
|
||||||
debug!("get_account_data failed: {:?}", error);
|
|
||||||
Err(io::Error::new(
|
|
||||||
io::ErrorKind::Other,
|
|
||||||
"get_account_data failed",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Request the balance of the user holding `pubkey`. This method blocks
|
|
||||||
/// until the server sends a response. If the response packet is dropped
|
|
||||||
/// by the network, this method will hang indefinitely.
|
|
||||||
pub fn get_balance(&self, pubkey: &Pubkey) -> io::Result<u64> {
|
|
||||||
let params = json!([format!("{}", pubkey)]);
|
let params = json!([format!("{}", pubkey)]);
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
@ -257,8 +233,7 @@ impl RpcClient {
|
|||||||
let account: Account =
|
let account: Account =
|
||||||
serde_json::from_value(account_json).expect("deserialize account");
|
serde_json::from_value(account_json).expect("deserialize account");
|
||||||
trace!("Response account {:?} {:?}", pubkey, account);
|
trace!("Response account {:?} {:?}", pubkey, account);
|
||||||
trace!("get_balance {:?}", account.lamports);
|
Ok(account)
|
||||||
Ok(account.lamports)
|
|
||||||
})
|
})
|
||||||
.map_err(|error| {
|
.map_err(|error| {
|
||||||
debug!("Response account {}: None (error: {:?})", pubkey, error);
|
debug!("Response account {}: None (error: {:?})", pubkey, error);
|
||||||
@ -266,6 +241,17 @@ impl RpcClient {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_account_data(&self, pubkey: &Pubkey) -> io::Result<Vec<u8>> {
|
||||||
|
self.get_account(pubkey).map(|account| account.data)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Request the balance of the user holding `pubkey`. This method blocks
|
||||||
|
/// until the server sends a response. If the response packet is dropped
|
||||||
|
/// by the network, this method will hang indefinitely.
|
||||||
|
pub fn get_balance(&self, pubkey: &Pubkey) -> io::Result<u64> {
|
||||||
|
self.get_account(pubkey).map(|account| account.lamports)
|
||||||
|
}
|
||||||
|
|
||||||
/// Request the transaction count. If the response packet is dropped by the network,
|
/// Request the transaction count. If the response packet is dropped by the network,
|
||||||
/// this method will try again 5 times.
|
/// this method will try again 5 times.
|
||||||
pub fn get_transaction_count(&self) -> io::Result<u64> {
|
pub fn get_transaction_count(&self) -> io::Result<u64> {
|
||||||
|
Reference in New Issue
Block a user