solana_trader_client_rust/provider/grpc/
general.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
use anyhow::Result;
use solana_trader_proto::api;
use solana_trader_proto::api::GetRecentBlockHashRequestV2;
use tonic::Request;

use super::GrpcClient;

impl GrpcClient {
    pub async fn get_transaction(
        &mut self,
        request: &api::GetTransactionRequest,
    ) -> Result<api::GetTransactionResponse> {
        let response = self
            .client
            .get_transaction(Request::new(request.clone()))
            .await
            .map_err(|e| anyhow::anyhow!("GetTransactionResponse error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_recent_block_hash(
        &mut self,
        request: &api::GetRecentBlockHashRequest,
    ) -> Result<api::GetRecentBlockHashResponse> {
        let response = self
            .client
            .get_recent_block_hash(Request::new(*request))
            .await
            .map_err(|e| anyhow::anyhow!("GetRecentBlockHash error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_recent_block_hash_v2(
        &mut self,
        request: GetRecentBlockHashRequestV2,
    ) -> Result<api::GetRecentBlockHashResponseV2> {
        let response = self
            .client
            .get_recent_block_hash_v2(Request::new(request))
            .await
            .map_err(|e| anyhow::anyhow!("GetRecentBlockHashV2 error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_rate_limit(
        &mut self,
        request: &api::GetRateLimitRequest,
    ) -> Result<api::GetRateLimitResponse> {
        let response = self
            .client
            .get_rate_limit(Request::new(*request))
            .await
            .map_err(|e| anyhow::anyhow!("GetRateLimit error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_account_balance_v2(
        &mut self,
        request: &api::GetAccountBalanceRequest,
    ) -> Result<api::GetAccountBalanceResponse> {
        let response = self
            .client
            .get_account_balance_v2(Request::new(request.clone()))
            .await
            .map_err(|e| anyhow::anyhow!("GetAccountBalanceV2 error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_priority_fee(
        &mut self,
        project: api::Project,
        percentile: Option<f64>,
    ) -> Result<api::GetPriorityFeeResponse> {
        let request = Request::new(api::GetPriorityFeeRequest {
            project: project as i32,
            percentile,
        });

        let response = self
            .client
            .get_priority_fee(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPriorityFee error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_priority_fee_by_program(
        &mut self,
        programs: Vec<String>,
    ) -> Result<api::GetPriorityFeeByProgramResponse> {
        let request = Request::new(api::GetPriorityFeeByProgramRequest { programs });

        let response = self
            .client
            .get_priority_fee_by_program(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetPriorityFeeByProgram error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_token_accounts(
        &mut self,
        owner_address: String,
    ) -> Result<api::GetTokenAccountsResponse> {
        let request = Request::new(api::GetTokenAccountsRequest { owner_address });

        let response = self
            .client
            .get_token_accounts(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetTokenAccounts error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_account_balance(
        &mut self,
        owner_address: String,
    ) -> Result<api::GetAccountBalanceResponse> {
        let request = Request::new(api::GetAccountBalanceRequest { owner_address });

        let response = self
            .client
            .get_account_balance(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetAccountBalance error: {}", e))?;

        Ok(response.into_inner())
    }

    pub async fn get_leader_schedule(
        &mut self,
        max_slots: u64,
    ) -> Result<api::GetLeaderScheduleResponse> {
        let request = Request::new(api::GetLeaderScheduleRequest { max_slots });

        let response = self
            .client
            .get_leader_schedule(request)
            .await
            .map_err(|e| anyhow::anyhow!("GetLeaderSchedule error: {}", e))?;

        Ok(response.into_inner())
    }
}