solscan/routes/
other.rs

1//! Market, chain information and tools sections.
2
3use crate::{concat_1, solana::Pubkey, Client, Result};
4use serde_json::Value;
5
6api_models! {
7    pub struct TokenMarketInfo {
8        pub price_usdt: f64,
9        pub volume_usdt: u64,
10    }
11
12    pub struct ChainInfo {
13        pub block_height: u64,
14        pub current_epoch: u64,
15        pub absolute_slot: u64,
16        pub transaction_count: u64,
17    }
18}
19
20impl Client {
21    /// Performs an HTTP `GET` request to the `/market/token/{token}` path.
22    pub async fn market(&self, token: &Pubkey) -> Result<TokenMarketInfo> {
23        self.get_no_query(&concat_1("market/token/", &token.to_string())).await
24    }
25
26    /// Performs an HTTP `GET` request to the `/chaininfo` path.
27    pub async fn chain_info(&self) -> Result<ChainInfo> {
28        self.get_no_query("chaininfo").await
29    }
30
31    // TODO: Return value
32    /// Performs an HTTP `GET` request to the `/tools/inspect` path.
33    pub async fn tools_inspect(&self, message: String) -> Result<Value> {
34        self.get("tools/inspect", &[("message", message)]).await
35    }
36}
37
38#[cfg(test)]
39mod tests {
40    use super::*;
41    use crate::ClientError;
42
43    static TOKEN: &str = "4k3Dyjzvzp8eMZWUXbBCjEvwSkkk59S5iCNLY3QrkX6R";
44
45    test_route!(test_market: |c| c.market(&TOKEN.parse().unwrap()) => |res| {
46        assert!(res.price_usdt.is_normal());
47        assert_ne!(res.volume_usdt, 0);
48    });
49
50    test_route!(test_chain_info: |c| c.chain_info() => |res| {
51        assert!(res.block_height > 156339814);
52    });
53
54    // test_route!(test_tools_inspect: |c| c.tools_inspect(String::new()) => |res| {
55    //     // ?
56    // });
57
58    #[tokio::test]
59    async fn test_tools_inspect() {
60        let client = Client::new();
61        let err = client.tools_inspect(String::new()).await.unwrap_err();
62        let ClientError::Response(err) = err else { panic!("{err}"); };
63        assert_eq!(err.status, 500);
64    }
65}