use crate::api::FullnodeClient;
use crate::error::{AptosError, AptosResult};
use crate::types::AccountAddress;
#[derive(Debug, Clone)]
pub struct AnsClient {
#[allow(dead_code)] fullnode: FullnodeClient,
}
impl AnsClient {
#[must_use]
pub fn new(fullnode: FullnodeClient) -> Self {
Self { fullnode }
}
pub async fn lookup(&self, _name: &str) -> AptosResult<AccountAddress> {
Err(AptosError::Internal(
"ANS lookup is not yet implemented in the Rust SDK (tracked as an audit \
follow-up); use the on-chain `0x...::router::get_address` view \
function directly for now"
.to_string(),
))
}
pub async fn reverse_lookup(&self, _address: AccountAddress) -> AptosResult<Option<String>> {
Err(AptosError::Internal(
"ANS reverse lookup is not yet implemented in the Rust SDK \
(tracked as an audit follow-up)"
.to_string(),
))
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::config::AptosConfig;
#[tokio::test]
async fn lookup_is_unsupported() {
let fullnode = FullnodeClient::new(AptosConfig::testnet()).unwrap();
let ans = AnsClient::new(fullnode);
let err = ans.lookup("alice.apt").await.unwrap_err();
assert!(matches!(err, AptosError::Internal(_)));
}
#[tokio::test]
async fn reverse_lookup_is_unsupported() {
let fullnode = FullnodeClient::new(AptosConfig::testnet()).unwrap();
let ans = AnsClient::new(fullnode);
let err = ans.reverse_lookup(AccountAddress::ONE).await.unwrap_err();
assert!(matches!(err, AptosError::Internal(_)));
}
}