isAccountWritable method

bool isAccountWritable({
  1. required int index,
  2. required int numStaticAccountKeys,
  3. List<AddressTableLookup> addressTableLookups = const [],
})

Implementation

bool isAccountWritable(
    {required int index,
    required int numStaticAccountKeys,
    List<AddressTableLookup> addressTableLookups = const []}) {
  if (index >= numStaticAccountKeys) {
    if (addressTableLookups.isEmpty) {
      throw MessageException(
          "Invalid index. The index must be lower than numStaticAccountKeys.");
    }
    final lookupAccountKeysIndex = index - numStaticAccountKeys;
    final numWritableLookupAccountKeys = addressTableLookups.fold<int>(
        0, (count, lookup) => count + lookup.writableIndexes.length);
    return lookupAccountKeysIndex < numWritableLookupAccountKeys;
  } else if (index >= numRequiredSignatures) {
    final unsignedAccountIndex = index - numRequiredSignatures;
    final numUnsignedAccounts = numStaticAccountKeys - numRequiredSignatures;
    final numWritableUnsignedAccounts =
        numUnsignedAccounts - numReadonlyUnsignedAccounts;
    return unsignedAccountIndex < numWritableUnsignedAccounts;
  } else {
    final numWritableSignedAccounts =
        numRequiredSignatures - numReadonlySignedAccounts;
    return index < numWritableSignedAccounts;
  }
}