isAccountWritable method
bool
isAccountWritable({
- required int index,
- required int numStaticAccountKeys,
- 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;
}
}