penumbra_community_pool/
component.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
/// The Community Pool is a thin component that doesn't have any logic of its own, except for initializing
/// its state and performing post-upgrade checks. It is primarily a collection of state that is modified by
/// [`CommunityPoolSpend`] and [`CommunityPoolDeposit`] actions.
pub mod state_key;

mod action_handler;
mod view;

use std::sync::Arc;

use async_trait::async_trait;
use cnidarium::StateWrite;
use cnidarium_component::Component;
use tendermint::v0_37::abci;
use tracing::instrument;
pub use view::{StateReadExt, StateWriteExt};

use crate::genesis;

pub struct CommunityPool {}

#[async_trait]
impl Component for CommunityPool {
    type AppState = genesis::Content;

    #[instrument(name = "community_pool", skip(state, app_state))]
    async fn init_chain<S: StateWrite>(mut state: S, app_state: Option<&Self::AppState>) {
        match app_state {
            Some(genesis) => {
                state.put_community_pool_params(genesis.community_pool_params.clone());
                state.community_pool_deposit(genesis.initial_balance).await;
            }
            None => {}
        }
    }

    #[instrument(name = "community_pool", skip(_state, _begin_block))]
    async fn begin_block<S: StateWrite + 'static>(
        _state: &mut Arc<S>,
        _begin_block: &abci::request::BeginBlock,
    ) {
    }

    #[instrument(name = "community_pool", skip(_state, _end_block))]
    async fn end_block<S: StateWrite + 'static>(
        _state: &mut Arc<S>,
        _end_block: &abci::request::EndBlock,
    ) {
    }

    #[instrument(name = "community_pool", skip(_state))]
    async fn end_epoch<S: StateWrite + 'static>(_state: &mut Arc<S>) -> anyhow::Result<()> {
        Ok(())
    }
}