penumbra_app/action_handler/
actions.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
use std::sync::Arc;

use anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use penumbra_shielded_pool::component::Ics20Transfer;
use penumbra_transaction::Action;
use penumbra_txhash::TransactionContext;

mod submit;

use crate::PenumbraHost;

use super::AppActionHandler;
use cnidarium_component::ActionHandler as _;

#[async_trait]
impl AppActionHandler for Action {
    type CheckStatelessContext = TransactionContext;

    async fn check_stateless(&self, context: TransactionContext) -> Result<()> {
        match self {
            Action::SwapClaim(action) => action.check_stateless(context).await,
            Action::Spend(action) => action.check_stateless(context).await,
            Action::DelegatorVote(action) => action.check_stateless(context).await,
            Action::Delegate(action) => action.check_stateless(()).await,
            Action::Undelegate(action) => action.check_stateless(()).await,
            Action::UndelegateClaim(action) => action.check_stateless(()).await,
            Action::ValidatorDefinition(action) => action.check_stateless(()).await,
            Action::ValidatorVote(action) => action.check_stateless(()).await,
            Action::PositionClose(action) => action.check_stateless(()).await,
            Action::PositionOpen(action) => action.check_stateless(()).await,
            Action::PositionWithdraw(action) => action.check_stateless(()).await,
            Action::ProposalSubmit(action) => action.check_stateless(()).await,
            Action::ProposalWithdraw(action) => action.check_stateless(()).await,
            Action::ProposalDepositClaim(action) => action.check_stateless(()).await,
            Action::Swap(action) => action.check_stateless(()).await,
            Action::Output(action) => action.check_stateless(()).await,
            Action::IbcRelay(action) => {
                action
                    .clone()
                    .with_handler::<Ics20Transfer, PenumbraHost>()
                    .check_stateless(())
                    .await
            }
            Action::Ics20Withdrawal(action) => {
                action
                    .clone()
                    .with_handler::<PenumbraHost>()
                    .check_stateless(())
                    .await
            }
            Action::CommunityPoolSpend(action) => action.check_stateless(()).await,
            Action::CommunityPoolOutput(action) => action.check_stateless(()).await,
            Action::CommunityPoolDeposit(action) => action.check_stateless(()).await,
            Action::ActionDutchAuctionSchedule(action) => action.check_stateless(()).await,
            Action::ActionDutchAuctionEnd(action) => action.check_stateless(()).await,
            Action::ActionDutchAuctionWithdraw(action) => action.check_stateless(()).await,
        }
    }

    async fn check_historical<S: StateRead + 'static>(&self, state: Arc<S>) -> Result<()> {
        match self {
            Action::Delegate(action) => action.check_historical(state).await,
            Action::Undelegate(action) => action.check_historical(state).await,
            Action::UndelegateClaim(action) => action.check_historical(state).await,
            Action::ValidatorDefinition(action) => action.check_historical(state).await,
            Action::DelegatorVote(action) => action.check_historical(state).await,
            Action::ValidatorVote(action) => action.check_historical(state).await,
            Action::PositionClose(action) => action.check_historical(state).await,
            Action::PositionOpen(action) => action.check_historical(state).await,
            Action::PositionWithdraw(action) => action.check_historical(state).await,
            Action::ProposalSubmit(action) => action.check_historical(state).await,
            Action::ProposalWithdraw(action) => action.check_historical(state).await,
            Action::ProposalDepositClaim(action) => action.check_historical(state).await,
            Action::Swap(action) => action.check_historical(state).await,
            Action::SwapClaim(action) => action.check_historical(state).await,
            Action::Spend(action) => action.check_historical(state).await,
            Action::Output(action) => action.check_historical(state).await,
            Action::IbcRelay(action) => {
                action
                    .clone()
                    .with_handler::<Ics20Transfer, PenumbraHost>()
                    .check_historical(state)
                    .await
            }
            Action::Ics20Withdrawal(action) => {
                action
                    .clone()
                    .with_handler::<PenumbraHost>()
                    .check_historical(state)
                    .await
            }
            Action::CommunityPoolSpend(action) => action.check_historical(state).await,
            Action::CommunityPoolOutput(action) => action.check_historical(state).await,
            Action::CommunityPoolDeposit(action) => action.check_historical(state).await,
            Action::ActionDutchAuctionSchedule(action) => action.check_historical(state).await,
            Action::ActionDutchAuctionEnd(action) => action.check_historical(state).await,
            Action::ActionDutchAuctionWithdraw(action) => action.check_historical(state).await,
        }
    }

    async fn check_and_execute<S: StateWrite>(&self, state: S) -> Result<()> {
        match self {
            Action::Delegate(action) => action.check_and_execute(state).await,
            Action::Undelegate(action) => action.check_and_execute(state).await,
            Action::UndelegateClaim(action) => action.check_and_execute(state).await,
            Action::ValidatorDefinition(action) => action.check_and_execute(state).await,
            Action::DelegatorVote(action) => action.check_and_execute(state).await,
            Action::ValidatorVote(action) => action.check_and_execute(state).await,
            Action::PositionClose(action) => action.check_and_execute(state).await,
            Action::PositionOpen(action) => action.check_and_execute(state).await,
            Action::PositionWithdraw(action) => action.check_and_execute(state).await,
            Action::ProposalSubmit(action) => action.check_and_execute(state).await,
            Action::ProposalWithdraw(action) => action.check_and_execute(state).await,
            Action::ProposalDepositClaim(action) => action.check_and_execute(state).await,
            Action::Swap(action) => action.check_and_execute(state).await,
            Action::SwapClaim(action) => action.check_and_execute(state).await,
            Action::Spend(action) => action.check_and_execute(state).await,
            Action::Output(action) => action.check_and_execute(state).await,
            Action::IbcRelay(action) => {
                action
                    .clone()
                    .with_handler::<Ics20Transfer, PenumbraHost>()
                    .check_and_execute(state)
                    .await
            }
            Action::Ics20Withdrawal(action) => {
                action
                    .clone()
                    .with_handler::<PenumbraHost>()
                    .check_and_execute(state)
                    .await
            }
            Action::CommunityPoolSpend(action) => action.check_and_execute(state).await,
            Action::CommunityPoolOutput(action) => action.check_and_execute(state).await,
            Action::CommunityPoolDeposit(action) => action.check_and_execute(state).await,
            Action::ActionDutchAuctionSchedule(action) => action.check_and_execute(state).await,
            Action::ActionDutchAuctionEnd(action) => action.check_and_execute(state).await,
            Action::ActionDutchAuctionWithdraw(action) => action.check_and_execute(state).await,
        }
    }
}