diff --git a/client/src/rpc_client.rs b/client/src/rpc_client.rs index 5899338beb..4d7d4b55f7 100644 --- a/client/src/rpc_client.rs +++ b/client/src/rpc_client.rs @@ -222,31 +222,7 @@ impl RpcClient { Ok(res) } - pub fn get_account_data(&self, pubkey: &Pubkey) -> io::Result> { - 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 { + pub fn get_account(&self, pubkey: &Pubkey) -> io::Result { let params = json!([format!("{}", pubkey)]); let response = self .client @@ -257,8 +233,7 @@ impl RpcClient { let account: Account = serde_json::from_value(account_json).expect("deserialize account"); trace!("Response account {:?} {:?}", pubkey, account); - trace!("get_balance {:?}", account.lamports); - Ok(account.lamports) + Ok(account) }) .map_err(|error| { debug!("Response account {}: None (error: {:?})", pubkey, error); @@ -266,6 +241,17 @@ impl RpcClient { }) } + pub fn get_account_data(&self, pubkey: &Pubkey) -> io::Result> { + 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 { + self.get_account(pubkey).map(|account| account.lamports) + } + /// Request the transaction count. If the response packet is dropped by the network, /// this method will try again 5 times. pub fn get_transaction_count(&self) -> io::Result {