1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
pub use self::error::PythError;
mod error;
pub mod state;
use solana_program::account_info::{
Account,
AccountInfo,
IntoAccountInfo,
};
use solana_program::pubkey::Pubkey;
use state::load_price_account;
pub use pyth_sdk::{
Price,
PriceFeed,
PriceIdentifier,
ProductIdentifier,
};
pub const VALID_SLOT_PERIOD: u64 = 25;
pub fn load_price_feed_from_account_info(
price_account_info: &AccountInfo,
) -> Result<PriceFeed, PythError> {
let data = price_account_info
.try_borrow_data()
.map_err(|_| PythError::InvalidAccountData)?;
let price_account = load_price_account(*data)?;
Ok(price_account.to_price_feed(price_account_info.key))
}
pub fn load_price_feed_from_account(
price_key: &Pubkey,
price_account: &mut impl Account,
) -> Result<PriceFeed, PythError> {
let price_account_info = (price_key, price_account).into_account_info();
load_price_feed_from_account_info(&price_account_info)
}