mintAptosSubdomain method

Future mintAptosSubdomain(
  1. AptosAccount account,
  2. String subdomainName,
  3. String domainName, {
  4. int? expirationTimestampSeconds,
  5. BigInt? maxGasAmount,
  6. BigInt? gasUnitPrice,
  7. BigInt? expireTimestamp,
})

Mint a new Aptos Subdomain.

account AptosAccount the owner of the domain name. subdomainName subdomain name to mint. domainName Aptos domain name to mint under. expirationTimestampSeconds must be set between the domains expiration and the current time. Return the hash of the pending transaction submitted to the API.

Implementation

Future<dynamic> mintAptosSubdomain(
  AptosAccount account,
  String subdomainName,
  String domainName,{
  int? expirationTimestampSeconds,
  BigInt? maxGasAmount,
  BigInt? gasUnitPrice,
  BigInt? expireTimestamp
}) async {
  // check if the domainName is valid
  if (!nameComponentPattern.hasMatch(domainName)) {
    throw ArgumentError("Domain name $domainName is not valid");
  }
  // check if the subdomainName is valid
  if (!nameComponentPattern.hasMatch(subdomainName)) {
    throw ArgumentError("Subdomain name $subdomainName is not valid");
  }
  // check if the name is available
  final subdomainRegistration = await getRegistrationForSubdomainName(domainName, subdomainName);
  if (subdomainRegistration != null) {
    final now = (DateTime.now().millisecondsSinceEpoch / 1000).ceil();
    if (now < subdomainRegistration.$2) {
      throw ArgumentError("Name $subdomainName.$domainName is not available");
    }
  }

  final domainRegistration = await getRegistrationForDomainName(domainName);
  if (domainRegistration == null) {
    throw ArgumentError("Domain name $domainName does not exist");
  }
  final now = (DateTime.now().millisecondsSinceEpoch / 1000).ceil();
  if (domainRegistration.$2 < now) {
    throw ArgumentError("Domain name $domainName expired");
  }

  final actualExpirationTimestampSeconds =
    expirationTimestampSeconds ?? domainRegistration.$2;
  if (actualExpirationTimestampSeconds < now) {
    throw ArgumentError("Expiration for $subdomainName.$domainName is before now");
  }

  final buildConfig = ABIBuilderConfig(
    sender: account.address,
    maxGasAmount: maxGasAmount,
    gasUnitPrice: gasUnitPrice,
    expSecFromNow: expireTimestamp
  );
  final builder = TransactionBuilderRemoteABI(aptosClient, buildConfig);
  final rawTxn = await builder.build(
    "$contractAddress::domains::register_subdomain",
    [],
    [subdomainName, domainName, actualExpirationTimestampSeconds]
  );

  final bcsTxn = AptosClient.generateBCSTransaction(account, rawTxn);
  final pendingTransaction = await aptosClient.submitSignedBCSTransaction(bcsTxn);

  return pendingTransaction["hash"];
}