1use std::time::Duration;
2
3pub type Pubkey = [u8; 32];
5
6#[derive(Debug, Clone)]
8pub struct AccountUpdate {
9 pub pubkey: Pubkey,
10 pub lamports: u64,
11 pub data: Vec<u8>,
12 pub slot: u64,
13 pub write_version: u64,
14}
15
16#[derive(Debug, Clone)]
18pub struct StreamConfig {
19 pub endpoint: String,
20 pub api_key: String,
21 pub staleness_threshold: Duration,
22}
23
24impl StreamConfig {
25 pub fn mainnet(api_key: impl Into<String>) -> Self {
27 Self {
28 endpoint: "wss://mainnet.helius-rpc.com/".into(),
29 api_key: api_key.into(),
30 staleness_threshold: Duration::from_millis(500),
31 }
32 }
33
34 pub fn devnet(api_key: impl Into<String>) -> Self {
36 Self {
37 endpoint: "wss://devnet.helius-rpc.com/".into(),
38 api_key: api_key.into(),
39 staleness_threshold: Duration::from_millis(500),
40 }
41 }
42
43 pub fn custom(endpoint: impl Into<String>, api_key: impl Into<String>) -> Self {
45 Self {
46 endpoint: endpoint.into(),
47 api_key: api_key.into(),
48 staleness_threshold: Duration::from_millis(500),
49 }
50 }
51
52 pub fn staleness_threshold(mut self, d: Duration) -> Self {
55 self.staleness_threshold = d;
56 self
57 }
58
59 pub(crate) fn ws_url(&self) -> String {
60 let sep = if self.endpoint.contains('?') { '&' } else { '?' };
61 format!("{}{}api-key={}", self.endpoint, sep, self.api_key)
62 }
63}
64
65#[derive(Debug, Clone, PartialEq)]
67pub enum StreamState {
68 Disconnected,
69 Connecting { attempt: u32 },
70 Connected { since: std::time::SystemTime },
71 Degraded { gap_slots: u64 },
72 Stale { stale_for_ms: u64 },
73 Failed { reason: String },
74}