Skip to content

Commit 344f8a9

Browse files
authored
feat: add anchor to pythnet sdk (#1531)
* add anchor to pythnet sdk * bump * bump * bump * please work * Solve
1 parent b2cb7c8 commit 344f8a9

File tree

5 files changed

+115
-108
lines changed

5 files changed

+115
-108
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ repos:
8080
- id: cargo-fmt-pythnet-sdk
8181
name: Cargo format for pythnet SDK
8282
language: "rust"
83-
entry: cargo +nightly-2023-07-23 fmt --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --all -- --config-path rustfmt.toml
83+
entry: cargo +nightly-2024-03-26 fmt --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --all -- --config-path rustfmt.toml
8484
pass_filenames: false
8585
files: pythnet/pythnet_sdk
8686
- id: cargo-clippy-pythnet-sdk
8787
name: Cargo clippy for pythnet SDK
8888
language: "rust"
89-
entry: cargo +nightly-2023-07-23 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
89+
entry: cargo +nightly-2024-03-26 clippy --manifest-path ./pythnet/pythnet_sdk/Cargo.toml --tests --fix --allow-dirty --allow-staged -- -D warnings
9090
pass_filenames: false
9191
files: pythnet/pythnet_sdk
9292
# Hooks for solana receiver contract

pythnet/pythnet_sdk/Cargo.toml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pythnet-sdk"
3-
version = "2.0.0"
3+
version = "2.1.0"
44
description = "Pyth Runtime for Solana"
55
authors = ["Pyth Data Association"]
66
repository = "https://github.com/pyth-network/pythnet"
@@ -13,7 +13,7 @@ name = "pythnet_sdk"
1313

1414
[features]
1515
test-utils = ["dep:wormhole-vaas-serde", "dep:serde_wormhole", "dep:libsecp256k1", "dep:rand"]
16-
solana-program = ["dep:solana-program"]
16+
solana-program = ["dep:solana-program", "dep:anchor-lang", "dep:proc-macro2"]
1717

1818
[dependencies]
1919
bincode = "1.3.1"
@@ -33,13 +33,15 @@ wormhole-vaas-serde = {version = "0.1.0", optional = true}
3333
libsecp256k1 = {version ="0.7.1", optional = true}
3434
rand = {version = "0.8.5", optional = true}
3535
solana-program = {version = ">=1.13.6", optional = true}
36+
anchor-lang = {version = ">=0.28.0", optional = true}
37+
proc-macro2 = {version = "=1.0.79", optional = true} # pinned to 1.0.79 to compilation errors with newer versions, remove this if it compiles fine without
3638

3739
[dev-dependencies]
3840
base64 = "0.21.0"
3941
rand = "0.7.0"
4042
serde_json = "1.0.96"
41-
solana-client = "=1.13.6"
42-
solana-sdk = "=1.13.6"
43+
solana-client = ">=1.13.6"
44+
solana-sdk = ">=1.13.6"
4345
proptest = "1.1.0"
4446

4547
[package.metadata.docs.rs]

pythnet/pythnet_sdk/src/messages.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1+
#[cfg(feature = "solana-program")]
2+
use anchor_lang::{
3+
AnchorDeserialize,
4+
AnchorSerialize,
5+
};
6+
#[cfg(not(feature = "solana-program"))]
7+
use borsh::{
8+
BorshDeserialize,
9+
BorshSerialize,
10+
};
111
#[cfg(feature = "quickcheck")]
212
use quickcheck::Arbitrary;
313
use {
4-
borsh::{
5-
BorshDeserialize,
6-
BorshSchema,
7-
BorshSerialize,
8-
},
14+
borsh::BorshSchema,
915
serde::{
1016
Deserialize,
1117
Serialize,
@@ -40,6 +46,7 @@ use {
4046
Deserialize
4147
))
4248
)]
49+
4350
pub enum Message {
4451
PriceFeedMessage(PriceFeedMessage),
4552
TwapMessage(TwapMessage),
@@ -75,17 +82,13 @@ impl Arbitrary for Message {
7582
pub type FeedId = [u8; 32];
7683

7784
#[repr(C)]
78-
#[derive(
79-
Debug,
80-
Copy,
81-
Clone,
82-
PartialEq,
83-
Serialize,
84-
Deserialize,
85-
BorshDeserialize,
86-
BorshSerialize,
87-
BorshSchema,
85+
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, BorshSchema)]
86+
#[cfg_attr(feature = "solana-program", derive(AnchorSerialize, AnchorDeserialize))]
87+
#[cfg_attr(
88+
not(feature = "solana-program"),
89+
derive(BorshSerialize, BorshDeserialize)
8890
)]
91+
8992
pub struct PriceFeedMessage {
9093
pub feed_id: FeedId,
9194
pub price: i64,

0 commit comments

Comments
 (0)