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
use brontes_database::{libmdbx::Libmdbx, IntoTableKey, Tables};
use brontes_types::init_thread_pools;
use clap::Parser;

#[derive(Debug, Parser)]
pub struct Insert {
    /// Table to query
    #[arg(long, short)]
    pub table: Tables,
    /// Key to query
    #[arg(long, short)]
    pub key:   String,
    /// Value to insert
    #[arg(long)]
    pub value: String,
}

impl Insert {
    pub async fn execute(self, brontes_db_path: String) -> eyre::Result<()> {
        let db = Libmdbx::init_db(brontes_db_path, None)?;
        init_thread_pools(10);

        macro_rules! write_to_table {
        ($table:expr, $($tables:ident),+ = $arg0:expr, $arg1:expr) => {
            match $table {
                $(
                    Tables::$tables => {
                        db.write_table(
                            &[
                            brontes_database::libmdbx::tables::$tables::into_table_data(
                                    $arg0,
                                    $arg1
                                )
                            ]
                        ).unwrap();
                    }
                )+
            }
        };
    }
        write_to_table!(
            self.table,
            CexPrice,
            CexTrades,
            BlockInfo,
            DexPrice,
            MevBlocks,
            AddressToProtocolInfo,
            TokenDecimals,
            TxTraces,
            Builder,
            AddressMeta,
            SearcherEOAs,
            SearcherContracts,
            InitializedState,
            PoolCreationBlocks = &self.key,
            &self.value
        );

        Ok(())
    }
}