serializeInstructionsV0 static method
serialize Message V0 instructions
Implementation
static List<int> serializeInstructionsV0(
List<CompiledInstruction> compiledInstructions) {
var serializedLength = 0;
final serializedInstructions =
List<int>.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 = LayoutConst.struct([
LayoutConst.u8(property: 'programIdIndex'),
LayoutConst.blob(encodedAccountKeyIndexesLength.length,
property: 'encodedAccountKeyIndexesLength'),
LayoutConst.array(LayoutConst.u8(), instruction.accounts.length,
property: 'accountKeyIndexes'),
LayoutConst.blob(encodedDataLength.length,
property: 'encodedDataLength'),
LayoutConst.blob(instruction.data.length, property: 'data')
]);
final encode = instructionLayout.serialize({
'programIdIndex': instruction.programIdIndex,
'encodedAccountKeyIndexesLength': encodedAccountKeyIndexesLength,
'accountKeyIndexes': instruction.accounts,
'encodedDataLength': encodedDataLength,
'data': instruction.data
});
serializedInstructions.setAll(serializedLength, encode);
serializedLength += encode.length;
}
return serializedInstructions.sublist(0, serializedLength);
}