penumbra_sdk_community_pool/component/action_handler/
community_pool_spend.rs

1use anyhow::Result;
2use async_trait::async_trait;
3use cnidarium::StateWrite;
4use cnidarium_component::ActionHandler;
5
6use crate::{component::StateWriteExt as _, CommunityPoolSpend};
7
8#[async_trait]
9impl ActionHandler for CommunityPoolSpend {
10    type CheckStatelessContext = ();
11    async fn check_stateless(&self, _context: ()) -> Result<()> {
12        // We can't statelessly check that the Community Pool has enough funds to spend, because we don't know
13        // what its state is here.
14        Ok(())
15    }
16
17    async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
18        // This will fail if we try to overdraw the Community Pool, so we can never spend more than we have.
19        state.community_pool_withdraw(self.value).await
20    }
21}