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
pub mod genesis;
pub mod hooks;
pub mod query;
#[cfg(test)]
mod tests;
use sov_modules_api::Error;
use sov_modules_macros::ModuleInfo;
use sov_state::{StateValue, WorkingSet};

/// Initial configuration for the sov_sequencer_registry module.
pub struct SequencerConfig<C: sov_modules_api::Context> {
    pub seq_rollup_address: C::Address,
    pub seq_da_address: Vec<u8>,
    pub coins_to_lock: sov_bank::Coins<C>,
}

#[derive(ModuleInfo)]
pub struct Sequencer<C: sov_modules_api::Context> {
    /// The address of the sov_sequencer_registry module
    /// Note: this is address is generated by the module framework and the corresponding private key is unknown.
    #[address]
    pub(crate) address: C::Address,

    /// Reference to the Bank module.
    #[module]
    pub(crate) bank: sov_bank::Bank<C>,

    /// The sequencer address on the rollup.
    #[state]
    pub(crate) seq_rollup_address: StateValue<C::Address>,

    /// The sequencer address on the DA.
    #[state]
    pub(crate) seq_da_address: StateValue<Vec<u8>>,

    /// Coin's that will be slashed if the sequencer is malicious.
    /// The coins will be transferred from `self.seq_rollup_address` to `self.address`
    /// and locked forever.
    #[state]
    pub(crate) coins_to_lock: StateValue<sov_bank::Coins<C>>,
}

impl<C: sov_modules_api::Context> sov_modules_api::Module for Sequencer<C> {
    type Context = C;

    type Config = SequencerConfig<C>;

    fn genesis(
        &self,
        config: &Self::Config,
        working_set: &mut WorkingSet<C::Storage>,
    ) -> Result<(), Error> {
        Ok(self.init_module(config, working_set)?)
    }
}