getTransactionVersionDecoder function
Returns a decoder that you can use to decode a byte array representing a TransactionVersion.
When the byte at the current offset is determined to represent a legacy transaction, this decoder will return TransactionVersion.legacy and will not advance the offset.
Implementation
VariableSizeDecoder<TransactionVersion> getTransactionVersionDecoder() {
return VariableSizeDecoder<TransactionVersion>(
maxSize: 1,
read: (bytes, offset) {
final firstByte = bytes[offset];
if ((firstByte & _versionFlagMask) == 0) {
// No version flag set; it's a legacy (unversioned) transaction.
return (TransactionVersion.legacy, offset);
} else {
final version = firstByte ^ _versionFlagMask;
if (version > maxSupportedTransactionVersion) {
throw SolanaError(
SolanaErrorCode.transactionVersionNumberNotSupported,
{'unsupportedVersion': version},
);
}
return (
version == 0 ? TransactionVersion.v0 : TransactionVersion.v1,
offset + 1,
);
}
},
);
}