Skip to content

Commit 47ca181

Browse files
authored
Pythd JRPC Websocket Server (#2)
* Add publisher and pythd modules * Add pythd JRPC API data structures * Add pythd adapter module and message formats * Add pythd JRPC API server implementation * Add tests for pythd JRPC API server * Bump Rust version * Bump pyth-sdk version * Fix imports * Install pkg-config * Add openssl dependency * Remove unused dependencies * Abort test server task in descructor * Rename PubKey to Pubkey, for consistency with Solana SDK
1 parent 6596ad4 commit 47ca181

File tree

7 files changed

+1190
-1
lines changed

7 files changed

+1190
-1
lines changed

Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,39 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7+
anyhow = "1.0.55"
8+
serde = { version = "1.0.136", features = ["derive"] }
9+
async-trait = "0.1.52"
10+
warp = { version = "0.3.1", features = ["websocket"] }
11+
tokio = { version = "1.0", features = ["full"] }
12+
tokio-stream = "0.1.1"
13+
futures-util = { version = "0.3", default-features = false, features = [
14+
"sink",
15+
] }
16+
jrpc = "0.4.1"
17+
serde_json = "1.0.79"
18+
tracing = "0.1.31"
19+
chrono = "0.4.19"
20+
parking_lot = "0.12.1"
21+
pyth-sdk = "0.6.0"
22+
pyth-sdk-solana = "0.6.0"
23+
solana-client = "1.10.24"
24+
solana-sdk = "1.10.24"
25+
bincode = "1.3.3"
26+
slog = "2.7.0"
27+
schnorrkel = "0.10.1"
28+
slog-term = "2.9.0"
29+
rand = "0.8.5"
30+
slog-async = "2.7.0"
31+
config = "0.13.2"
32+
thiserror = "1.0.32"
33+
34+
[dev-dependencies]
35+
tokio-util = { version = "0.7.0", features = ["full"] }
36+
soketto = "0.7.1"
37+
mockall = "0.11.0"
38+
portpicker = "0.1.1"
39+
rand = "0.8.5"
40+
tokio-retry = "0.3.0"
41+
slog-extlog = "8.0.0"
42+
iobuffer = "0.2.0"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.58.1-slim-bullseye
1+
FROM rust:1.61.0-slim-bullseye
22

33
ADD . /agent
44
WORKDIR /agent

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#[macro_use]
2+
extern crate slog;
3+
extern crate slog_term;
4+
5+
pub mod publisher;

src/publisher.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod pythd;

src/publisher/pythd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod adapter;
2+
pub mod api;

src/publisher/pythd/adapter.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::api::{
2+
Conf, NotifyPrice, NotifyPriceSched, Price, ProductAccount, ProductAccountMetadata, Pubkey,
3+
SubscriptionID,
4+
};
5+
use anyhow::Result;
6+
use tokio::sync::{mpsc, oneshot};
7+
8+
// Adapter is the adapter between the pythd websocket API, and the stores.
9+
// It is responsible for implementing the business logic for responding to
10+
// the pythd websocket API calls.
11+
#[derive(Debug)]
12+
pub enum Message {
13+
GetProductList {
14+
result_tx: oneshot::Sender<Result<Vec<ProductAccountMetadata>>>,
15+
},
16+
GetProduct {
17+
account: Pubkey,
18+
result_tx: oneshot::Sender<Result<ProductAccount>>,
19+
},
20+
GetAllProducts {
21+
result_tx: oneshot::Sender<Result<Vec<ProductAccount>>>,
22+
},
23+
SubscribePrice {
24+
account: Pubkey,
25+
notify_price_tx: mpsc::Sender<NotifyPrice>,
26+
result_tx: oneshot::Sender<Result<SubscriptionID>>,
27+
},
28+
SubscribePriceSched {
29+
account: Pubkey,
30+
notify_price_sched_tx: mpsc::Sender<NotifyPriceSched>,
31+
result_tx: oneshot::Sender<Result<SubscriptionID>>,
32+
},
33+
UpdatePrice {
34+
account: Pubkey,
35+
price: Price,
36+
conf: Conf,
37+
status: String,
38+
},
39+
}

0 commit comments

Comments
 (0)