deserializeMessageLegacy static method

Message deserializeMessageLegacy(
  1. List<int> bytes
)

convert Bytes to legacy message

Implementation

static Message deserializeMessageLegacy(List<int> bytes) {
  List<int> byteArray = List<int>.from(bytes);
  int numRequiredSignatures = byteArray.removeAt(0);
  if (numRequiredSignatures !=
      (numRequiredSignatures & SolanaTransactionConstant.versionPrefixMask)) {
    throw MessageException('invalid versioned Message');
  }
  int numReadonlySignedAccounts = byteArray.removeAt(0);
  int numReadonlyUnsignedAccounts = byteArray.removeAt(0);
  int accountCount = SolanaTransactionUtils._decodeLength(byteArray);
  List<SolAddress> accountKeys = [];
  for (int i = 0; i < accountCount; i++) {
    List<int> account =
        byteArray.sublist(0, SolanaTransactionConstant.publicKeyLength);
    byteArray = byteArray.sublist(SolanaTransactionConstant.publicKeyLength);
    accountKeys.add(SolAddress.uncheckBytes(account));
  }
  List<int> recentBlockhash =
      byteArray.sublist(0, SolanaTransactionConstant.publicKeyLength);
  byteArray = byteArray.sublist(SolanaTransactionConstant.publicKeyLength);
  int instructionCount = SolanaTransactionUtils._decodeLength(byteArray);
  List<CompiledInstruction> instructions = [];
  for (int i = 0; i < instructionCount; i++) {
    int programIdIndex = byteArray.removeAt(0);
    int accountCount = SolanaTransactionUtils._decodeLength(byteArray);
    List<int> accounts = byteArray.sublist(0, accountCount);
    byteArray = byteArray.sublist(accountCount);
    int dataLength = SolanaTransactionUtils._decodeLength(byteArray);
    List<int> data = byteArray.sublist(0, dataLength);
    byteArray = byteArray.sublist(dataLength);
    instructions.add(CompiledInstruction(
        programIdIndex: programIdIndex, accounts: accounts, data: data));
  }
  return Message(
      accountKeys: accountKeys,
      compiledInstructions: instructions,
      recentBlockhash: SolAddress.uncheckBytes(recentBlockhash),
      header: MessageHeader(
          numRequiredSignatures: numRequiredSignatures,
          numReadonlySignedAccounts: numReadonlySignedAccounts,
          numReadonlyUnsignedAccounts: numReadonlyUnsignedAccounts));
}