serializeAddressTableLookups static method

List<int> serializeAddressTableLookups(
  1. List<AddressTableLookup> addressTableLookups
)

serialize address table

Implementation

static List<int> serializeAddressTableLookups(
    List<AddressTableLookup> addressTableLookups) {
  var serializedLength = 0;
  final serializedAddressTableLookups =
      LayoutByteWriter.filled(SolanaTransactionConstant.packetDataSize, 0);
  for (var lookup in addressTableLookups) {
    final encodedWritableIndexesLength =
        SolanaTransactionUtils._encodeLength(lookup.writableIndexes.length);
    final encodedReadonlyIndexesLength =
        SolanaTransactionUtils._encodeLength(lookup.readonlyIndexes.length);

    final addressTableLookupLayout = LayoutUtils.struct([
      LayoutUtils.publicKey('accountKey'),
      LayoutUtils.blob(encodedWritableIndexesLength.length,
          property: 'encodedWritableIndexesLength'),
      LayoutUtils.array(LayoutUtils.u8(), lookup.writableIndexes.length,
          property: 'writableIndexes'),
      LayoutUtils.blob(encodedReadonlyIndexesLength.length,
          property: 'encodedReadonlyIndexesLength'),
      LayoutUtils.array(LayoutUtils.u8(), lookup.readonlyIndexes.length,
          property: 'readonlyIndexes')
    ]);
    serializedLength += addressTableLookupLayout.encode({
      'accountKey': lookup.accountKey,
      'encodedWritableIndexesLength': encodedWritableIndexesLength,
      'writableIndexes': lookup.writableIndexes,
      'encodedReadonlyIndexesLength': encodedReadonlyIndexesLength,
      'readonlyIndexes': lookup.readonlyIndexes
    }, serializedAddressTableLookups, offset: serializedLength);
  }
  return serializedAddressTableLookups.toBytes().sublist(0, serializedLength);
}