Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodus committed Nov 12, 2024
1 parent aa1e708 commit e2d45d2
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/budgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use tokio::{

use crate::metrics::METRICS;

#[allow(clippy::upper_case_acronyms)]
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub struct USD(pub NotNan<f64>);

Expand Down
6 changes: 3 additions & 3 deletions src/indexers/cost_models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const COST_MODEL_QUERY_DOCUMENT: &str = r#"
pub enum Error {
/// The request failed.
#[error("request error: {0}")]
RequestError(String),
Request(String),

/// Invalid response.
///
Expand Down Expand Up @@ -50,14 +50,14 @@ pub async fn send_request(
unreachable!("request serialization should not fail")
}
RequestError::RequestSendError(..) | RequestError::ResponseRecvError(..) => {
Error::RequestError(err.to_string())
Error::Request(err.to_string())
}
RequestError::ResponseDeserializationError { .. } => {
Error::InvalidResponse(err.to_string())
}
})?
.map_err(|err| match err {
ResponseError::Failure { .. } => Error::RequestError(err.to_string()),
ResponseError::Failure { .. } => Error::Request(err.to_string()),
ResponseError::Empty => Error::EmptyResponse,
})?;

Expand Down
6 changes: 3 additions & 3 deletions src/indexers/indexing_progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const INDEXING_PROGRESS_QUERY_DOCUMENT: &str = r#"
pub enum Error {
/// The request failed.
#[error("request error: {0}")]
RequestError(String),
Request(String),

/// Invalid response.
///
Expand Down Expand Up @@ -53,14 +53,14 @@ pub async fn send_request(
unreachable!("request serialization should not fail")
}
RequestError::RequestSendError(..) | RequestError::ResponseRecvError(..) => {
Error::RequestError(err.to_string())
Error::Request(err.to_string())
}
RequestError::ResponseDeserializationError { .. } => {
Error::InvalidResponse(err.to_string())
}
})?
.map_err(|err| match err {
ResponseError::Failure { .. } => Error::RequestError(err.to_string()),
ResponseError::Failure { .. } => Error::Request(err.to_string()),
ResponseError::Empty => Error::EmptyResponse,
})?;

Expand Down
6 changes: 3 additions & 3 deletions src/indexers/public_poi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const PUBLIC_PROOF_OF_INDEXING_QUERY_DOCUMENT: &str = r#"
pub enum Error {
/// The request failed.
#[error("request error: {0}")]
RequestError(String),
Request(String),

/// Invalid response.
///
Expand Down Expand Up @@ -94,14 +94,14 @@ pub async fn send_request(
unreachable!("request serialization should not fail")
}
RequestError::RequestSendError(..) | RequestError::ResponseRecvError(..) => {
Error::RequestError(err.to_string())
Error::Request(err.to_string())
}
RequestError::ResponseDeserializationError { .. } => {
Error::InvalidResponse(err.to_string())
}
})?
.map_err(|err| match err {
ResponseError::Failure { .. } => Error::RequestError(err.to_string()),
ResponseError::Failure { .. } => Error::Request(err.to_string()),
ResponseError::Empty => Error::EmptyResponse,
})?;

Expand Down
4 changes: 1 addition & 3 deletions src/network/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ impl From<IndexingError> for ResolutionError {

let reason = match err {
HostResolutionError::InvalidUrl(_) => "invalid indexer URL",
HostResolutionError::DnsResolutionError(_) => {
"indexer URL DNS resolution failed"
}
HostResolutionError::Dns(_) => "indexer URL DNS resolution failed",
HostResolutionError::Timeout => {
"indexer URL DNS resolution failed (timeout)"
}
Expand Down
2 changes: 1 addition & 1 deletion src/network/indexer_host_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum ResolutionError {
///
/// This is a wrapper around [`ResolveError`].
#[error("dns resolution error: {0}")]
DnsResolutionError(#[from] ResolveError),
Dns(#[from] ResolveError),

/// Resolution timed out.
#[error("timeout")]
Expand Down
14 changes: 7 additions & 7 deletions src/receipts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ use thegraph_core::{Address, AllocationId};
#[derive(Debug, Clone)]
pub enum Receipt {
Legacy(u128, Vec<u8>),
TAP(EIP712SignedMessage<TapReceipt>),
Tap(EIP712SignedMessage<TapReceipt>),
}

impl Receipt {
/// Returns the value of the receipt.
pub fn grt_value(&self) -> u128 {
match self {
Receipt::Legacy(value, _) => *value,
Receipt::TAP(receipt) => receipt.message.value,
Receipt::Tap(receipt) => receipt.message.value,
}
}

/// Returns the allocation ID of the receipt.
pub fn allocation(&self) -> Address {
match self {
Receipt::Legacy(_, receipt) => Address::from_slice(&receipt[0..20]),
Receipt::TAP(receipt) => receipt.message.allocation_id,
Receipt::Tap(receipt) => receipt.message.allocation_id,
}
}

Expand All @@ -40,7 +40,7 @@ impl Receipt {
pub fn serialize(&self) -> String {
match self {
Receipt::Legacy(_, receipt) => hex::encode(&receipt[..(receipt.len() - 32)]),
Receipt::TAP(receipt) => serde_json::to_string(&receipt).unwrap(),
Receipt::Tap(receipt) => serde_json::to_string(&receipt).unwrap(),
}
}

Expand All @@ -49,7 +49,7 @@ impl Receipt {
pub fn header_name(&self) -> &'static str {
match self {
Receipt::Legacy(_, _) => "Scalar-Receipt",
Receipt::TAP(_) => "Tap-Receipt",
Receipt::Tap(_) => "Tap-Receipt",
}
}
}
Expand Down Expand Up @@ -187,7 +187,7 @@ impl ReceiptSigner {

/// Creates a new Scalar TAP receipt for the given allocation and fee.
pub fn create_receipt(&self, allocation: AllocationId, fee: u128) -> anyhow::Result<Receipt> {
self.tap.create_receipt(allocation, fee).map(Receipt::TAP)
self.tap.create_receipt(allocation, fee).map(Receipt::Tap)
}

/// Creates a new Scalar legacy receipt for the given allocation and fee.
Expand Down Expand Up @@ -352,6 +352,6 @@ mod tests {

//* Then
let receipt = res.expect("failed to create tap receipt");
assert!(matches!(receipt, Receipt::TAP(_)));
assert!(matches!(receipt, Receipt::Tap(_)));
}
}

0 comments on commit e2d45d2

Please sign in to comment.