Skip to content

Commit 52976b9

Browse files
committed
chore: apply rustfmt
1 parent ff4bf15 commit 52976b9

File tree

188 files changed

+1672
-3899
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

188 files changed

+1672
-3899
lines changed

apps/fortuna/src/api.rs

Lines changed: 25 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,27 @@
11
use {
22
crate::{
3-
chain::reader::{
4-
BlockNumber,
5-
BlockStatus,
6-
EntropyReader,
7-
},
3+
chain::reader::{BlockNumber, BlockStatus, EntropyReader},
84
state::HashChainState,
95
},
106
anyhow::Result,
117
axum::{
128
body::Body,
139
http::StatusCode,
14-
response::{
15-
IntoResponse,
16-
Response,
17-
},
10+
response::{IntoResponse, Response},
1811
routing::get,
1912
Router,
2013
},
2114
ethers::core::types::Address,
2215
prometheus_client::{
2316
encoding::EncodeLabelSet,
24-
metrics::{
25-
counter::Counter,
26-
family::Family,
27-
},
17+
metrics::{counter::Counter, family::Family},
2818
registry::Registry,
2919
},
30-
std::{
31-
collections::HashMap,
32-
sync::Arc,
33-
},
20+
std::{collections::HashMap, sync::Arc},
3421
tokio::sync::RwLock,
3522
url::Url,
3623
};
37-
pub use {
38-
chain_ids::*,
39-
index::*,
40-
live::*,
41-
metrics::*,
42-
ready::*,
43-
revelation::*,
44-
};
24+
pub use {chain_ids::*, index::*, live::*, metrics::*, ready::*, revelation::*};
4525

4626
mod chain_ids;
4727
mod index;
@@ -99,16 +79,16 @@ impl ApiState {
9979
#[derive(Clone)]
10080
pub struct BlockchainState {
10181
/// The chain id for this blockchain, useful for logging
102-
pub id: ChainId,
82+
pub id: ChainId,
10383
/// The hash chain(s) required to serve random numbers for this blockchain
104-
pub state: Arc<HashChainState>,
84+
pub state: Arc<HashChainState>,
10585
/// The contract that the server is fulfilling requests for.
106-
pub contract: Arc<dyn EntropyReader>,
86+
pub contract: Arc<dyn EntropyReader>,
10787
/// The address of the provider that this server is operating for.
108-
pub provider_address: Address,
88+
pub provider_address: Address,
10989
/// The server will wait for this many block confirmations of a request before revealing
11090
/// the random number.
111-
pub reveal_delay_blocks: BlockNumber,
91+
pub reveal_delay_blocks: BlockNumber,
11292
/// The BlockStatus of the block that is considered to be confirmed on the blockchain.
11393
/// For eg., Finalized, Safe
11494
pub confirmed_block_status: BlockStatus,
@@ -194,35 +174,16 @@ pub fn get_register_uri(base_uri: &str, chain_id: &str) -> Result<String> {
194174
mod test {
195175
use {
196176
crate::{
197-
api::{
198-
self,
199-
ApiState,
200-
BinaryEncoding,
201-
Blob,
202-
BlockchainState,
203-
GetRandomValueResponse,
204-
},
205-
chain::reader::{
206-
mock::MockEntropyReader,
207-
BlockStatus,
208-
},
209-
state::{
210-
HashChainState,
211-
PebbleHashChain,
212-
},
177+
api::{self, ApiState, BinaryEncoding, Blob, BlockchainState, GetRandomValueResponse},
178+
chain::reader::{mock::MockEntropyReader, BlockStatus},
179+
state::{HashChainState, PebbleHashChain},
213180
},
214181
axum::http::StatusCode,
215-
axum_test::{
216-
TestResponse,
217-
TestServer,
218-
},
182+
axum_test::{TestResponse, TestServer},
219183
ethers::prelude::Address,
220184
lazy_static::lazy_static,
221185
prometheus_client::registry::Registry,
222-
std::{
223-
collections::HashMap,
224-
sync::Arc,
225-
},
186+
std::{collections::HashMap, sync::Arc},
226187
tokio::sync::RwLock,
227188
};
228189

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

247208
let eth_state = BlockchainState {
248-
id: "ethereum".into(),
249-
state: ETH_CHAIN.clone(),
250-
contract: eth_read.clone(),
251-
provider_address: PROVIDER,
252-
reveal_delay_blocks: 1,
209+
id: "ethereum".into(),
210+
state: ETH_CHAIN.clone(),
211+
contract: eth_read.clone(),
212+
provider_address: PROVIDER,
213+
reveal_delay_blocks: 1,
253214
confirmed_block_status: BlockStatus::Latest,
254215
};
255216

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

260221
let avax_state = BlockchainState {
261-
id: "avalanche".into(),
262-
state: AVAX_CHAIN.clone(),
263-
contract: avax_read.clone(),
264-
provider_address: PROVIDER,
265-
reveal_delay_blocks: 2,
222+
id: "avalanche".into(),
223+
state: AVAX_CHAIN.clone(),
224+
contract: avax_read.clone(),
225+
provider_address: PROVIDER,
226+
reveal_delay_blocks: 2,
266227
confirmed_block_status: BlockStatus::Latest,
267228
};
268229

apps/fortuna/src/api/chain_ids.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
use {
2-
crate::api::{
3-
ChainId,
4-
RestError,
5-
},
2+
crate::api::{ChainId, RestError},
63
anyhow::Result,
7-
axum::{
8-
extract::State,
9-
Json,
10-
},
4+
axum::{extract::State, Json},
115
};
126

137
/// Get the list of supported chain ids

apps/fortuna/src/api/index.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use axum::{
2-
response::IntoResponse,
3-
Json,
4-
};
1+
use axum::{response::IntoResponse, Json};
52

63
/// This is the index page for the REST service. It lists all the available endpoints.
74
///

apps/fortuna/src/api/live.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use axum::{
22
http::StatusCode,
3-
response::{
4-
IntoResponse,
5-
Response,
6-
},
3+
response::{IntoResponse, Response},
74
};
85

96
pub async fn live() -> Response {

apps/fortuna/src/api/metrics.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
//! Exposing prometheus metrics via HTTP in openmetrics format.
22
33
use {
4-
axum::{
5-
extract::State,
6-
response::IntoResponse,
7-
},
4+
axum::{extract::State, response::IntoResponse},
85
prometheus_client::encoding::text::encode,
96
};
107

apps/fortuna/src/api/ready.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use axum::{
22
http::StatusCode,
3-
response::{
4-
IntoResponse,
5-
Response,
6-
},
3+
response::{IntoResponse, Response},
74
};
85

96
pub async fn ready() -> Response {

apps/fortuna/src/api/revelation.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
use {
2-
crate::api::{
3-
ChainId,
4-
RequestLabel,
5-
RestError,
6-
},
2+
crate::api::{ChainId, RequestLabel, RestError},
73
anyhow::Result,
84
axum::{
9-
extract::{
10-
Path,
11-
Query,
12-
State,
13-
},
5+
extract::{Path, Query, State},
146
Json,
157
},
168
pythnet_sdk::wire::array,
179
serde_with::serde_as,
1810
tokio::try_join,
19-
utoipa::{
20-
IntoParams,
21-
ToSchema,
22-
},
11+
utoipa::{IntoParams, ToSchema},
2312
};
2413

2514
/// Reveal the random value for a given sequence number and blockchain.

apps/fortuna/src/chain/eth_gas_oracle.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,11 @@ use {
22
axum::async_trait,
33
ethers::{
44
prelude::{
5-
gas_oracle::{
6-
GasOracleError,
7-
Result,
8-
},
5+
gas_oracle::{GasOracleError, Result},
96
GasOracle,
107
},
118
providers::Middleware,
12-
types::{
13-
I256,
14-
U256,
15-
},
9+
types::{I256, U256},
1610
},
1711
};
1812

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

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

43-
4436
/// Gas oracle from a [`Middleware`] implementation such as an
4537
/// Ethereum RPC provider.
4638
#[derive(Clone, Debug)]

apps/fortuna/src/chain/ethereum.rs

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,64 +4,24 @@ use {
44
chain::{
55
eth_gas_oracle::EthProviderOracle,
66
nonce_manager::NonceManagerMiddleware,
7-
reader::{
8-
self,
9-
BlockNumber,
10-
BlockStatus,
11-
EntropyReader,
12-
RequestedWithCallbackEvent,
13-
},
14-
traced_client::{
15-
RpcMetrics,
16-
TracedClient,
17-
},
7+
reader::{self, BlockNumber, BlockStatus, EntropyReader, RequestedWithCallbackEvent},
8+
traced_client::{RpcMetrics, TracedClient},
189
},
1910
config::EthereumConfig,
2011
},
21-
anyhow::{
22-
anyhow,
23-
Error,
24-
Result,
25-
},
12+
anyhow::{anyhow, Error, Result},
2613
axum::async_trait,
2714
ethers::{
2815
abi::RawLog,
29-
contract::{
30-
abigen,
31-
ContractCall,
32-
EthLogDecode,
33-
},
16+
contract::{abigen, ContractCall, EthLogDecode},
3417
core::types::Address,
35-
middleware::{
36-
gas_oracle::GasOracleMiddleware,
37-
MiddlewareError,
38-
SignerMiddleware,
39-
},
40-
prelude::{
41-
BlockId,
42-
JsonRpcClient,
43-
PendingTransaction,
44-
TransactionRequest,
45-
},
46-
providers::{
47-
Http,
48-
Middleware,
49-
Provider,
50-
},
51-
signers::{
52-
LocalWallet,
53-
Signer,
54-
},
55-
types::{
56-
transaction::eip2718::TypedTransaction,
57-
BlockNumber as EthersBlockNumber,
58-
U256,
59-
},
60-
},
61-
sha3::{
62-
Digest,
63-
Keccak256,
18+
middleware::{gas_oracle::GasOracleMiddleware, MiddlewareError, SignerMiddleware},
19+
prelude::{BlockId, JsonRpcClient, PendingTransaction, TransactionRequest},
20+
providers::{Http, Middleware, Provider},
21+
signers::{LocalWallet, Signer},
22+
types::{transaction::eip2718::TypedTransaction, BlockNumber as EthersBlockNumber, U256},
6423
},
24+
sha3::{Digest, Keccak256},
6525
std::sync::Arc,
6626
thiserror::Error,
6727
};
@@ -94,7 +54,7 @@ pub type InstrumentedPythContract = PythRandom<Provider<TracedClient>>;
9454
#[derive(Clone, Debug)]
9555
pub struct LegacyTxMiddleware<M> {
9656
use_legacy_tx: bool,
97-
inner: M,
57+
inner: M,
9858
}
9959

10060
impl<M> LegacyTxMiddleware<M> {
@@ -333,10 +293,10 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
333293
// sequence_number == 0 means the request does not exist.
334294
if r.sequence_number != 0 {
335295
Ok(Some(reader::Request {
336-
provider: r.provider,
296+
provider: r.provider,
337297
sequence_number: r.sequence_number,
338-
block_number: r.block_number.try_into()?,
339-
use_blockhash: r.use_blockhash,
298+
block_number: r.block_number.try_into()?,
299+
use_blockhash: r.use_blockhash,
340300
}))
341301
} else {
342302
Ok(None)
@@ -370,9 +330,9 @@ impl<T: JsonRpcClient + 'static> EntropyReader for PythRandom<Provider<T>> {
370330
Ok(res
371331
.iter()
372332
.map(|r| RequestedWithCallbackEvent {
373-
sequence_number: r.sequence_number,
333+
sequence_number: r.sequence_number,
374334
user_random_number: r.user_random_number,
375-
provider_address: r.request.provider,
335+
provider_address: r.request.provider,
376336
})
377337
.collect())
378338
}

0 commit comments

Comments
 (0)