Skip to content
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
1,635 changes: 909 additions & 726 deletions multichain-aggregator/Cargo.lock

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions multichain-aggregator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ multichain-aggregator-entity = { path = "./multichain-aggregator-entity" }
multichain-aggregator-logic = { path = "./multichain-aggregator-logic" }
multichain-aggregator-migration = { path = "./multichain-aggregator-migration" }
multichain-aggregator-proto = { path = "./multichain-aggregator-proto" }
bens-proto = { git = "https://github.com/blockscout/blockscout-rs", rev = "741fc40" }

# web
actix-prost = { version = "0.1.0" }
actix-prost-build = { version = "0.1.0", features = [
"conversions",
] }
actix-prost-build = { version = "0.1.0" }
actix-prost-macros = { version = "0.1.0" }
actix-web = "4.2"
blockscout-service-launcher = { version = "0.17.0", features = [
"database-1_0",
] }
blockscout-service-launcher = { version = "0.19.0", features = ["database-1"] }
prost = "0.13"
prost-build = "0.13"
prost-wkt = "0.6.0"
prost-wkt-types = "0.6.0"
prost-wkt-build = "0.6.0"
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }
tonic = "0.12"
tonic-build = "0.12"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2021"
[dependencies]
multichain-aggregator-entity = { workspace = true }
multichain-aggregator-proto = { workspace = true }
bens-proto = { workspace = true }
anyhow = { workspace = true }
api-client-framework = { workspace = true }
blockscout-chains = { workspace = true }
Expand Down
101 changes: 101 additions & 0 deletions multichain-aggregator/multichain-aggregator-logic/src/clients/bens.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
use api_client_framework::{Endpoint, Error, HttpApiClient as Client, HttpApiClientConfig};
use reqwest::Method;
use url::Url;

pub fn new_client(url: Url) -> Result<Client, Error> {
let config = HttpApiClientConfig::default();
Client::new(url, config)
}

pub mod lookup_domain_name {
use super::*;
use api_client_framework::serialize_query;
use bens_proto::blockscout::bens::v1::{
LookupDomainNameRequest, LookupDomainNameResponse, Order,
};
use serde::Serialize;

pub struct LookupDomainName {
pub request: LookupDomainNameRequest,
}

impl Endpoint for LookupDomainName {
type Response = LookupDomainNameResponse;

fn method(&self) -> Method {
Method::GET
}

fn path(&self) -> String {
format!("/api/v1/{}/domains:lookup", self.request.chain_id)
}

fn query(&self) -> Option<String> {
#[derive(Serialize)]
pub struct Params<'a> {
pub name: Option<&'a String>,
pub chain_id: i64,
pub only_active: bool,
pub sort: &'a String,
pub order: Order,
pub page_size: Option<u32>,
pub page_token: Option<&'a String>,
pub protocols: Option<&'a String>,
}

let params = Params {
name: self.request.name.as_ref(),
chain_id: self.request.chain_id,
only_active: self.request.only_active,
sort: &self.request.sort,
order: self
.request
.order
.try_into()
.expect("valid order enum should be provided"),
page_size: self.request.page_size,
page_token: self.request.page_token.as_ref(),
protocols: self.request.protocols.as_ref(),
};
serialize_query(&params)
}
}
}
Comment thread
lok52 marked this conversation as resolved.

pub mod get_address {
use super::*;
use api_client_framework::serialize_query;
use bens_proto::blockscout::bens::v1::{GetAddressRequest, GetAddressResponse};
use serde::Serialize;

pub struct GetAddress {
pub request: GetAddressRequest,
}

impl Endpoint for GetAddress {
type Response = GetAddressResponse;

fn method(&self) -> Method {
Method::GET
}

fn path(&self) -> String {
format!(
"/api/v1/{}/addresses/{}",
self.request.chain_id, self.request.address
)
}

fn query(&self) -> Option<String> {
#[derive(Serialize)]
pub struct Params<'a> {
pub protocol_id: Option<&'a String>,
}

let params = Params {
protocol_id: self.request.protocol_id.as_ref(),
};
serialize_query(&params)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod bens;
pub mod dapp;
pub mod token_info;
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum ParseError {
ParseUuid(#[from] uuid::Error),
#[error("parse error: invalid slice")]
TryFromSlice(#[from] core::array::TryFromSliceError),
#[error("parse error: invalid json")]
Json(#[from] serde_json::Error),
#[error("parse error: {0}")]
Custom(String),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ where

pub async fn list<C>(
db: &C,
address: Option<AddressAlloy>,
addresses: Vec<AddressAlloy>,
contract_name_query: Option<String>,
chain_ids: Option<Vec<ChainId>>,
chain_ids: Vec<ChainId>,
token_types: Option<Vec<db_enum::TokenType>>,
page_size: u64,
page_token: Option<(AddressAlloy, ChainId)>,
Expand All @@ -213,21 +213,32 @@ where
let base_select = QuerySelect::query(&mut Entity::find())
.from_clear()
.from(addresses_cte_iden)
.apply_if(chain_ids, |q, chain_ids| {
if !chain_ids.is_empty() {
.apply_if(
(!chain_ids.is_empty()).then_some(chain_ids),
|q, chain_ids| {
q.and_where(Column::ChainId.is_in(chain_ids));
}
})
},
)
.apply_if(token_types, |q, token_types| {
if !token_types.is_empty() {
q.and_where(Column::TokenType.is_in(token_types));
} else {
q.and_where(Column::TokenType.is_null());
}
})
.apply_if(address, |q, address| {
q.and_where(Column::Hash.eq(address.as_slice()));
})
.apply_if(
(!addresses.is_empty()).then_some(addresses),
|q, addresses| {
q.and_where(
Column::Hash.is_in(
addresses
.into_iter()
.map(|a| a.to_vec())
.collect::<Vec<_>>(),
),
);
},
)
.apply_if(page_token, |q, page_token| {
q.and_where(
Expr::tuple([
Expand Down
Loading