@@ -14,7 +14,11 @@ use solana_program::account_info::{
1414} ;
1515use solana_program:: pubkey:: Pubkey ;
1616
17- use state:: load_price_account;
17+ use state:: {
18+ load_price_account,
19+ GenericPriceAccount ,
20+ SolanaPriceAccount ,
21+ } ;
1822
1923pub use pyth_sdk:: {
2024 Price ,
@@ -27,24 +31,43 @@ pub use pyth_sdk::{
2731pub const VALID_SLOT_PERIOD : u64 = 25 ;
2832
2933/// Loads Pyth Feed Price from Price Account Info.
34+ #[ deprecated( note = "solana-specific, use SolanaPriceAccount::from_account_info instead." ) ]
3035pub fn load_price_feed_from_account_info (
3136 price_account_info : & AccountInfo ,
3237) -> Result < PriceFeed , PythError > {
33- let data = price_account_info
34- . try_borrow_data ( )
35- . map_err ( |_| PythError :: InvalidAccountData ) ?;
36- let price_account = load_price_account ( * data) ?;
37-
38- Ok ( price_account. to_price_feed ( price_account_info. key ) )
38+ SolanaPriceAccount :: account_info_to_feed ( price_account_info)
3939}
4040
4141/// Loads Pyth Price Feed from Account when using Solana Client.
4242///
4343/// It is a helper function which constructs Account Info when reading Account in clients.
44+ #[ deprecated( note = "solana-specific, use SolanaPriceAccount::from_account instead." ) ]
4445pub fn load_price_feed_from_account (
4546 price_key : & Pubkey ,
4647 price_account : & mut impl Account ,
4748) -> Result < PriceFeed , PythError > {
48- let price_account_info = ( price_key, price_account) . into_account_info ( ) ;
49- load_price_feed_from_account_info ( & price_account_info)
49+ SolanaPriceAccount :: account_to_feed ( price_key, price_account)
50+ }
51+
52+ impl < const N : usize , T : ' static > GenericPriceAccount < N , T >
53+ where
54+ T : Default ,
55+ T : Copy ,
56+ {
57+ pub fn account_info_to_feed ( price_account_info : & AccountInfo ) -> Result < PriceFeed , PythError > {
58+ load_price_account :: < N , T > (
59+ * price_account_info
60+ . try_borrow_data ( )
61+ . map_err ( |_| PythError :: InvalidAccountData ) ?,
62+ )
63+ . map ( |acc| acc. to_price_feed ( price_account_info. key ) )
64+ }
65+
66+ pub fn account_to_feed (
67+ price_key : & Pubkey ,
68+ price_account : & mut impl Account ,
69+ ) -> Result < PriceFeed , PythError > {
70+ let price_account_info = ( price_key, price_account) . into_account_info ( ) ;
71+ Self :: account_info_to_feed ( & price_account_info)
72+ }
5073}
0 commit comments