HyperStackClient

Struct HyperStackClient 

Source
pub struct HyperStackClient<T> { /* private fields */ }

Implementations§

Source§

impl<T> HyperStackClient<T>
where T: Serialize + DeserializeOwned + Clone + Send + Sync + 'static,

Source

pub fn new(url: impl Into<String>, view: impl Into<String>) -> Self

Examples found in repository?
examples/flip/flip_demo.rs (line 70)
63async fn main() -> anyhow::Result<()> {
64    let url = std::env::args()
65        .nth(1)
66        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
67
68    let view = std::env::var("VIEW").unwrap_or_else(|_| "SettlementGame/kv".to_string());
69
70    let mut client = HyperStackClient::<SettlementGame>::new(url, &view);
71
72    if let Ok(key) = std::env::var("KEY") {
73        client = client.with_key(key);
74    }
75
76    let store = client.connect().await?;
77
78    println!("connected, watching {}...\n", view);
79
80    let mut updates = store.subscribe();
81
82    loop {
83        tokio::select! {
84            Ok((key, game)) = updates.recv() => {
85                println!("\n=== Game {} ===", key);
86                println!("{}", serde_json::to_string_pretty(&game).unwrap_or_default());
87            }
88            _ = sleep(Duration::from_secs(30)) => {
89                println!("No updates for 30s...");
90            }
91        }
92    }
93}
More examples
Hide additional examples
examples/pump/token_trades.rs (line 35)
29async fn main() -> anyhow::Result<()> {
30    let url = std::env::args()
31        .nth(1)
32        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
33    let mint = std::env::var("KEY").expect("KEY env var required (token mint address)");
34
35    let client = HyperStackClient::<PumpToken>::new(url, "PumpToken/kv").with_key(&mint);
36
37    let store = client.connect().await?;
38
39    println!("watching trades for token {}...\n", mint);
40
41    let mut updates = store.subscribe();
42    let mut trade_history: VecDeque<TradeInfo> = VecDeque::with_capacity(100);
43
44    loop {
45        tokio::select! {
46            Ok((_key, token)) = updates.recv() => {
47                if let Some(trade) = token.last_trade {
48                    trade_history.push_back(trade.clone());
49                    if trade_history.len() > 100 {
50                        trade_history.pop_front();
51                    }
52
53                    println!("[{}] {} | {}... | {:.4} SOL (total: {} trades)",
54                        Utc::now().format("%H:%M:%S"),
55                        trade.direction,
56                        &trade.wallet[..8],
57                        trade.amount_sol,
58                        trade_history.len());
59                }
60            }
61            _ = sleep(Duration::from_secs(60)) => {
62                println!("No trades for 60s...");
63            }
64        }
65    }
66}
examples/pump/new_launches.rs (line 26)
21async fn main() -> anyhow::Result<()> {
22    let url = std::env::args()
23        .nth(1)
24        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
25
26    let client = HyperStackClient::<PumpToken>::new(url, "PumpToken/list");
27
28    let store = client.connect().await?;
29
30    println!("watching for new pump.fun token launches...\n");
31
32    let mut updates = store.subscribe();
33
34    loop {
35        tokio::select! {
36            Ok((mint, token)) = updates.recv() => {
37                if token.name.is_some() || token.symbol.is_some() {
38                    println!("\n[{}] new token launch", Utc::now().format("%Y-%m-%d %H:%M:%S UTC"));
39                    println!("mint: {}", mint);
40                    if let Some(name) = &token.name {
41                        println!("name: {}", name);
42                    }
43                    if let Some(symbol) = &token.symbol {
44                        println!("symbol: {}", symbol);
45                    }
46                    if let Some(creator) = &token.creator {
47                        println!("creator: {}", creator);
48                    }
49                    if let Some(sol) = token.virtual_sol_reserves {
50                        println!("initial liquidity: {:.4} SOL", sol as f64 / 1e9);
51                    }
52                }
53            }
54            _ = sleep(Duration::from_secs(60)) => {
55                println!("No new launches for 60s...");
56            }
57        }
58    }
59}
Source

pub fn with_key(self, key: impl Into<String>) -> Self

Examples found in repository?
examples/flip/flip_demo.rs (line 73)
63async fn main() -> anyhow::Result<()> {
64    let url = std::env::args()
65        .nth(1)
66        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
67
68    let view = std::env::var("VIEW").unwrap_or_else(|_| "SettlementGame/kv".to_string());
69
70    let mut client = HyperStackClient::<SettlementGame>::new(url, &view);
71
72    if let Ok(key) = std::env::var("KEY") {
73        client = client.with_key(key);
74    }
75
76    let store = client.connect().await?;
77
78    println!("connected, watching {}...\n", view);
79
80    let mut updates = store.subscribe();
81
82    loop {
83        tokio::select! {
84            Ok((key, game)) = updates.recv() => {
85                println!("\n=== Game {} ===", key);
86                println!("{}", serde_json::to_string_pretty(&game).unwrap_or_default());
87            }
88            _ = sleep(Duration::from_secs(30)) => {
89                println!("No updates for 30s...");
90            }
91        }
92    }
93}
More examples
Hide additional examples
examples/pump/token_trades.rs (line 35)
29async fn main() -> anyhow::Result<()> {
30    let url = std::env::args()
31        .nth(1)
32        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
33    let mint = std::env::var("KEY").expect("KEY env var required (token mint address)");
34
35    let client = HyperStackClient::<PumpToken>::new(url, "PumpToken/kv").with_key(&mint);
36
37    let store = client.connect().await?;
38
39    println!("watching trades for token {}...\n", mint);
40
41    let mut updates = store.subscribe();
42    let mut trade_history: VecDeque<TradeInfo> = VecDeque::with_capacity(100);
43
44    loop {
45        tokio::select! {
46            Ok((_key, token)) = updates.recv() => {
47                if let Some(trade) = token.last_trade {
48                    trade_history.push_back(trade.clone());
49                    if trade_history.len() > 100 {
50                        trade_history.pop_front();
51                    }
52
53                    println!("[{}] {} | {}... | {:.4} SOL (total: {} trades)",
54                        Utc::now().format("%H:%M:%S"),
55                        trade.direction,
56                        &trade.wallet[..8],
57                        trade.amount_sol,
58                        trade_history.len());
59                }
60            }
61            _ = sleep(Duration::from_secs(60)) => {
62                println!("No trades for 60s...");
63            }
64        }
65    }
66}
Source

pub async fn connect(self) -> Result<EntityStore<T>>

Examples found in repository?
examples/flip/flip_demo.rs (line 76)
63async fn main() -> anyhow::Result<()> {
64    let url = std::env::args()
65        .nth(1)
66        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
67
68    let view = std::env::var("VIEW").unwrap_or_else(|_| "SettlementGame/kv".to_string());
69
70    let mut client = HyperStackClient::<SettlementGame>::new(url, &view);
71
72    if let Ok(key) = std::env::var("KEY") {
73        client = client.with_key(key);
74    }
75
76    let store = client.connect().await?;
77
78    println!("connected, watching {}...\n", view);
79
80    let mut updates = store.subscribe();
81
82    loop {
83        tokio::select! {
84            Ok((key, game)) = updates.recv() => {
85                println!("\n=== Game {} ===", key);
86                println!("{}", serde_json::to_string_pretty(&game).unwrap_or_default());
87            }
88            _ = sleep(Duration::from_secs(30)) => {
89                println!("No updates for 30s...");
90            }
91        }
92    }
93}
More examples
Hide additional examples
examples/pump/token_trades.rs (line 37)
29async fn main() -> anyhow::Result<()> {
30    let url = std::env::args()
31        .nth(1)
32        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
33    let mint = std::env::var("KEY").expect("KEY env var required (token mint address)");
34
35    let client = HyperStackClient::<PumpToken>::new(url, "PumpToken/kv").with_key(&mint);
36
37    let store = client.connect().await?;
38
39    println!("watching trades for token {}...\n", mint);
40
41    let mut updates = store.subscribe();
42    let mut trade_history: VecDeque<TradeInfo> = VecDeque::with_capacity(100);
43
44    loop {
45        tokio::select! {
46            Ok((_key, token)) = updates.recv() => {
47                if let Some(trade) = token.last_trade {
48                    trade_history.push_back(trade.clone());
49                    if trade_history.len() > 100 {
50                        trade_history.pop_front();
51                    }
52
53                    println!("[{}] {} | {}... | {:.4} SOL (total: {} trades)",
54                        Utc::now().format("%H:%M:%S"),
55                        trade.direction,
56                        &trade.wallet[..8],
57                        trade.amount_sol,
58                        trade_history.len());
59                }
60            }
61            _ = sleep(Duration::from_secs(60)) => {
62                println!("No trades for 60s...");
63            }
64        }
65    }
66}
examples/pump/new_launches.rs (line 28)
21async fn main() -> anyhow::Result<()> {
22    let url = std::env::args()
23        .nth(1)
24        .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string());
25
26    let client = HyperStackClient::<PumpToken>::new(url, "PumpToken/list");
27
28    let store = client.connect().await?;
29
30    println!("watching for new pump.fun token launches...\n");
31
32    let mut updates = store.subscribe();
33
34    loop {
35        tokio::select! {
36            Ok((mint, token)) = updates.recv() => {
37                if token.name.is_some() || token.symbol.is_some() {
38                    println!("\n[{}] new token launch", Utc::now().format("%Y-%m-%d %H:%M:%S UTC"));
39                    println!("mint: {}", mint);
40                    if let Some(name) = &token.name {
41                        println!("name: {}", name);
42                    }
43                    if let Some(symbol) = &token.symbol {
44                        println!("symbol: {}", symbol);
45                    }
46                    if let Some(creator) = &token.creator {
47                        println!("creator: {}", creator);
48                    }
49                    if let Some(sol) = token.virtual_sol_reserves {
50                        println!("initial liquidity: {:.4} SOL", sol as f64 / 1e9);
51                    }
52                }
53            }
54            _ = sleep(Duration::from_secs(60)) => {
55                println!("No new launches for 60s...");
56            }
57        }
58    }
59}

Auto Trait Implementations§

§

impl<T> Freeze for HyperStackClient<T>

§

impl<T> RefUnwindSafe for HyperStackClient<T>
where T: RefUnwindSafe,

§

impl<T> Send for HyperStackClient<T>
where T: Send,

§

impl<T> Sync for HyperStackClient<T>
where T: Sync,

§

impl<T> Unpin for HyperStackClient<T>
where T: Unpin,

§

impl<T> UnwindSafe for HyperStackClient<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V