serializeAddressTableLookups static method

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

serialize address table

Implementation

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

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