Skip to content

Commit 0225ed4

Browse files
authored
Merge pull request #69 from pyth-network/solana-pubkey
Replace pyth_sdk_solana::AccKey with solana_program::pubkey::Pubkey
2 parents 248b2f7 + 3db056d commit 0225ed4

File tree

4 files changed

+16
-60
lines changed

4 files changed

+16
-60
lines changed

pyth-sdk-solana/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-sdk-solana"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"

pyth-sdk-solana/examples/get_accounts.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ fn main() {
5151

5252
// iget and print each Product in Mapping directory
5353
let mut i = 0;
54-
for prod_akey in &map_acct.products {
55-
let prod_pkey = Pubkey::new(&prod_akey.val);
54+
for prod_pkey in &map_acct.products {
5655
let prod_data = clnt.get_account_data(&prod_pkey).unwrap();
5756
let prod_acct = load_product_account(&prod_data).unwrap();
5857

@@ -65,8 +64,8 @@ fn main() {
6564
}
6665

6766
// print all Prices that correspond to this Product
68-
if prod_acct.px_acc.is_valid() {
69-
let mut px_pkey = Pubkey::new(&prod_acct.px_acc.val);
67+
if prod_acct.px_acc != Pubkey::default() {
68+
let mut px_pkey = prod_acct.px_acc;
7069
loop {
7170
let price_data = clnt.get_account_data(&px_pkey).unwrap();
7271
let price_account = load_price_account(&price_data).unwrap();
@@ -120,8 +119,8 @@ fn main() {
120119
}
121120

122121
// go to next price account in list
123-
if price_account.next.is_valid() {
124-
px_pkey = Pubkey::new(&price_account.next.val);
122+
if price_account.next != Pubkey::default() {
123+
px_pkey = price_account.next;
125124
} else {
126125
break;
127126
}
@@ -135,9 +134,9 @@ fn main() {
135134
}
136135

137136
// go to next Mapping account in list
138-
if !map_acct.next.is_valid() {
137+
if map_acct.next == Pubkey::default() {
139138
break;
140139
}
141-
akey = Pubkey::new(&map_acct.next.val);
140+
akey = map_acct.next;
142141
}
143142
}

pyth-sdk-solana/src/state.rs

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,6 @@ impl Default for PriceType {
115115
}
116116
}
117117

118-
/// Public key of a Solana account
119-
#[derive(
120-
Copy,
121-
Clone,
122-
Debug,
123-
Default,
124-
PartialEq,
125-
Eq,
126-
Hash,
127-
Ord,
128-
PartialOrd,
129-
BorshSerialize,
130-
BorshDeserialize,
131-
serde::Serialize,
132-
serde::Deserialize,
133-
)]
134-
#[repr(C)]
135-
pub struct AccKey {
136-
pub val: [u8; 32],
137-
}
138-
139118
/// Mapping accounts form a linked-list containing the listing of all products on Pyth.
140119
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
141120
#[repr(C)]
@@ -152,8 +131,8 @@ pub struct MappingAccount {
152131
pub num: u32,
153132
pub unused: u32,
154133
/// next mapping account (if any)
155-
pub next: AccKey,
156-
pub products: [AccKey; MAP_TABLE_SIZE],
134+
pub next: Pubkey,
135+
pub products: [Pubkey; MAP_TABLE_SIZE],
157136
}
158137

159138
#[cfg(target_endian = "little")]
@@ -179,7 +158,7 @@ pub struct ProductAccount {
179158
/// price account size
180159
pub size: u32,
181160
/// first price account in list
182-
pub px_acc: AccKey,
161+
pub px_acc: Pubkey,
183162
/// key/value pairs of reference attr.
184163
pub attr: [u8; PROD_ATTR_SIZE],
185164
}
@@ -247,7 +226,7 @@ pub struct PriceInfo {
247226
#[repr(C)]
248227
pub struct PriceComp {
249228
/// key of contributing publisher
250-
pub publisher: AccKey,
229+
pub publisher: Pubkey,
251230
/// the price used to compute the current aggregate price
252231
pub agg: PriceInfo,
253232
/// The publisher's latest price. This price will be incorporated into the aggregate price
@@ -317,9 +296,9 @@ pub struct PriceAccount {
317296
/// space for future derived values
318297
pub drv4: u32,
319298
/// product account key
320-
pub prod: AccKey,
299+
pub prod: Pubkey,
321300
/// next Price account in linked list
322-
pub next: AccKey,
301+
pub next: Pubkey,
323302
/// valid slot of previous update
324303
pub prev_slot: u64,
325304
/// aggregate price of previous update with TRADING status
@@ -367,7 +346,7 @@ impl PriceAccount {
367346
self.expo,
368347
self.num,
369348
self.num_qt,
370-
ProductIdentifier::new(self.prod.val),
349+
ProductIdentifier::new(self.prod.to_bytes()),
371350
self.agg.price,
372351
self.agg.conf,
373352
self.ema_price.val,
@@ -379,28 +358,6 @@ impl PriceAccount {
379358
}
380359
}
381360

382-
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
383-
struct AccKeyU64 {
384-
pub val: [u64; 4],
385-
}
386-
387-
#[cfg(target_endian = "little")]
388-
unsafe impl Zeroable for AccKeyU64 {
389-
}
390-
391-
#[cfg(target_endian = "little")]
392-
unsafe impl Pod for AccKeyU64 {
393-
}
394-
395-
impl AccKey {
396-
pub fn is_valid(&self) -> bool {
397-
match load::<AccKeyU64>(&self.val) {
398-
Ok(k8) => k8.val[0] != 0 || k8.val[1] != 0 || k8.val[2] != 0 || k8.val[3] != 0,
399-
Err(_) => false,
400-
}
401-
}
402-
}
403-
404361
fn load<T: Pod>(data: &[u8]) -> Result<&T, PodCastError> {
405362
let size = size_of::<T>();
406363
if data.len() >= size {

pyth-sdk-solana/test-contract/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test-bpf = []
88
no-entrypoint = []
99

1010
[dependencies]
11-
pyth-sdk-solana = { path = "../", version = "0.5.0" }
11+
pyth-sdk-solana = { path = "../", version = "0.6.0" }
1212
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
1313
bytemuck = "1.7.2"
1414
borsh = "0.9"

0 commit comments

Comments
 (0)