Skip to content
This repository was archived by the owner on Jun 30, 2022. It is now read-only.

Commit 11b39b9

Browse files
authored
Add debug, eq, .. traits to public structs (#21)
* Add debug, eq, .. traits to public apis * Add serde and borsh to fields that can take it freely + add good traits to price_conf * Release 0.5.0
1 parent ea3d18c commit 11b39b9

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-client"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
authors = ["Pyth Data Foundation"]
55
edition = "2018"
66
license = "Apache-2.0"
@@ -22,6 +22,7 @@ bytemuck = "1.7.2"
2222
num-derive = "0.3"
2323
num-traits = "0.2"
2424
thiserror = "1.0"
25+
serde = { version = "1.0.136", features = ["derive"] }
2526

2627
[dev-dependencies]
2728
solana-program-test = "1.8.1"

src/lib.rs

+36-12
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub const PROD_ATTR_SIZE : usize = PROD_ACCT_SIZE - PROD_HDR_SIZE;
3434
pub const MAX_SLOT_DIFFERENCE : u64 = 25;
3535

3636
/// The type of Pyth account determines what data it contains
37-
#[derive(Copy, Clone)]
37+
#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
3838
#[repr(C)]
3939
pub enum AccountType
4040
{
@@ -44,8 +44,14 @@ pub enum AccountType
4444
Price
4545
}
4646

47+
impl Default for AccountType {
48+
fn default() -> Self {
49+
AccountType::Unknown
50+
}
51+
}
52+
4753
/// The current status of a price feed.
48-
#[derive(Copy, Clone, PartialEq, BorshSerialize, BorshDeserialize, Debug)]
54+
#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
4955
#[repr(C)]
5056
pub enum PriceStatus
5157
{
@@ -59,34 +65,52 @@ pub enum PriceStatus
5965
Auction
6066
}
6167

68+
impl Default for PriceStatus {
69+
fn default() -> Self {
70+
PriceStatus::Unknown
71+
}
72+
}
73+
6274
/// Status of any ongoing corporate actions.
6375
/// (still undergoing dev)
64-
#[derive(Copy, Clone, PartialEq)]
76+
#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
6577
#[repr(C)]
6678
pub enum CorpAction
6779
{
6880
NoCorpAct
6981
}
7082

83+
impl Default for CorpAction {
84+
fn default() -> Self {
85+
CorpAction::NoCorpAct
86+
}
87+
}
88+
7189
/// The type of prices associated with a product -- each product may have multiple price feeds of different types.
72-
#[derive(Copy, Clone, PartialEq)]
90+
#[derive(Copy, Clone, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
7391
#[repr(C)]
7492
pub enum PriceType
7593
{
7694
Unknown,
7795
Price
7896
}
7997

98+
impl Default for PriceType {
99+
fn default() -> Self {
100+
PriceType::Unknown
101+
}
102+
}
103+
80104
/// Public key of a Solana account
81-
#[derive(Copy, Clone)]
105+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
82106
#[repr(C)]
83107
pub struct AccKey
84108
{
85109
pub val: [u8;32]
86110
}
87111

88112
/// Mapping accounts form a linked-list containing the listing of all products on Pyth.
89-
#[derive(Copy, Clone)]
113+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
90114
#[repr(C)]
91115
pub struct Mapping
92116
{
@@ -115,7 +139,7 @@ unsafe impl Pod for Mapping {}
115139

116140
/// Product accounts contain metadata for a single product, such as its symbol ("Crypto.BTC/USD")
117141
/// and its base/quote currencies.
118-
#[derive(Copy, Clone)]
142+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
119143
#[repr(C)]
120144
pub struct Product
121145
{
@@ -147,7 +171,7 @@ unsafe impl Pod for Product {}
147171

148172
/// A price and confidence at a specific slot. This struct can represent either a
149173
/// publisher's contribution or the outcome of price aggregation.
150-
#[derive(Copy, Clone)]
174+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
151175
#[repr(C)]
152176
pub struct PriceInfo
153177
{
@@ -167,7 +191,7 @@ pub struct PriceInfo
167191
}
168192

169193
/// The price and confidence contributed by a specific publisher.
170-
#[derive(Copy, Clone)]
194+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
171195
#[repr(C)]
172196
pub struct PriceComp
173197
{
@@ -182,7 +206,7 @@ pub struct PriceComp
182206
}
183207

184208
/// An exponentially-weighted moving average.
185-
#[derive(Copy, Clone)]
209+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
186210
#[repr(C)]
187211
pub struct Ema
188212
{
@@ -195,7 +219,7 @@ pub struct Ema
195219
}
196220

197221
/// Price accounts represent a continuously-updating price feed for a product.
198-
#[derive(Copy, Clone)]
222+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
199223
#[repr(C)]
200224
pub struct Price
201225
{
@@ -332,7 +356,7 @@ impl Price {
332356
}
333357
}
334358

335-
#[derive(Copy, Clone)]
359+
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
336360
struct AccKeyU64
337361
{
338362
pub val: [u64;4]

src/price_conf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const MAX_PD_V_U64: u64 = (1 << 28) - 1;
2727
* small that the price does not fit into an i64). Users of these methods should (1) select
2828
* their exponents to avoid this problem, and (2) handle the `None` case gracefully.
2929
*/
30-
#[derive(PartialEq, Debug, BorshSerialize, BorshDeserialize, Clone)]
30+
#[derive(Clone, Copy, Default, Debug, PartialEq, Eq, BorshSerialize, BorshDeserialize, serde::Serialize, serde::Deserialize)]
3131
pub struct PriceConf {
3232
pub price: i64,
3333
pub conf: u64,

0 commit comments

Comments
 (0)