Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

ci: add cargo fmt #12

Merged
merged 2 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: tests

on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
fmt:
name: cargo fmt
runs-on: ubuntu-latest
container:
image: rust:latest
steps:
- uses: actions/checkout@v3
- run: |
rustup component add rustfmt
cargo fmt --all -- --check
5 changes: 2 additions & 3 deletions native/src/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use super::*;
use eip_712_derive::{
sign_typed, Bytes32, DomainSeparator, Eip712Domain, MemberVisitor, StructType, U256,
};
use std::convert::TryInto;
use secp256k1::SecretKey;
use std::convert::TryInto;

pub struct AttestationSigner {
subgraph_deployment_id: Bytes32,
Expand All @@ -18,9 +18,8 @@ impl AttestationSigner {
signer: SecretKey,
subgraph_deployment_id: Bytes32,
) -> Self {

let bytes = hex::decode("a070ffb1cd7409649bf77822cce74495468e06dbfaef09556838bf188679b9c2")
.unwrap();
.unwrap();

let salt: [u8; 32] = bytes.try_into().unwrap();

Expand Down
5 changes: 2 additions & 3 deletions service/src/common/address.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ethers::signers::{Wallet, WalletError, LocalWallet, MnemonicBuilder, coins_bip39::English};
use ethers_core::{utils::hex, k256::ecdsa::SigningKey};
use ethers::signers::{coins_bip39::English, LocalWallet, MnemonicBuilder, Wallet, WalletError};
use ethers_core::{k256::ecdsa::SigningKey, utils::hex};
use sha3::{Digest, Keccak256};

/// A normalized address in checksum format.
Expand All @@ -12,7 +12,6 @@ pub fn to_address(s: impl AsRef<str>) -> Address {
hex::encode(hash)
}


/// Build Wallet from Private key or Mnemonic
pub fn build_wallet(value: &str) -> Result<Wallet<SigningKey>, WalletError> {
value
Expand Down
6 changes: 4 additions & 2 deletions service/src/common/database.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use diesel::pg::PgConnection;
use diesel::prelude::*;
use diesel::r2d2::{ConnectionManager, Pool};
use dotenvy::dotenv;
use std::env;
use diesel::r2d2::{ConnectionManager, Pool};
use std::sync::{Arc, RwLock};

pub type PgPool = Pool<ConnectionManager<PgConnection>>;
Expand All @@ -17,5 +17,7 @@ pub fn establish_connection() -> PgConnection {

pub(crate) fn create_pg_pool(database_url: &str) -> PgPool {
let manager = ConnectionManager::<PgConnection>::new(database_url);
Pool::builder().build(manager).expect("Failed to create pool")
Pool::builder()
.build(manager)
.expect("Failed to create pool")
}
38 changes: 22 additions & 16 deletions service/src/common/indexer_error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::{fmt::{self, Display}, error::Error};

use std::{
error::Error,
fmt::{self, Display},
};

const ERROR_BASE_URL: &str = "https://github.com/graphprotocol/indexer/blob/main/docs/errors.md";

Expand Down Expand Up @@ -228,7 +230,9 @@ impl IndexerErrorCode {
Self::IE061 => "Failed to allocate: Invalid allocation amount provided'",
Self::IE062 => "Did not receive tx receipt, not authorized or network paused'",
Self::IE063 => "No active allocation with provided id found'",
Self::IE064 => "Failed to unallocate: Allocation cannot be closed in the same epoch it was created",
Self::IE064 => {
"Failed to unallocate: Allocation cannot be closed in the same epoch it was created"
}
Self::IE065 => "Failed to unallocate: Allocation has already been closed'",
Self::IE066 => "Failed to allocate: allocation ID already exists on chain'",
Self::IE067 => "Failed to query POI for current epoch start block'",
Expand All @@ -249,7 +253,6 @@ impl IndexerErrorCode {

// pub type IndexerErrorCause = Box<dyn std::error::Error + Send + Sync>;


#[derive(Debug)]
pub struct IndexerErrorCause(Box<dyn Error + Send + Sync>);

Expand All @@ -276,7 +279,10 @@ impl Error for IndexerErrorCause {

impl From<String> for IndexerErrorCause {
fn from(error: String) -> Self {
Self(Box::new(std::io::Error::new(std::io::ErrorKind::Other, error)))
Self(Box::new(std::io::Error::new(
std::io::ErrorKind::Other,
error,
)))
}
}

Expand Down Expand Up @@ -322,15 +328,15 @@ pub fn indexer_error(code: IndexerErrorCode) -> IndexerError {
}

impl std::fmt::Display for IndexerError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Indexer error: {}, explanation: {}",
self.code, self.explanation
)?;
if let Some(cause) = &self.cause {
write!(f, ", cause: {:?}", cause)?;
}
Ok(())
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"Indexer error: {}, explanation: {}",
self.code, self.explanation
)?;
if let Some(cause) = &self.cause {
write!(f, ", cause: {:?}", cause)?;
}
Ok(())
}
}
2 changes: 1 addition & 1 deletion service/src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod database;
pub mod address;
pub mod database;
pub mod indexer_error;
// pub mod query_fee_models;
// pub mod schema;
21 changes: 14 additions & 7 deletions service/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use std::collections::HashSet;
use autometrics::autometrics;
use clap::{command, error::ErrorKind, Args, CommandFactory, Parser, ValueEnum};
use ethers::signers::WalletError;
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use tracing::{debug, info};
use ethers::signers::WalletError;
use clap::{Args, Parser, CommandFactory, command, ValueEnum, error::ErrorKind};

use crate::{common::address::build_wallet, util::{init_tracing, wallet_address}, query_processor::QueryError};
use crate::{
common::address::build_wallet,
query_processor::QueryError,
util::{init_tracing, wallet_address},
};

#[derive(Clone, Debug, Parser, Serialize, Deserialize, Default)]
#[clap(
Expand Down Expand Up @@ -236,11 +240,14 @@ impl Cli {
pub fn args() -> Self {
// TODO: load config file before parse
let cli = Cli::parse();
if let Some(path) = cli.input_file.clone(){
if let Some(path) = cli.input_file.clone() {
let loaded_cli = confy::load_path::<Cli>(path);
println!("loaded cli, not used, but may later be used by overwriting cli arguments: {:#?}", loaded_cli);
println!(
"loaded cli, not used, but may later be used by overwriting cli arguments: {:#?}",
loaded_cli
);
};

// Enables tracing under RUST_LOG variable
// std::env::set_var("RUST_LOG", cli.log_level.clone());
init_tracing(String::from("pretty")).expect("Could not set up global default subscriber for logger, check environmental variable `RUST_LOG` or the CLI input `log-level`");
Expand Down
4 changes: 2 additions & 2 deletions service/src/graph_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl GraphNodeInstance {
let response = request.send().await?.text().await?;
Ok(UnattestedQueryResult {
graphQLResponse: response,
attestable: true
attestable: true,
})
}

Expand All @@ -65,4 +65,4 @@ impl GraphNodeInstance {
attestable: false,
})
}
}
}
14 changes: 11 additions & 3 deletions service/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@ use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
use util::package_version;
use uuid::Uuid;

use crate::{query_processor::{FreeQuery, QueryProcessor, SubgraphDeploymentID}, config::Cli, metrics::handle_serve_metrics, util::public_key};
use crate::{
config::Cli,
metrics::handle_serve_metrics,
query_processor::{FreeQuery, QueryProcessor, SubgraphDeploymentID},
util::public_key,
};
// use server::{ServerOptions, index, subgraph_queries, network_queries};
use common::database::create_pg_pool;
use server::{routes, ServerOptions};

mod common;
mod config;
mod graph_node;
mod metrics;
mod model;
mod query_fee;
mod query_processor;
mod server;
mod util;
mod metrics;

/// Create Indexer service App
///
Expand Down Expand Up @@ -63,7 +68,10 @@ async fn main() -> Result<(), std::io::Error> {
);

// Start indexer service basic metrics
tokio::spawn(handle_serve_metrics(String::from("http://0.0.0.0"), config.indexer_infrastructure.metrics_port));
tokio::spawn(handle_serve_metrics(
String::from("http://0.0.0.0"),
config.indexer_infrastructure.metrics_port,
));
let service_options = ServerOptions::new(
Some(config.indexer_infrastructure.port),
release,
Expand Down
Loading