@@ -38,3 +38,73 @@ impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>> for Config {
3838 Self :: deserialize ( & mut data)
3939 }
4040}
41+
42+ #[ cfg( feature = "fetch" ) ]
43+ pub fn fetch_config (
44+ rpc : & solana_client:: rpc_client:: RpcClient ,
45+ address : & Pubkey ,
46+ ) -> Result < crate :: shared:: DecodedAccount < Config > , std:: io:: Error > {
47+ let accounts = fetch_all_config ( rpc, & [ * address] ) ?;
48+ Ok ( accounts[ 0 ] . clone ( ) )
49+ }
50+
51+ #[ cfg( feature = "fetch" ) ]
52+ pub fn fetch_all_config (
53+ rpc : & solana_client:: rpc_client:: RpcClient ,
54+ addresses : & [ Pubkey ] ,
55+ ) -> Result < Vec < crate :: shared:: DecodedAccount < Config > > , std:: io:: Error > {
56+ let accounts = rpc
57+ . get_multiple_accounts ( & addresses)
58+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
59+ let mut decoded_accounts: Vec < crate :: shared:: DecodedAccount < Config > > = Vec :: new ( ) ;
60+ for i in 0 ..addresses. len ( ) {
61+ let address = addresses[ i] ;
62+ let account = accounts[ i] . as_ref ( ) . ok_or ( std:: io:: Error :: new (
63+ std:: io:: ErrorKind :: Other ,
64+ format ! ( "Account not found: {}" , address) ,
65+ ) ) ?;
66+ let data = Config :: from_bytes ( & account. data ) ?;
67+ decoded_accounts. push ( crate :: shared:: DecodedAccount {
68+ address,
69+ account : account. clone ( ) ,
70+ data,
71+ } ) ;
72+ }
73+ Ok ( decoded_accounts)
74+ }
75+
76+ #[ cfg( feature = "fetch" ) ]
77+ pub fn fetch_maybe_config (
78+ rpc : & solana_client:: rpc_client:: RpcClient ,
79+ address : & Pubkey ,
80+ ) -> Result < crate :: shared:: MaybeAccount < Config > , std:: io:: Error > {
81+ let accounts = fetch_all_maybe_config ( rpc, & [ * address] ) ?;
82+ Ok ( accounts[ 0 ] . clone ( ) )
83+ }
84+
85+ #[ cfg( feature = "fetch" ) ]
86+ pub fn fetch_all_maybe_config (
87+ rpc : & solana_client:: rpc_client:: RpcClient ,
88+ addresses : & [ Pubkey ] ,
89+ ) -> Result < Vec < crate :: shared:: MaybeAccount < Config > > , std:: io:: Error > {
90+ let accounts = rpc
91+ . get_multiple_accounts ( & addresses)
92+ . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e. to_string ( ) ) ) ?;
93+ let mut decoded_accounts: Vec < crate :: shared:: MaybeAccount < Config > > = Vec :: new ( ) ;
94+ for i in 0 ..addresses. len ( ) {
95+ let address = addresses[ i] ;
96+ if let Some ( account) = accounts[ i] . as_ref ( ) {
97+ let data = Config :: from_bytes ( & account. data ) ?;
98+ decoded_accounts. push ( crate :: shared:: MaybeAccount :: Exists (
99+ crate :: shared:: DecodedAccount {
100+ address,
101+ account : account. clone ( ) ,
102+ data,
103+ } ,
104+ ) ) ;
105+ } else {
106+ decoded_accounts. push ( crate :: shared:: MaybeAccount :: NotFound ( address) ) ;
107+ }
108+ }
109+ Ok ( decoded_accounts)
110+ }
0 commit comments