reallocNameAccount static method

Future<TransactionInstruction> reallocNameAccount({
  1. required SolanaRPC rpc,
  2. required String name,
  3. required int space,
  4. required SolAddress payerKey,
  5. SolAddress? nameClass,
  6. SolAddress? nameParent,
})

Realloc the name account space.

Implementation

static Future<TransactionInstruction> reallocNameAccount({
  /// The solana connection object to the RPC node
  required SolanaRPC rpc,

  /// The name of the name account
  required String name,

  /// The new space to be allocated
  required int space,

  /// The allocation cost payer if new space is larger than current or the refund destination if smaller
  required SolAddress payerKey,

  /// The class of this name, if it exsists
  SolAddress? nameClass,

  /// The parent name of this name, if it exists
  SolAddress? nameParent,
}) async {
  final hashedName = NameServiceProgramUtils.getHashedName(name);
  final nameAccountKey = NameServiceProgramUtils.getNameAccountProgram(
    hashedName: hashedName,
    nameClass: nameClass,
    nameParent: nameParent,
  );

  SolAddress? nameOwner = nameClass;
  if (nameOwner == null) {
    final account = await rpc
        .request(SolanaRPCNameRegistryAccount(account: nameAccountKey));
    if (account == null) {
      throw const MessageException("Account not found.");
    }
    nameOwner = account.owner;
  }

  return NameServiceProgram.realloc(
    payerKey: payerKey,
    nameAccountKey: nameAccountKey,
    nameOwnerKey: nameOwner,
    layout: NameServiceReallocLayout(space: space),
  );
}