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
#![allow(non_camel_case_types)]

use std::fmt::Debug;

use reth_db::table::{DupSort, Table};

pub struct ReturnKV<T>
where
    T: CompressedTable,
    T::Value: From<T::DecompressedValue> + Into<T::DecompressedValue>,
{
    pub key:   T::Key,
    pub value: T::DecompressedValue,
}

impl<T> From<(T::Key, T::DecompressedValue)> for ReturnKV<T>
where
    T: CompressedTable,
    T::Value: From<T::DecompressedValue> + Into<T::DecompressedValue>,
{
    fn from(value: (T::Key, T::DecompressedValue)) -> Self {
        Self { key: value.0, value: value.1 }
    }
}

pub trait LibmdbxData<T: CompressedTable>: Sized + Send + Sync
where
    T::Value: From<T::DecompressedValue> + Into<T::DecompressedValue>,
{
    #[allow(clippy::wrong_self_convention)]
    fn into_key_val(&self) -> ReturnKV<T>;
}

pub trait LibmdbxDupData<T: DupSort + CompressedTable>: Sized
where
    T::Value: From<T::DecompressedValue> + Into<T::DecompressedValue>,
{
    #[allow(clippy::wrong_self_convention)]
    fn into_key_subkey_val(&self) -> (T::Key, T::SubKey, T::DecompressedValue);
}

pub trait IntoTableKey<T, K, D> {
    fn into_key(value: T) -> K;
    fn into_table_data(key: T, value: T) -> D;
}

pub trait CompressedTable: reth_db::table::Table + Send + Sync
where
    <Self as Table>::Value: From<<Self as CompressedTable>::DecompressedValue>
        + Into<<Self as CompressedTable>::DecompressedValue>,
{
    type DecompressedValue: Debug + PartialEq;

    const INIT_CHUNK_SIZE: Option<usize>;
    const INIT_QUERY: Option<&'static str>;
    const HTTP_ENDPOINT: Option<&'static str>;
    const INIT_FLAG: Option<u16>;
}