deserialize static method

AddressLookupTableState deserialize(
  1. ByteArray accountData
)

Implementation

static AddressLookupTableState deserialize(ByteArray accountData) {
  final input = Uint8List.fromList(accountData.toList());
  final reader = BinaryReader(input.buffer.asByteData());

  final typeIndex = reader.readU32();

  if (typeIndex != 1) {
    throw Exception(
      'invalid account data; account type mismatch $typeIndex != 1',
    );
  }

  final deactivationSlot = reader.readU64();
  final lastExtendedSlot = reader.readU64();
  final lastExtendedStartIndex = reader.readU8();
  reader.readU8();
  final authority = reader
      .readFixedArray(
        1,
        () => reader.readFixedArray(32, reader.readU8),
      )
      .map(Ed25519HDPublicKey.new)
      .toList();

  final int serializedAddressesLen =
      accountData.length - _lookupTableMetaSize;
  assert(serializedAddressesLen >= 0, 'lookup table is invalid');
  assert(serializedAddressesLen % 32 == 0, 'lookup table is invalid');

  final int numSerializedAddresses = serializedAddressesLen ~/ 32;

  final addressReader =
      BinaryReader(input.sublist(_lookupTableMetaSize).buffer.asByteData());

  final addresses = addressReader
      .readFixedArray(
        numSerializedAddresses,
        () => addressReader.readFixedArray(32, addressReader.readU8),
      )
      .map(Ed25519HDPublicKey.new)
      .toList();

  return AddressLookupTableState(
    deactivationSlot: deactivationSlot,
    lastExtendedSlot: lastExtendedSlot.toInt(),
    lastExtendedSlotStartIndex: lastExtendedStartIndex,
    authority: authority.isNotEmpty ? authority.first : null,
    addresses: addresses,
  );
}