penumbra_fee/component/
rpc.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
use async_trait::async_trait;
use cnidarium::Storage;
use penumbra_proto::core::component::fee::v1::{self as pb, query_service_server::QueryService};

use super::StateReadExt;

// TODO: Hide this and only expose a Router?
pub struct Server {
    storage: Storage,
}

impl Server {
    pub fn new(storage: Storage) -> Self {
        Self { storage }
    }
}

#[async_trait]
impl QueryService for Server {
    async fn current_gas_prices(
        &self,
        _request: tonic::Request<pb::CurrentGasPricesRequest>,
    ) -> Result<tonic::Response<pb::CurrentGasPricesResponse>, tonic::Status> {
        let state = self.storage.latest_snapshot();

        let gas_prices = state
            .get_gas_prices()
            .await
            .map_err(|e| tonic::Status::internal(e.to_string()))?;

        Ok(tonic::Response::new(pb::CurrentGasPricesResponse {
            gas_prices: Some(gas_prices.into()),
            alt_gas_prices: Vec::new(),
        }))
    }
}