Skip to content

Commit 19220fa

Browse files
authored
Made Price_t member offsets available to Rust (#203)
* added price_t member offsets to bindings.h * Fix inconsistent naming * Add aggregate offset Co-authored-by: Guillermo Bescos <guibescos>
1 parent 1428082 commit 19220fa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

program/rust/src/bindings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ typedef unsigned int uint32_t;
1111
typedef signed long int int64_t;
1212
typedef unsigned long int uint64_t;
1313

14-
#include "../../c/src/oracle/oracle.h"
14+
#include "../../c/src/oracle/oracle.h"
15+
#include "price_t_offsets.h"

program/rust/src/price_t_offsets.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//The constants below are used by the rust oracle to efficiently access members in price_t
2+
//price_t is a big struct, attemting to deserialize all of it directly in borsh causes stack
3+
//issues on Solana. It is also more efficient to only access the members we need
4+
#include "../../c/src/oracle/oracle.h"
5+
#include <stddef.h>
6+
const size_t PRICE_T_EXPO_OFFSET = offsetof(struct pc_price, expo_);
7+
const size_t PRICE_T_TIMESTAMP_OFFSET = offsetof(struct pc_price, timestamp_);
8+
const size_t PRICE_T_AGGREGATE_OFFSET = offsetof(struct pc_price, agg_);
9+
const size_t PRICE_T_AGGREGATE_CONF_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, conf_);
10+
const size_t PRICE_T_AGGREGATE_PRICE_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, price_);
11+
const size_t PRICE_T_AGGREGATE_STATUS_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, status_);
12+
const size_t PRICE_T_PREV_TIMESTAMP_OFFSET = offsetof(struct pc_price, prev_timestamp_);
13+
const size_t PRICE_T_PREV_CONF_OFFSET = offsetof(struct pc_price, prev_conf_);
14+
const size_t PRICE_T_PREV_AGGREGATE_OFFSET = offsetof(struct pc_price, prev_price_);

0 commit comments

Comments
 (0)