penumbra_shielded_pool/component/action_handler/
ics20_withdrawal.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
use std::sync::Arc;

use anyhow::{ensure, Result};
use cnidarium::{StateRead, StateWrite};
use penumbra_ibc::{component::HostInterface, StateReadExt as _};

use crate::component::transfer::{Ics20TransferReadExt as _, Ics20TransferWriteExt as _};
use crate::component::Ics20WithdrawalWithHandler;

impl<HI: HostInterface> Ics20WithdrawalWithHandler<HI> {
    pub async fn check_stateless(&self, _context: ()) -> Result<()> {
        self.action().validate()
    }

    pub async fn check_historical<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
        ensure!(
            state
                .get_ibc_params()
                .await?
                .outbound_ics20_transfers_enabled,
            "transaction an ICS20 withdrawal, but outbound ICS20 withdrawals are not enabled"
        );
        Ok(())
    }

    pub async fn check_and_execute<S: StateWrite>(&self, mut state: S) -> Result<()> {
        let current_block_time = HI::get_block_timestamp(&state).await?;
        state
            .withdrawal_check(self.action(), current_block_time)
            .await?;
        state.withdrawal_execute(self.action()).await
    }
}