Skip to content

Commit 76e982d

Browse files
authored
Export upd_aggregate (#249)
* Export upd_aggregate * Comment * Cleanup * Better comment * Get the right gcc Co-authored-by: Guillermo Bescos <guibescos>
1 parent 651e3bb commit 76e982d

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

program/c/makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
OUT_DIR := ./target
22
SOLANA := ../../../solana
33
include $(SOLANA)/sdk/bpf/c/bpf.mk
4+
45
cpyth:
6+
# Bundle C code compiled to bpf for use by rust
57
bash -c "ar rcs target/libcpyth.a target/**/*.o"
8+
cpythtest:
9+
# Compile C code to system architecture for use by rust's cargo test
10+
$(CC) -c ./src/oracle/for_cargo_test/cpyth_test.c -o ./target/cpyth_test.o
11+
# Bundle C code compiled to system architecture for use by rust's cargo test
12+
ar rcs target/libcpythtest.a ./target/cpyth_test.o
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// The goal of this file is to provide the upd_aggregate function to local rust tests
2+
3+
/// We need to allocate some heap space for upd_aggregate
4+
/// When compiling for the solana runtime, the heap space is preallocated and PC_HEAP_START is provided by <solana.h>
5+
char heap_start[8192];
6+
#define PC_HEAP_START (heap_start)
7+
#define static_assert _Static_assert
8+
9+
typedef signed char int8_t;
10+
typedef unsigned char uint8_t;
11+
typedef signed short int16_t;
12+
typedef unsigned short uint16_t;
13+
typedef signed int int32_t;
14+
typedef unsigned int uint32_t;
15+
typedef signed long int int64_t;
16+
typedef unsigned long int uint64_t;
17+
18+
#include "../upd_aggregate.h"
19+
20+
extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
21+
return upd_aggregate(ptr, slot, timestamp );
22+
}

program/c/src/oracle/oracle.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,7 @@ extern uint64_t c_entrypoint(const uint8_t *input)
171171
}
172172
return dispatch( prm, ka );
173173
}
174+
175+
extern bool c_upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp ){
176+
return upd_aggregate(ptr, slot, timestamp );
177+
}

scripts/build-bpf.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ export V="${V:-1}"
3030
make clean
3131
make "${@:2}"
3232
make cpyth
33+
make cpythtest
3334
rm ./target/*-keypair.json
3435

3536

3637
#build Rust and link it with C
3738
cd "${PYTH_DIR}"
3839
cargo clean
39-
cargo test
40+
cargo test-bpf
4041
cargo clean
4142
cargo build-bpf
4243

0 commit comments

Comments
 (0)