Skip to content

Commit

Permalink
chore: apply rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Nov 8, 2024
1 parent 79e6e86 commit 44d0d0e
Show file tree
Hide file tree
Showing 188 changed files with 1,672 additions and 3,899 deletions.
89 changes: 25 additions & 64 deletions apps/fortuna/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,47 +1,27 @@
use {
crate::{
chain::reader::{
BlockNumber,
BlockStatus,
EntropyReader,
},
chain::reader::{BlockNumber, BlockStatus, EntropyReader},
state::HashChainState,
},
anyhow::Result,
axum::{
body::Body,
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
routing::get,
Router,
},
ethers::core::types::Address,
prometheus_client::{
encoding::EncodeLabelSet,
metrics::{
counter::Counter,
family::Family,
},
metrics::{counter::Counter, family::Family},
registry::Registry,
},
std::{
collections::HashMap,
sync::Arc,
},
std::{collections::HashMap, sync::Arc},
tokio::sync::RwLock,
url::Url,
};
pub use {
chain_ids::*,
index::*,
live::*,
metrics::*,
ready::*,
revelation::*,
};
pub use {chain_ids::*, index::*, live::*, metrics::*, ready::*, revelation::*};

mod chain_ids;
mod index;
Expand Down Expand Up @@ -99,16 +79,16 @@ impl ApiState {
#[derive(Clone)]
pub struct BlockchainState {
/// The chain id for this blockchain, useful for logging
pub id: ChainId,
pub id: ChainId,
/// The hash chain(s) required to serve random numbers for this blockchain
pub state: Arc<HashChainState>,
pub state: Arc<HashChainState>,
/// The contract that the server is fulfilling requests for.
pub contract: Arc<dyn EntropyReader>,
pub contract: Arc<dyn EntropyReader>,
/// The address of the provider that this server is operating for.
pub provider_address: Address,
pub provider_address: Address,
/// The server will wait for this many block confirmations of a request before revealing
/// the random number.
pub reveal_delay_blocks: BlockNumber,
pub reveal_delay_blocks: BlockNumber,
/// The BlockStatus of the block that is considered to be confirmed on the blockchain.
/// For eg., Finalized, Safe
pub confirmed_block_status: BlockStatus,
Expand Down Expand Up @@ -194,35 +174,16 @@ pub fn get_register_uri(base_uri: &str, chain_id: &str) -> Result<String> {
mod test {
use {
crate::{
api::{
self,
ApiState,
BinaryEncoding,
Blob,
BlockchainState,
GetRandomValueResponse,
},
chain::reader::{
mock::MockEntropyReader,
BlockStatus,
},
state::{
HashChainState,
PebbleHashChain,
},
api::{self, ApiState, BinaryEncoding, Blob, BlockchainState, GetRandomValueResponse},
chain::reader::{mock::MockEntropyReader, BlockStatus},
state::{HashChainState, PebbleHashChain},
},
axum::http::StatusCode,
axum_test::{
TestResponse,
TestServer,
},
axum_test::{TestResponse, TestServer},
ethers::prelude::Address,
lazy_static::lazy_static,
prometheus_client::registry::Registry,
std::{
collections::HashMap,
sync::Arc,
},
std::{collections::HashMap, sync::Arc},
tokio::sync::RwLock,
};

Expand All @@ -245,11 +206,11 @@ mod test {
let eth_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let eth_state = BlockchainState {
id: "ethereum".into(),
state: ETH_CHAIN.clone(),
contract: eth_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 1,
id: "ethereum".into(),
state: ETH_CHAIN.clone(),
contract: eth_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 1,
confirmed_block_status: BlockStatus::Latest,
};

Expand All @@ -258,11 +219,11 @@ mod test {
let avax_read = Arc::new(MockEntropyReader::with_requests(10, &[]));

let avax_state = BlockchainState {
id: "avalanche".into(),
state: AVAX_CHAIN.clone(),
contract: avax_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 2,
id: "avalanche".into(),
state: AVAX_CHAIN.clone(),
contract: avax_read.clone(),
provider_address: PROVIDER,
reveal_delay_blocks: 2,
confirmed_block_status: BlockStatus::Latest,
};

Expand Down
10 changes: 2 additions & 8 deletions apps/fortuna/src/api/chain_ids.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
use {
crate::api::{
ChainId,
RestError,
},
crate::api::{ChainId, RestError},
anyhow::Result,
axum::{
extract::State,
Json,
},
axum::{extract::State, Json},
};

/// Get the list of supported chain ids
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/index.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use axum::{
response::IntoResponse,
Json,
};
use axum::{response::IntoResponse, Json};

/// This is the index page for the REST service. It lists all the available endpoints.
///
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/live.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use axum::{
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
};

pub async fn live() -> Response {
Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
//! Exposing prometheus metrics via HTTP in openmetrics format.

use {
axum::{
extract::State,
response::IntoResponse,
},
axum::{extract::State, response::IntoResponse},
prometheus_client::encoding::text::encode,
};

Expand Down
5 changes: 1 addition & 4 deletions apps/fortuna/src/api/ready.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use axum::{
http::StatusCode,
response::{
IntoResponse,
Response,
},
response::{IntoResponse, Response},
};

pub async fn ready() -> Response {
Expand Down
17 changes: 3 additions & 14 deletions apps/fortuna/src/api/revelation.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
use {
crate::api::{
ChainId,
RequestLabel,
RestError,
},
crate::api::{ChainId, RequestLabel, RestError},
anyhow::Result,
axum::{
extract::{
Path,
Query,
State,
},
extract::{Path, Query, State},
Json,
},
pythnet_sdk::wire::array,
serde_with::serde_as,
tokio::try_join,
utoipa::{
IntoParams,
ToSchema,
},
utoipa::{IntoParams, ToSchema},
};

/// Reveal the random value for a given sequence number and blockchain.
Expand Down
12 changes: 2 additions & 10 deletions apps/fortuna/src/chain/eth_gas_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ use {
axum::async_trait,
ethers::{
prelude::{
gas_oracle::{
GasOracleError,
Result,
},
gas_oracle::{GasOracleError, Result},
GasOracle,
},
providers::Middleware,
types::{
I256,
U256,
},
types::{I256, U256},
},
};

Expand All @@ -35,12 +29,10 @@ pub const SURGE_THRESHOLD_1: u64 = 40_000;
pub const SURGE_THRESHOLD_2: u64 = 100_000;
pub const SURGE_THRESHOLD_3: u64 = 200_000;


/// The threshold max change/difference (in %) at which we will ignore the fee history values
/// under it.
pub const EIP1559_FEE_ESTIMATION_THRESHOLD_MAX_CHANGE: i64 = 200;


/// Gas oracle from a [`Middleware`] implementation such as an
/// Ethereum RPC provider.
#[derive(Clone, Debug)]
Expand Down
72 changes: 16 additions & 56 deletions apps/fortuna/src/chain/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,24 @@ use {
chain::{
eth_gas_oracle::EthProviderOracle,
nonce_manager::NonceManagerMiddleware,
reader::{
self,
BlockNumber,
BlockStatus,
EntropyReader,
RequestedWithCallbackEvent,
},
traced_client::{
RpcMetrics,
TracedClient,
},
reader::{self, BlockNumber, BlockStatus, EntropyReader, RequestedWithCallbackEvent},
traced_client::{RpcMetrics, TracedClient},
},
config::EthereumConfig,
},
anyhow::{
anyhow,
Error,
Result,
},
anyhow::{anyhow, Error, Result},
axum::async_trait,
ethers::{
abi::RawLog,
contract::{
abigen,
ContractCall,
EthLogDecode,
},
contract::{abigen, ContractCall, EthLogDecode},
core::types::Address,
middleware::{
gas_oracle::GasOracleMiddleware,
MiddlewareError,
SignerMiddleware,
},
prelude::{
BlockId,
JsonRpcClient,
PendingTransaction,
TransactionRequest,
},
providers::{
Http,
Middleware,
Provider,
},
signers::{
LocalWallet,
Signer,
},
types::{
transaction::eip2718::TypedTransaction,
BlockNumber as EthersBlockNumber,
U256,
},
},
sha3::{
Digest,
Keccak256,
middleware::{gas_oracle::GasOracleMiddleware, MiddlewareError, SignerMiddleware},
prelude::{BlockId, JsonRpcClient, PendingTransaction, TransactionRequest},
providers::{Http, Middleware, Provider},
signers::{LocalWallet, Signer},
types::{transaction::eip2718::TypedTransaction, BlockNumber as EthersBlockNumber, U256},
},
sha3::{Digest, Keccak256},
std::sync::Arc,
thiserror::Error,
};
Expand Down Expand Up @@ -94,7 +54,7 @@ pub type InstrumentedPythContract = PythRandom<Provider<TracedClient>>;
#[derive(Clone, Debug)]
pub struct LegacyTxMiddleware<M> {
use_legacy_tx: bool,
inner: M,
inner: M,
}

impl<M> LegacyTxMiddleware<M> {
Expand Down Expand Up @@ -333,10 +293,10 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
// sequence_number == 0 means the request does not exist.
if r.sequence_number != 0 {
Ok(Some(reader::Request {
provider: r.provider,
provider: r.provider,
sequence_number: r.sequence_number,
block_number: r.block_number.try_into()?,
use_blockhash: r.use_blockhash,
block_number: r.block_number.try_into()?,
use_blockhash: r.use_blockhash,
}))
} else {
Ok(None)
Expand Down Expand Up @@ -370,9 +330,9 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
Ok(res
.iter()
.map(|r| RequestedWithCallbackEvent {
sequence_number: r.sequence_number,
sequence_number: r.sequence_number,
user_random_number: r.user_random_number,
provider_address: r.request.provider,
provider_address: r.request.provider,
})
.collect())
}
Expand Down
Loading

0 comments on commit 44d0d0e

Please sign in to comment.