resolveStellarAddress static method

Future<FederationResponse> resolveStellarAddress(
  1. String address
)

Resolves a stellar address such as bob*soneso.com. Returns a FederationResponse object.

Implementation

static Future<FederationResponse> resolveStellarAddress(String address) async {
  String addr = address;
  if (!addr.contains("*")) {
    throw Exception("invalid federation address: $addr");
  }

  String domain = addr.split("*").last;
  StellarToml toml = await StellarToml.fromDomain(domain);
  String? federationServer = toml.generalInformation.federationServer;
  if (federationServer == null) {
    throw Exception("no federation server found for domain $domain");
  }

  Uri serverURI = Uri.parse(federationServer);
  http.Client httpClient = http.Client();

  _FederationRequestBuilder requestBuilder = _FederationRequestBuilder(httpClient, serverURI);
  FederationResponse response =
      await requestBuilder.forStringToLookUp(addr).forType("name").execute();
  return response;
}