@@ -274,6 +274,40 @@ impl RpcClient {
274274 self . get_account ( pubkey) . map ( |account| account. lamports )
275275 }
276276
277+ pub fn get_program_accounts ( & self , pubkey : & Pubkey ) -> io:: Result < Vec < ( Pubkey , Account ) > > {
278+ let params = json ! ( [ format!( "{}" , pubkey) ] ) ;
279+ let response = self
280+ . client
281+ . send ( & RpcRequest :: GetProgramAccounts , Some ( params) , 0 )
282+ . map_err ( |err| {
283+ io:: Error :: new (
284+ io:: ErrorKind :: Other ,
285+ format ! ( "AccountNotFound: pubkey={}: {}" , pubkey, err) ,
286+ )
287+ } ) ?;
288+
289+ let accounts: Vec < ( String , Account ) > =
290+ serde_json:: from_value :: < Vec < ( String , Account ) > > ( response) . map_err ( |err| {
291+ io:: Error :: new (
292+ io:: ErrorKind :: Other ,
293+ format ! ( "GetProgramAccounts parse failure: {:?}" , err) ,
294+ )
295+ } ) ?;
296+ println ! ( "{:?}" , accounts) ;
297+
298+ let mut pubkey_accounts: Vec < ( Pubkey , Account ) > = Vec :: new ( ) ;
299+ for ( string, account) in accounts. into_iter ( ) {
300+ let pubkey = string. parse ( ) . map_err ( |err| {
301+ io:: Error :: new (
302+ io:: ErrorKind :: Other ,
303+ format ! ( "GetProgramAccounts parse failure: {:?}" , err) ,
304+ )
305+ } ) ?;
306+ pubkey_accounts. push ( ( pubkey, account) ) ;
307+ }
308+ Ok ( pubkey_accounts)
309+ }
310+
277311 /// Request the transaction count. If the response packet is dropped by the network,
278312 /// this method will try again 5 times.
279313 pub fn get_transaction_count ( & self ) -> io:: Result < u64 > {
0 commit comments