deserializeMessageLegacy static method
convert Bytes to legacy message
Implementation
static Message deserializeMessageLegacy(List<int> bytes) {
List<int> byteArray = List<int>.from(bytes);
final int numRequiredSignatures = byteArray.removeAt(0);
if (numRequiredSignatures !=
(numRequiredSignatures & SolanaTransactionConstant.versionPrefixMask)) {
throw const SolanaPluginException('invalid versioned Message');
}
final int numReadonlySignedAccounts = byteArray.removeAt(0);
final int numReadonlyUnsignedAccounts = byteArray.removeAt(0);
final int accountCount = SolanaTransactionUtils._decodeLength(byteArray);
final List<SolAddress> accountKeys = [];
for (int i = 0; i < accountCount; i++) {
final List<int> account =
byteArray.sublist(0, SolanaTransactionConstant.publicKeyLength);
byteArray = byteArray.sublist(SolanaTransactionConstant.publicKeyLength);
accountKeys.add(SolAddress.uncheckBytes(account));
}
final List<int> recentBlockhash =
byteArray.sublist(0, SolanaTransactionConstant.publicKeyLength);
byteArray = byteArray.sublist(SolanaTransactionConstant.publicKeyLength);
final int instructionCount =
SolanaTransactionUtils._decodeLength(byteArray);
final List<CompiledInstruction> instructions = [];
for (int i = 0; i < instructionCount; i++) {
final int programIdIndex = byteArray.removeAt(0);
final int accountCount = SolanaTransactionUtils._decodeLength(byteArray);
final List<int> accounts = byteArray.sublist(0, accountCount);
byteArray = byteArray.sublist(accountCount);
final int dataLength = SolanaTransactionUtils._decodeLength(byteArray);
final 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));
}