Skip to content

Commit

Permalink
chore: Fix lint and fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe Rosa committed Dec 13, 2023
1 parent 903f777 commit 06377ad
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions hermes/crates/cardano-chain-follower/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ use pallas::{
network::miniprotocols::{MAINNET_MAGIC, PREVIEW_MAGIC, PRE_PRODUCTION_MAGIC, TESTNET_MAGIC},
};

/// Default [`Follower`] block buffer size.
const DEFAULT_BLOCK_BUFFER_SIZE: usize = 32;
/// Default [`Follower`] max await retries.
const DEFAULT_MAX_AWAIT_RETRIES: u32 = 3;

/// Crate error type.
Expand Down Expand Up @@ -98,36 +100,42 @@ pub enum ChainUpdate {
Rollback(MultiEraBlockData),
}

/// Builder used to create [Config]s.
/// Builder used to create [`Config`]s.
#[derive(Default)]
pub struct ConfigBuilder {
/// Block buffer size option.
block_buffer_size: Option<usize>,
/// Maximum await retries option.
max_await_retries: Option<u32>,
}

impl ConfigBuilder {
/// Sets the size of the block buffer used by the [Follower].
/// Sets the size of the block buffer used by the [`Follower`].
///
/// # Arguments
///
/// * `block_buffer_size`: Size of the block buffer.
#[must_use]
pub fn with_block_buffer_size(mut self, block_buffer_size: usize) -> Self {
self.block_buffer_size = Some(block_buffer_size);
self
}

/// Sets the maximum number of retries the [Follower] will execute when remote node sends
/// an AWAIT message when the [Follower] is already in the MUST_REPLY state.
/// Sets the maximum number of retries the [`Follower`] will execute when remote node
/// sends an AWAIT message when the [`Follower`] is already in the "must reply"
/// state.
///
/// # Argument
///
/// * `max_await_retries`: Maxium number of retries.
#[must_use]
pub fn with_max_await_retries(mut self, max_await_retries: u32) -> Self {
self.max_await_retries = Some(max_await_retries);
self
}

/// Builds a [Config].
/// Builds a [`Config`].
#[must_use]
pub fn build(self) -> Config {
Config {
block_buffer_size: self.block_buffer_size.unwrap_or(DEFAULT_BLOCK_BUFFER_SIZE),
Expand All @@ -138,7 +146,9 @@ impl ConfigBuilder {

/// Configuration for the Cardano chain follower.
pub struct Config {
/// Configured block buffer size.
block_buffer_size: usize,
/// Configured maximum await retry count.
max_await_retries: u32,
}

Expand All @@ -152,7 +162,7 @@ impl Follower {
///
/// * `address`: Address of the node to connect to.
/// * `network`: The [Network] the client is assuming it's connecting to.
/// * `config`: Follower's configuration (see [ConfigBuilder]).
/// * `config`: Follower's configuration (see [`ConfigBuilder`]).
///
/// # Errors
///
Expand Down Expand Up @@ -183,7 +193,8 @@ impl Follower {
///
/// # Errors
///
/// Returns Err if the block range was not found or if some communication error ocurred.
/// Returns Err if the block range was not found or if some communication error
/// ocurred.
pub async fn fetch_block_range(
&mut self, _from: Point, _to: Point,
) -> Result<Vec<MultiEraBlockData>> {
Expand All @@ -201,9 +212,7 @@ impl Follower {
///
/// Returns Err if something went wrong while communicating with the producer.
pub async fn set_read_pointer<P>(&mut self, _at: P) -> Result<Option<Point>>
where
P: Into<PointOrTip>,
{
where P: Into<PointOrTip> {
todo!()
}

Expand Down

0 comments on commit 06377ad

Please sign in to comment.