penumbra_app/
community_pool_ext.rsuse anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use futures::{StreamExt, TryStreamExt};
use penumbra_governance::state_key;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_sct::component::clock::EpochRead;
use penumbra_transaction::Transaction;
#[async_trait]
pub trait CommunityPoolStateReadExt: StateRead + penumbra_stake::StateReadExt {
async fn pending_community_pool_transactions(&self) -> Result<Vec<Transaction>> {
let prefix = state_key::deliver_community_pool_transactions_at_height(
self.get_block_height().await?,
);
let proposals: Vec<u64> = self
.prefix_proto::<u64>(&prefix)
.map(|result| anyhow::Ok(result?.1))
.try_collect()
.await?;
let mut transactions = Vec::new();
for proposal in proposals {
transactions.push(
self.get(&state_key::community_pool_transaction(proposal))
.await?
.ok_or_else(|| {
anyhow::anyhow!("no transaction found for proposal {}", proposal)
})?,
);
}
Ok(transactions)
}
}
impl<T: StateRead + penumbra_stake::StateReadExt + ?Sized> CommunityPoolStateReadExt for T {}
#[async_trait]
pub trait CommunityPoolStateWriteExt: StateWrite {
fn put_community_pool_transaction(&mut self, proposal: u64, transaction: Transaction) {
self.put(state_key::community_pool_transaction(proposal), transaction);
}
}
impl<T: StateWrite + ?Sized> CommunityPoolStateWriteExt for T {}