penumbra_sdk_shielded_pool/component/action_handler/
ics20_withdrawal.rs

1use std::sync::Arc;
2
3use anyhow::{ensure, Result};
4use cnidarium::{StateRead, StateWrite};
5use penumbra_sdk_ibc::{component::HostInterface, StateReadExt as _};
6
7use crate::component::transfer::{Ics20TransferReadExt as _, Ics20TransferWriteExt as _};
8use crate::component::Ics20WithdrawalWithHandler;
9
10impl<HI: HostInterface> Ics20WithdrawalWithHandler<HI> {
11    pub async fn check_stateless(&self, _context: ()) -> Result<()> {
12        self.action().validate()
13    }
14
15    pub async fn check_historical<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
16        ensure!(
17            state
18                .get_ibc_params()
19                .await?
20                .outbound_ics20_transfers_enabled,
21            "transaction an ICS20 withdrawal, but outbound ICS20 withdrawals are not enabled"
22        );
23        Ok(())
24    }
25
26    pub async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
27        let current_block_time = HI::get_block_timestamp(&state).await?;
28        state
29            .withdrawal_check(self.action(), current_block_time)
30            .await?;
31        state.withdrawal_execute(self.action()).await
32    }
33}