From 6a5f6755ea1ae71d65aab3c80d69b29cdc5b4cdb Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 31 Aug 2022 18:05:29 +0000 Subject: [PATCH 1/4] Replace pyth_sdk_solana::AccKey with solana_program::pubkey::Pubkey --- pyth-sdk-solana/src/state.rs | 44 ++++++------------------------------ 1 file changed, 7 insertions(+), 37 deletions(-) diff --git a/pyth-sdk-solana/src/state.rs b/pyth-sdk-solana/src/state.rs index 2dba6ef..3aedd1e 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, @@ -392,15 +371,6 @@ unsafe impl Zeroable for AccKeyU64 { 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 { From 3fb69e9567cb9d0aaf1a7f5aea9fa707f32fd97f Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 31 Aug 2022 18:06:16 +0000 Subject: [PATCH 2/4] Remove unused AccKeyU64 type --- pyth-sdk-solana/src/state.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/pyth-sdk-solana/src/state.rs b/pyth-sdk-solana/src/state.rs index 3aedd1e..1cfcf5b 100644 --- a/pyth-sdk-solana/src/state.rs +++ b/pyth-sdk-solana/src/state.rs @@ -358,19 +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 { -} - fn load(data: &[u8]) -> Result<&T, PodCastError> { let size = size_of::(); if data.len() >= size { From 98f00b62d88ea69f053caa29631878ffcbea2d3c Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 31 Aug 2022 18:06:40 +0000 Subject: [PATCH 3/4] Update example --- pyth-sdk-solana/examples/get_accounts.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) 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; } } From 3db056d5d7951db64fbd96faf6d1e21950ae623a Mon Sep 17 00:00:00 2001 From: Tom Pointon Date: Wed, 31 Aug 2022 18:07:42 +0000 Subject: [PATCH 4/4] Bump pyth-sdk-solana to major version --- pyth-sdk-solana/Cargo.toml | 2 +- pyth-sdk-solana/test-contract/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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"