-
Notifications
You must be signed in to change notification settings - Fork 19
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
911db49
commit d28c8a7
Showing
7 changed files
with
96 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use crate::client::NameClient; | ||
use async_trait::async_trait; | ||
use primitives::{ | ||
chain::Chain, | ||
name::{NameProvider, NameRecord}, | ||
}; | ||
use reqwest::Client; | ||
use serde::{Deserialize, Serialize}; | ||
use std::error::Error; | ||
|
||
#[derive(Debug, Deserialize, Serialize)] | ||
pub struct ResolveName { | ||
pub address: String, | ||
} | ||
|
||
pub struct AptosClient { | ||
url: String, | ||
client: Client, | ||
} | ||
|
||
impl AptosClient { | ||
pub fn new(url: String) -> Self { | ||
let client = Client::new(); | ||
Self { url, client } | ||
} | ||
|
||
async fn resolve_name(&self, name: &str) -> Result<String, Box<dyn Error>> { | ||
let url = format!("{}/api/mainnet/v1/address/{}", self.url, name); | ||
let response = self | ||
.client | ||
.get(&url) | ||
.send() | ||
.await? | ||
.json::<ResolveName>() | ||
.await?; | ||
|
||
Ok(response.address) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl NameClient for AptosClient { | ||
fn provider() -> NameProvider { | ||
NameProvider::Aptos | ||
} | ||
|
||
async fn resolve(&self, name: &str, chain: Chain) -> Result<NameRecord, Box<dyn Error>> { | ||
match chain { | ||
Chain::Aptos => { | ||
let address = self.resolve_name(name).await?; | ||
Ok(NameRecord { | ||
name: name.to_string(), | ||
chain, | ||
address, | ||
provider: NameProvider::Ud, //Self::provider(), | ||
}) | ||
} | ||
_ => return Err("error".to_string().into()), | ||
} | ||
} | ||
|
||
fn domains() -> Vec<&'static str> { | ||
vec!["apt"] | ||
} | ||
|
||
fn chains() -> Vec<Chain> { | ||
vec![Chain::Aptos] | ||
} | ||
} |
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,3 +1,4 @@ | ||
pub mod aptos; | ||
pub mod client; | ||
pub mod did; | ||
pub mod ens; | ||
|
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