write method Null safety
- Uint8List contents
Creates a TransactionModel
with the contents
and save to local database.
When a TransactionModel
is created it is not added to the next block
immediately. It needs to wait until the _blockTimer
runs again to check if
the oldest transaction was created more than _blockInterval
duration or
if there are more than _maxTransactions
waiting to be added to a
BlockModel.
Implementation
Future<TransactionModel> write(Uint8List contents) async {
TransactionModel transaction =
_transactionService.create(contents, _primaryKey);
List<TransactionModel> transactions = _transactionService.getPending();
if (transactions.length >= _maxTransactions) {
await _createBlock(transactions);
}
return transaction;
}