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
use std::sync::Arc;

use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use filament_chain::{Input, Transaction};

use crate::handler::Handler;

mod delegate;
mod transfer;
mod undelegate;

#[async_trait]
impl Handler for Input {
    async fn validate(&self, tx: Arc<Transaction>) -> eyre::Result<()> {
        match self {
            Self::Delegate(input) => input.validate(tx),
            Self::Undelegate(input) => input.validate(tx),

            Self::Transfer(input) => input.validate(tx),
        }
        .await
    }

    async fn check<S: StateRead>(&self, state: Arc<S>) -> eyre::Result<()> {
        match self {
            Self::Delegate(input) => input.check(state),
            Self::Undelegate(input) => input.check(state),

            Self::Transfer(input) => input.check(state),
        }
        .await
    }

    async fn execute<S: StateWrite>(&self, state: &mut S) -> eyre::Result<()> {
        match self {
            Self::Delegate(input) => input.execute(state),
            Self::Undelegate(input) => input.execute(state),

            Self::Transfer(input) => input.execute(state),
        }
        .await
    }
}