diff --git a/pyth-sdk-solana/Cargo.toml b/pyth-sdk-solana/Cargo.toml index fb5070a..45115d3 100644 --- a/pyth-sdk-solana/Cargo.toml +++ b/pyth-sdk-solana/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyth-sdk-solana" -version = "0.5.0" +version = "0.6.0" authors = ["Pyth Data Foundation"] edition = "2018" license = "Apache-2.0" diff --git a/pyth-sdk-solana/examples/get_accounts.rs b/pyth-sdk-solana/examples/get_accounts.rs index 4fe7c80..7085e2a 100644 --- a/pyth-sdk-solana/examples/get_accounts.rs +++ b/pyth-sdk-solana/examples/get_accounts.rs @@ -51,8 +51,7 @@ fn main() { // iget and print each Product in Mapping directory let mut i = 0; - for prod_akey in &map_acct.products { - let prod_pkey = Pubkey::new(&prod_akey.val); + for prod_pkey in &map_acct.products { let prod_data = clnt.get_account_data(&prod_pkey).unwrap(); let prod_acct = load_product_account(&prod_data).unwrap(); @@ -65,8 +64,8 @@ fn main() { } // print all Prices that correspond to this Product - if prod_acct.px_acc.is_valid() { - let mut px_pkey = Pubkey::new(&prod_acct.px_acc.val); + if prod_acct.px_acc != Pubkey::default() { + let mut px_pkey = prod_acct.px_acc; loop { let price_data = clnt.get_account_data(&px_pkey).unwrap(); let price_account = load_price_account(&price_data).unwrap(); @@ -120,8 +119,8 @@ fn main() { } // go to next price account in list - if price_account.next.is_valid() { - px_pkey = Pubkey::new(&price_account.next.val); + if price_account.next != Pubkey::default() { + px_pkey = price_account.next; } else { break; } @@ -135,9 +134,9 @@ fn main() { } // go to next Mapping account in list - if !map_acct.next.is_valid() { + if map_acct.next == Pubkey::default() { break; } - akey = Pubkey::new(&map_acct.next.val); + akey = map_acct.next; } } diff --git a/pyth-sdk-solana/src/state.rs b/pyth-sdk-solana/src/state.rs index 2dba6ef..1cfcf5b 100644 --- a/pyth-sdk-solana/src/state.rs +++ b/pyth-sdk-solana/src/state.rs @@ -115,27 +115,6 @@ impl Default for PriceType { } } -/// Public key of a Solana account -#[derive( - Copy, - Clone, - Debug, - Default, - PartialEq, - Eq, - Hash, - Ord, - PartialOrd, - BorshSerialize, - BorshDeserialize, - serde::Serialize, - serde::Deserialize, -)] -#[repr(C)] -pub struct AccKey { - pub val: [u8; 32], -} - /// Mapping accounts form a linked-list containing the listing of all products on Pyth. #[derive(Copy, Clone, Debug, PartialEq, Eq)] #[repr(C)] @@ -152,8 +131,8 @@ pub struct MappingAccount { pub num: u32, pub unused: u32, /// next mapping account (if any) - pub next: AccKey, - pub products: [AccKey; MAP_TABLE_SIZE], + pub next: Pubkey, + pub products: [Pubkey; MAP_TABLE_SIZE], } #[cfg(target_endian = "little")] @@ -179,7 +158,7 @@ pub struct ProductAccount { /// price account size pub size: u32, /// first price account in list - pub px_acc: AccKey, + pub px_acc: Pubkey, /// key/value pairs of reference attr. pub attr: [u8; PROD_ATTR_SIZE], } @@ -247,7 +226,7 @@ pub struct PriceInfo { #[repr(C)] pub struct PriceComp { /// key of contributing publisher - pub publisher: AccKey, + pub publisher: Pubkey, /// the price used to compute the current aggregate price pub agg: PriceInfo, /// The publisher's latest price. This price will be incorporated into the aggregate price @@ -317,9 +296,9 @@ pub struct PriceAccount { /// space for future derived values pub drv4: u32, /// product account key - pub prod: AccKey, + pub prod: Pubkey, /// next Price account in linked list - pub next: AccKey, + pub next: Pubkey, /// valid slot of previous update pub prev_slot: u64, /// aggregate price of previous update with TRADING status @@ -367,7 +346,7 @@ impl PriceAccount { self.expo, self.num, self.num_qt, - ProductIdentifier::new(self.prod.val), + ProductIdentifier::new(self.prod.to_bytes()), self.agg.price, self.agg.conf, self.ema_price.val, @@ -379,28 +358,6 @@ impl PriceAccount { } } -#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -struct AccKeyU64 { - pub val: [u64; 4], -} - -#[cfg(target_endian = "little")] -unsafe impl Zeroable for AccKeyU64 { -} - -#[cfg(target_endian = "little")] -unsafe impl Pod for AccKeyU64 { -} - -impl AccKey { - pub fn is_valid(&self) -> bool { - match load::(&self.val) { - Ok(k8) => k8.val[0] != 0 || k8.val[1] != 0 || k8.val[2] != 0 || k8.val[3] != 0, - Err(_) => false, - } - } -} - fn load(data: &[u8]) -> Result<&T, PodCastError> { let size = size_of::(); if data.len() >= size { diff --git a/pyth-sdk-solana/test-contract/Cargo.toml b/pyth-sdk-solana/test-contract/Cargo.toml index bc792bf..7a1d3fd 100644 --- a/pyth-sdk-solana/test-contract/Cargo.toml +++ b/pyth-sdk-solana/test-contract/Cargo.toml @@ -8,7 +8,7 @@ test-bpf = [] no-entrypoint = [] [dependencies] -pyth-sdk-solana = { path = "../", version = "0.5.0" } +pyth-sdk-solana = { path = "../", version = "0.6.0" } solana-program = "1.8.1, < 1.11" # Currently latest Solana 1.11 crate can't build bpf: https://github.com/solana-labs/solana/issues/26188 bytemuck = "1.7.2" borsh = "0.9"