Skip to content

Commit 515b55c

Browse files
committed
adapter - docs improvements
1 parent 96f7d21 commit 515b55c

File tree

8 files changed

+48
-22
lines changed

8 files changed

+48
-22
lines changed

adapter/src/adapter.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ pub(crate) mod state {
2525
}
2626

2727
#[derive(Debug)]
28-
/// [`Adapter`] struct
28+
/// The [`Adapter`] struct and it's states.
29+
///
30+
/// Used for communication with the underlying client implementation.
31+
///
32+
/// # Available adapters
33+
///
34+
/// 2 Adapters are available in this crate:
35+
/// - Ethereum
36+
/// - [`crate::ethereum::LockedAdapter`] and [`crate::ethereum::UnlockedAdapter`]
37+
/// - Client implementation [`crate::Ethereum`] for chains compatible with EVM.
38+
/// - Dummy
39+
/// - [`crate::dummy::Adapter`] and it's client implementation [`crate::Dummy`] for testing.
2940
pub struct Adapter<C, S = state::LockedState> {
3041
/// client in a specific state - Locked or Unlocked
3142
pub client: Arc<C>,
@@ -119,7 +130,7 @@ where
119130
}
120131

121132
/// Creates a `Session` from a provided Token by calling the Contract.
122-
/// Does **not** cache the (`Token`, `Session`) pair.
133+
/// Does **not** cache the (`Token`, [`Session`]) pair.
123134
async fn session_from_token(&self, token: &str) -> Result<Session, Error> {
124135
self.client
125136
.session_from_token(token)

adapter/src/client.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
//! The Client traits that define the actions for each state.
2+
//!
3+
//! - [`Locked`]
4+
//! - [`Unlocked`]
5+
//! - [`Unlockable`]
6+
17
use crate::primitives::{Deposit, Session};
28
use async_trait::async_trait;
39
use primitives::{Address, Channel, ValidatorId};

adapter/src/dummy.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! The [`Dummy`] client for the [`Adapter`].
2+
//!
13
use crate::{
24
prelude::*,
35
primitives::{Deposit, Session},
@@ -11,8 +13,8 @@ use std::{collections::HashMap, sync::Arc};
1113

1214
pub type Adapter<S> = crate::Adapter<Dummy, S>;
1315

16+
/// Dummy adapter implementation intended for testing.
1417
#[derive(Debug, Clone)]
15-
/// Dummy adapter implementation.
1618
pub struct Dummy {
1719
/// Who am I
1820
identity: ValidatorId,

adapter/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use thiserror::Error;
44

55
pub(crate) type BoxError = Box<dyn StdError + Send + Sync>;
66

7+
/// The error used by the [`crate::Adapter`] to wrap any custom error from the client
8+
/// and the kinds of errors that the [`crate::Adapter`] can return.
79
#[derive(Debug, Error)]
810
#[error("{inner}")]
911
pub struct Error {

adapter/src/ethereum.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1+
//! The [`Ethereum`] client for the [`Adapter`].
2+
13
use ethstore::{ethkey::Password, SafeAccount};
24

35
use once_cell::sync::Lazy;
46
use serde_json::Value;
57
use web3::signing::keccak256;
68

7-
use crate::{LockedState, UnlockedState};
9+
use crate::{LockedState, UnlockedState, Adapter};
810

911
pub use {
1012
client::{get_counterfactual_address, Ethereum, Options},
1113
error::Error,
1214
};
1315

14-
pub type UnlockedAdapter = crate::Adapter<client::Ethereum<UnlockedWallet>, UnlockedState>;
15-
pub type LockedAdapter = crate::Adapter<client::Ethereum<LockedWallet>, LockedState>;
16-
pub type LockedClient = client::Ethereum<LockedWallet>;
17-
pub type UnlockedClient = client::Ethereum<UnlockedWallet>;
16+
pub type UnlockedAdapter = Adapter<client::Ethereum<UnlockedWallet>, UnlockedState>;
17+
pub type LockedAdapter = Adapter<client::Ethereum<LockedWallet>, LockedState>;
18+
pub type LockedClient = Ethereum<LockedWallet>;
19+
pub type UnlockedClient = Ethereum<UnlockedWallet>;
1820

1921
mod channel;
2022
mod client;

adapter/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ pub use {
44
Adapter,
55
},
66
error::Error,
7+
dummy::Dummy,
8+
ethereum::Ethereum,
79
};
810

9-
pub use dummy::Dummy;
10-
pub use ethereum::Ethereum;
11-
12-
/// only re-export types from the `primitives` crate that are being used by the [`crate::Adapter`].
11+
/// Primitives used by the [`Adapter`].
12+
/// Including re-exported types from the `primitives` crate that are being used.
1313
pub mod primitives {
1414
use serde::{Deserialize, Serialize};
1515

16-
/// Re-export all the types used from the [`primitives`] crate.
1716
pub use ::primitives::{Address, BigNum, Channel, ValidatorId};
1817

1918
use crate::ethereum::WalletState;
2019

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

2324
/// A helper type that allows you to use either of them
@@ -38,29 +39,30 @@ pub mod primitives {
3839
}
3940
}
4041

42+
/// [`Session`] struct returned by the [`crate::Adapter`] when [`crate::client::Locked::session_from_token`] is called.
4143
#[derive(Debug, Clone, Serialize, Deserialize)]
4244
pub struct Session {
4345
pub era: i64,
4446
pub uid: Address,
4547
}
4648
}
4749

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

5355
pub use crate::{LockedState, UnlockedState};
5456
}
5557

56-
/// The [`Adapter`] struct and it's states
57-
/// Used for communication with underlying implementation.
58-
/// 2 Adapters are available in this crate:
59-
/// - [`crate::ethereum::LockedAdapter`] and [`crate::ethereum::UnlockedAdapter`] and it's client implementation [`crate::Ethereum`] for chains compatible with EVM.
60-
/// - [`crate::dummy::Adapter`] and it's client implementation [`crate::Dummy`] for testing.
6158
mod adapter;
59+
60+
6261
pub mod client;
62+
6363
pub mod dummy;
64+
6465
mod error;
66+
6567
pub mod ethereum;
6668
pub mod util;

adapter/src/util.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//! Utilities for working with the `State root` and the `Balances`
2+
13
use thiserror::Error;
24

3-
/// Re-export all the types used from the [`primitives`] crate.
4-
pub use ::primitives::{Address, BigNum, Channel, ValidatorId};
5+
use crate::primitives::{Address, BigNum};
56
use web3::{
67
ethabi::{encode, Address as EthAddress, Token},
78
signing::keccak256,

test_harness/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct TestValidator {
7070
pub sentry_config: sentry::application::Config,
7171
/// Sentry REST API url
7272
pub sentry_url: ApiUrl,
73-
/// Used for the _Sentry REST API_ [`sentry::Application`] as well as the _Validator worker_ [`validator_worker::worker::Args`]
73+
/// Used for the _Sentry REST API_ [`sentry::Application`] as well as the _Validator worker_ [`validator_worker::Worker`]
7474
pub config: Config,
7575
/// Prefix for sentry logger
7676
pub sentry_logger_prefix: String,

0 commit comments

Comments
 (0)