-
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.
- Loading branch information
1 parent
f1a0eb1
commit ff4f9d1
Showing
8 changed files
with
98 additions
and
11 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 |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod ud; | |
pub mod sns; | ||
pub mod ton; | ||
pub mod tree; | ||
pub mod spaceid; |
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,63 @@ | ||
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 code: i32, | ||
pub address: String, | ||
} | ||
|
||
pub struct SpaceIdClient { | ||
api_url: String, | ||
client: Client, | ||
} | ||
|
||
impl SpaceIdClient { | ||
pub fn new(api_url: String) -> Self { | ||
let client = Client::new(); | ||
Self { | ||
api_url, | ||
client, | ||
} | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl NameClient for SpaceIdClient { | ||
|
||
fn provider() -> NameProvider { | ||
NameProvider::SpaceId | ||
} | ||
|
||
async fn resolve(&self, name: &str, chain: Chain) -> Result<NameRecord, Box<dyn Error>> { | ||
let tld = name.split('.').clone().last().unwrap_or_default(); | ||
let url = format!("{}/v1/getAddress?tld={}&domain={}", self.api_url, tld, name); | ||
let record: ResolveRecord = self.client.get(&url).send().await?.json().await?; | ||
if record.code != 0 { | ||
return Err("SpaceIdClient: code != 0".into()); | ||
} | ||
let address = record.address; | ||
|
||
Ok(NameRecord { name: name.to_string(), chain, address, provider: Self::provider() }) | ||
} | ||
|
||
fn domains() -> Vec<&'static str> { | ||
vec![ | ||
"bnb", | ||
"arb", | ||
] | ||
} | ||
|
||
fn chains() -> Vec<Chain> { | ||
vec![ | ||
Chain::SmartChain, | ||
Chain::Arbitrum, | ||
] | ||
} | ||
} |
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