getCompiledTransactionMessageDecoder function
Returns a decoder that you can use to decode a byte array representing a CompiledTransactionMessage.
The wire format of a Solana transaction consists of signatures followed by a compiled transaction message. You can use this decoder to decode the message part.
Implementation
VariableSizeDecoder<CompiledTransactionMessage>
getCompiledTransactionMessageDecoder() {
return VariableSizeDecoder<CompiledTransactionMessage>(
read: (bytes, offset) {
final versionDec = getTransactionVersionDecoder();
final headerDec = getMessageHeaderDecoder();
final shortU16Dec = getShortU16Decoder();
final addrDec = getAddressDecoder();
final lifetimeDec = fixDecoderSize(getBase58Decoder(), 32);
final instructionDec = getInstructionDecoder();
final lookupDec = getAddressTableLookupDecoder();
// Decode version.
final (version, o1) = versionDec.read(bytes, offset);
if (version == TransactionVersion.v1) {
return _readV1Message(bytes, offset);
}
// Decode header.
final (header, o2) = headerDec.read(bytes, o1);
// Decode static accounts.
final accountArrayDec = getArrayDecoder<Address>(
addrDec,
size: PrefixedArraySize(shortU16Dec),
);
final (staticAccounts, o3) = accountArrayDec.read(bytes, o2);
// Decode lifetime token.
final (lifetimeToken, o4) = lifetimeDec.read(bytes, o3);
// Decode instructions.
final instructionArrayDec = getArrayDecoder<CompiledInstruction>(
instructionDec,
size: PrefixedArraySize(shortU16Dec),
);
final (instructions, o5) = instructionArrayDec.read(bytes, o4);
// Decode address table lookups (present for all messages in the wire
// format, but semantically only meaningful for versioned messages).
List<AddressTableLookup>? addressTableLookups;
var finalOffset = o5;
if (o5 < bytes.length) {
final lookupArrayDec = getArrayDecoder<AddressTableLookup>(
lookupDec,
size: PrefixedArraySize(shortU16Dec),
);
final (lookups, o6) = lookupArrayDec.read(bytes, o5);
finalOffset = o6;
if (version != TransactionVersion.legacy && lookups.isNotEmpty) {
addressTableLookups = lookups;
}
}
return (
CompiledTransactionMessage(
version: version,
header: header,
staticAccounts: staticAccounts,
lifetimeToken: lifetimeToken,
instructions: instructions,
addressTableLookups: addressTableLookups,
),
finalOffset,
);
},
);
}