-
Notifications
You must be signed in to change notification settings - Fork 139
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
196 additions
and
16 deletions.
There are no files selected for viewing
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
multichain-aggregator/multichain-aggregator-logic/src/clients/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod dapp; | ||
pub mod token_info; |
64 changes: 64 additions & 0 deletions
64
multichain-aggregator/multichain-aggregator-logic/src/clients/token_info.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::{error::ServiceError, ChainId}; | ||
use serde::Deserialize; | ||
use url::Url; | ||
|
||
pub struct TokenInfoClient { | ||
http: reqwest::Client, | ||
url: Url, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
#[serde(rename_all = "camelCase")] | ||
pub struct TokenInfo { | ||
pub token_address: String, | ||
pub chain_id: String, | ||
pub icon_url: String, | ||
pub token_name: Option<String>, | ||
pub token_symbol: Option<String>, | ||
} | ||
|
||
#[derive(Debug, Deserialize)] | ||
pub struct TokenInfoSearchResponse { | ||
pub token_infos: Vec<TokenInfo>, | ||
pub next_page_params: Option<String>, | ||
} | ||
|
||
impl TokenInfoClient { | ||
pub fn new(url: Url) -> Self { | ||
let http = reqwest::Client::new(); | ||
Self { http, url } | ||
} | ||
|
||
pub async fn search_tokens( | ||
&self, | ||
query: &str, | ||
chain_id: Option<ChainId>, | ||
page_size: Option<u32>, | ||
page_token: Option<String>, | ||
) -> Result<TokenInfoSearchResponse, ServiceError> { | ||
let mut url = self.url.clone(); | ||
url.set_path("/api/v1/token-infos:search"); | ||
url.query_pairs_mut().append_pair("query", query); | ||
|
||
if let Some(chain_id) = chain_id { | ||
url.query_pairs_mut() | ||
.append_pair("chain_id", &chain_id.to_string()); | ||
} | ||
if let Some(page_size) = page_size { | ||
url.query_pairs_mut() | ||
.append_pair("page_size", &page_size.to_string()); | ||
} | ||
if let Some(page_token) = page_token { | ||
url.query_pairs_mut().append_pair("page_token", &page_token); | ||
} | ||
|
||
self.http | ||
.get(url) | ||
.send() | ||
.await | ||
.map_err(|e| ServiceError::Internal(e.into()))? | ||
.json::<TokenInfoSearchResponse>() | ||
.await | ||
.map_err(|e| ServiceError::Internal(e.into())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
pub mod api_key_manager; | ||
pub mod dapp_client; | ||
pub mod clients; | ||
pub mod error; | ||
mod import; | ||
mod proto; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
multichain-aggregator/multichain-aggregator-logic/src/types/dapp.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,5 @@ pub mod chains; | |
pub mod dapp; | ||
pub mod hashes; | ||
pub mod search_results; | ||
pub mod token_info; | ||
pub type ChainId = i64; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
multichain-aggregator/multichain-aggregator-logic/src/types/token_info.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::ChainId; | ||
use crate::{clients, error::ParseError, proto}; | ||
|
||
#[derive(Debug)] | ||
pub struct Token { | ||
pub address: alloy_primitives::Address, | ||
pub icon_url: String, | ||
pub name: String, | ||
pub symbol: String, | ||
pub chain_id: ChainId, | ||
} | ||
|
||
impl TryFrom<clients::token_info::TokenInfo> for Token { | ||
type Error = ParseError; | ||
|
||
fn try_from(v: clients::token_info::TokenInfo) -> Result<Self, Self::Error> { | ||
Ok(Self { | ||
address: v.token_address.parse().map_err(ParseError::from)?, | ||
icon_url: v.icon_url, | ||
name: v | ||
.token_name | ||
.ok_or_else(|| ParseError::Custom("token name is required".to_string()))?, | ||
symbol: v | ||
.token_symbol | ||
.ok_or_else(|| ParseError::Custom("token symbol is required".to_string()))?, | ||
chain_id: v.chain_id.parse().map_err(ParseError::from)?, | ||
}) | ||
} | ||
} | ||
|
||
impl From<Token> for proto::Token { | ||
fn from(v: Token) -> Self { | ||
Self { | ||
address: v.address.to_string(), | ||
name: v.name, | ||
symbol: v.symbol, | ||
icon_url: v.icon_url, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters