serializeTransaction static method

List<int> serializeTransaction(
  1. VersionedMessage message,
  2. List<List<int>> signatures
)

serialize transaction to bytes

Implementation

static List<int> serializeTransaction(
    VersionedMessage message, List<List<int>> signatures) {
  final serializedMessage = message.serialize();
  final encodedSignaturesLength =
      SolanaTransactionUtils._encodeLength(signatures.length);

  final transactionLayout = LayoutUtils.struct([
    LayoutUtils.blob(encodedSignaturesLength.length,
        property: 'encodedSignaturesLength'),
    LayoutUtils.array(
        LayoutUtils.blob(64, property: "signature"), signatures.length,
        property: 'signatures'),
    LayoutUtils.blob(serializedMessage.length, property: 'serializedMessage')
  ]);
  final serializedTransaction = LayoutByteWriter.filled(2048);
  final serializedTransactionLength = transactionLayout.encode({
    'encodedSignaturesLength': encodedSignaturesLength,
    'signatures': signatures,
    'serializedMessage': serializedMessage
  }, serializedTransaction);
  return serializedTransaction
      .toBytes()
      .sublist(0, serializedTransactionLength);
}