serializeV0 static method

List<int> serializeV0(
  1. MessageV0 message
)

serialize message V0 to bytes

Implementation

static List<int> serializeV0(MessageV0 message) {
  final encodedStaticAccountKeysLength =
      SolanaTransactionUtils._encodeLength(message.accountKeys.length);
  final serializedInstructions =
      serializeInstructionsV0(message.compiledInstructions);
  final encodedInstructionsLength = SolanaTransactionUtils._encodeLength(
      message.compiledInstructions.length);
  final serializedAddressTableLookups =
      serializeAddressTableLookups(message.addressTableLookups);
  final encodedAddressTableLookupsLength =
      SolanaTransactionUtils._encodeLength(
          message.addressTableLookups.length);
  final messageLayout = LayoutConst.struct([
    LayoutConst.u8(property: 'prefix'),
    LayoutConst.struct([
      LayoutConst.u8(property: 'numRequiredSignatures'),
      LayoutConst.u8(property: 'numReadonlySignedAccounts'),
      LayoutConst.u8(property: 'numReadonlyUnsignedAccounts')
    ], property: 'header'),
    LayoutConst.blob(encodedStaticAccountKeysLength.length,
        property: 'staticAccountKeysLength'),
    LayoutConst.array(
        SolanaLayoutUtils.publicKey(), message.accountKeys.length,
        property: 'staticAccountKeys'),
    SolanaLayoutUtils.publicKey('recentBlockhash'),
    LayoutConst.blob(encodedInstructionsLength.length,
        property: 'instructionsLength'),
    LayoutConst.blob(serializedInstructions.length,
        property: 'serializedInstructions'),
    LayoutConst.blob(encodedAddressTableLookupsLength.length,
        property: 'addressTableLookupsLength'),
    LayoutConst.blob(serializedAddressTableLookups.length,
        property: 'serializedAddressTableLookups')
  ]);
  const messageVersion0Prefix = 1 << 7;
  return messageLayout.serialize({
    'prefix': messageVersion0Prefix,
    'header': message.header.toJson(),
    'staticAccountKeysLength': encodedStaticAccountKeysLength,
    'staticAccountKeys': message.accountKeys.map((key) => key).toList(),
    'recentBlockhash': message.recentBlockhash,
    'instructionsLength': encodedInstructionsLength,
    'serializedInstructions': serializedInstructions,
    'addressTableLookupsLength': encodedAddressTableLookupsLength,
    'serializedAddressTableLookups': serializedAddressTableLookups
  });
}