@@ -14,7 +14,11 @@ use solana_program::account_info::{
14
14
} ;
15
15
use solana_program:: pubkey:: Pubkey ;
16
16
17
- use state:: load_price_account;
17
+ use state:: {
18
+ load_price_account,
19
+ GenericPriceAccount ,
20
+ SolanaPriceAccount ,
21
+ } ;
18
22
19
23
pub use pyth_sdk:: {
20
24
Price ,
@@ -27,24 +31,43 @@ pub use pyth_sdk::{
27
31
pub const VALID_SLOT_PERIOD : u64 = 25 ;
28
32
29
33
/// Loads Pyth Feed Price from Price Account Info.
34
+ #[ deprecated( note = "solana-specific, use SolanaPriceAccount::from_account_info instead." ) ]
30
35
pub fn load_price_feed_from_account_info (
31
36
price_account_info : & AccountInfo ,
32
37
) -> 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)
39
39
}
40
40
41
41
/// Loads Pyth Price Feed from Account when using Solana Client.
42
42
///
43
43
/// It is a helper function which constructs Account Info when reading Account in clients.
44
+ #[ deprecated( note = "solana-specific, use SolanaPriceAccount::from_account instead." ) ]
44
45
pub fn load_price_feed_from_account (
45
46
price_key : & Pubkey ,
46
47
price_account : & mut impl Account ,
47
48
) -> 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
+ }
50
73
}
0 commit comments