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
#![deny(rust_2018_idioms)]
#![deny(clippy::all)]
#![deny(rustdoc::broken_intra_doc_links)]
#![cfg_attr(docsrs, feature(doc_cfg))]

pub use {
    self::adapter::{
        state::{LockedState, UnlockedState},
        Adapter,
    },
    dummy::Dummy,
    error::Error,
    ethereum::Ethereum,
};

/// Primitives used by the [`Adapter`].
/// Including re-exported types from the `primitives` crate that are being used.
pub mod primitives {
    use serde::{Deserialize, Serialize};

    pub use ::primitives::{
        config::{ChainInfo, Config, TokenInfo},
        Address, BigNum, Chain, ChainId, ChainOf, Channel, ValidatorId,
    };

    use crate::ethereum::WalletState;

    /// The [`Deposit`] struct with [`BigNum`] values.
    /// Returned by [`crate::client::Locked::get_deposit`]
    pub type Deposit = ::primitives::Deposit<primitives::BigNum>;

    /// A helper type that allows you to use either of them
    /// and dereference the adapter when calling for example an application
    /// with a concrete implementation of the [`crate::Adapter`].
    pub enum AdapterTypes<S, ES> {
        Dummy(Box<crate::dummy::Adapter<S>>),
        Ethereum(Box<crate::Adapter<crate::Ethereum<ES>, S>>),
    }

    impl<S, ES: WalletState> AdapterTypes<S, ES> {
        pub fn dummy(dummy: crate::dummy::Adapter<S>) -> Self {
            Self::Dummy(Box::new(dummy))
        }

        pub fn ethereum(ethereum: crate::Adapter<crate::Ethereum<ES>, S>) -> Self {
            Self::Ethereum(Box::new(ethereum))
        }
    }

    /// [`Session`] struct returned by the [`crate::Adapter`] when [`crate::client::Locked::session_from_token`] is called.
    #[derive(Debug, Clone, Serialize, Deserialize)]
    pub struct Session {
        pub era: i64,
        /// Authenticated as [`Address`].
        pub uid: Address,
        /// Authenticated for [`Chain`].
        pub chain: Chain,
    }
}

/// Re-export of the [`crate::client`] traits and the states of the [`Adapter`].
pub mod prelude {
    /// Re-export traits used for working with the [`crate::Adapter`].
    pub use crate::client::{Locked, Unlockable, Unlocked};

    pub use crate::{LockedState, UnlockedState};
}

mod adapter;

pub mod client;

pub mod dummy;

mod error;

pub mod ethereum;
pub mod util;