deserializeTransactions method Null safety
- Uint8List serializedBlock
Creates a List of TransactionModel
] from a Uint8List
of the serialized
block.
This is the revert function for serializeTransactions
. It should be used
when recovering a block body.
Implementation
static List<TransactionModel> deserializeTransactions(
Uint8List serializedBlock) {
List<TransactionModel> txns = [];
List<Uint8List> extractedBlockBytes = CompactSize.decode(serializedBlock);
List<Uint8List> serializedTransactions = extractedBlockBytes.sublist(5);
int totalTxn = Bytes.decodeBigInt(extractedBlockBytes[4]).toInt();
if (serializedTransactions.length != totalTxn) {
throw 'Invalid transaction length. Expected ${serializedTransactions.length}, got $totalTxn';
}
for (int i = 0; i < serializedTransactions.length; i++) {
TransactionModel txn =
TransactionModel.deserialize(serializedTransactions[i]);
if (!validateIntegrity(txn)) {
throw Exception('Corrupted transaction $txn');
}
txns.add(txn);
}
return txns;
}