resolveStellarAddress 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 = checkNotNull(address, "address can not be null");
  if (!addr.contains("*")) {
    throw new 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 new Exception("no federation server found for domain $domain");
  }

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

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