penumbra_distributions/component/
view.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
use async_trait::async_trait;

use crate::{component::state_key, params::DistributionsParameters};
use anyhow::Result;
use cnidarium::{StateRead, StateWrite};
use penumbra_num::Amount;
use penumbra_proto::{StateReadProto, StateWriteProto};

#[async_trait]
pub trait StateReadExt: StateRead {
    /// Gets the distributions module chain parameters from the JMT.
    async fn get_distributions_params(&self) -> Result<DistributionsParameters> {
        self.get(state_key::distributions_parameters())
            .await?
            .ok_or_else(|| anyhow::anyhow!("Missing DistributionsParameters"))
    }

    fn get_staking_token_issuance_for_epoch(&self) -> Option<Amount> {
        self.object_get(&state_key::staking_token_issuance_for_epoch())
    }
}

impl<T: StateRead + ?Sized> StateReadExt for T {}
#[async_trait]

pub trait StateWriteExt: StateWrite + StateReadExt {
    /// Set the total amount of staking tokens issued for this epoch.
    fn set_staking_token_issuance_for_epoch(&mut self, issuance: Amount) {
        self.object_put(state_key::staking_token_issuance_for_epoch(), issuance);
    }

    /// Set the Distributions parameters in the JMT.
    fn put_distributions_params(&mut self, params: DistributionsParameters) {
        self.put(state_key::distributions_parameters().into(), params)
    }
}
impl<T: StateWrite + ?Sized> StateWriteExt for T {}