-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update client.rs * Create tree.rs * Update lib.rs * Update Cargo.toml * Update Settings.toml * Update lib.rs * Complete tree integration * Update tree.rs --------- Co-authored-by: timdegen <104884878+timdegen@users.noreply.github.com>
- Loading branch information
1 parent
b71302c
commit f1a0eb1
Showing
7 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ pub mod ens; | |
pub mod ud; | ||
pub mod sns; | ||
pub mod ton; | ||
pub mod tree; |
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,58 @@ | ||
use primitives::chain::Chain; | ||
use reqwest::Client; | ||
use serde::{Deserialize, Serialize}; | ||
use async_trait::async_trait; | ||
use std::{error::Error}; | ||
|
||
use primitives::name::{NameRecord, NameProvider}; | ||
use crate::client::NameClient; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct ResolveRecord { | ||
pub owner: String, | ||
} | ||
|
||
pub struct TreeClient { | ||
api_url: String, | ||
client: Client, | ||
} | ||
|
||
impl TreeClient { | ||
pub fn new(api_url: String) -> Self { | ||
let client = Client::new(); | ||
Self { | ||
api_url, | ||
client, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl NameClient for TreeClient { | ||
|
||
fn provider() -> NameProvider { | ||
NameProvider::Tree | ||
} | ||
|
||
async fn resolve(&self, name: &str, chain: Chain) -> Result<NameRecord, Box<dyn Error>> { | ||
let url = format!("{}/resolve/{}", self.api_url, name); | ||
let record: ResolveRecord = self.client.get(&url).send().await?.json().await?; | ||
let address = record.owner; | ||
|
||
Ok(NameRecord { name: name.to_string(), chain, address, provider: Self::provider() }) | ||
} | ||
|
||
fn domains() -> Vec<&'static str> { | ||
vec![ | ||
"tree" | ||
] | ||
} | ||
|
||
fn chains() -> Vec<Chain> { | ||
vec![ | ||
Chain::Ethereum, | ||
Chain::Polygon, | ||
Chain::SmartChain, | ||
] | ||
} | ||
} |
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