serializeInstructionsV0 static method
serialize Message V0 instructions
Implementation
static List<int> serializeInstructionsV0(
List<CompiledInstruction> compiledInstructions) {
var serializedLength = 0;
final serializedInstructions =
LayoutByteWriter.filled(SolanaTransactionConstant.packetDataSize, 0);
for (var instruction in compiledInstructions) {
final encodedAccountKeyIndexesLength =
SolanaTransactionUtils._encodeLength(instruction.accounts.length);
final encodedDataLength =
SolanaTransactionUtils._encodeLength(instruction.data.length);
final instructionLayout = LayoutUtils.struct([
LayoutUtils.u8('programIdIndex'),
LayoutUtils.blob(encodedAccountKeyIndexesLength.length,
property: 'encodedAccountKeyIndexesLength'),
LayoutUtils.array(LayoutUtils.u8(), instruction.accounts.length,
property: 'accountKeyIndexes'),
LayoutUtils.blob(encodedDataLength.length,
property: 'encodedDataLength'),
LayoutUtils.blob(instruction.data.length, property: 'data')
]);
serializedLength += instructionLayout.encode({
'programIdIndex': instruction.programIdIndex,
'encodedAccountKeyIndexesLength': encodedAccountKeyIndexesLength,
'accountKeyIndexes': instruction.accounts,
'encodedDataLength': encodedDataLength,
'data': instruction.data
}, serializedInstructions, offset: serializedLength);
}
return serializedInstructions.toBytes().sublist(0, serializedLength);
}