BackupService constructor Null safety

BackupService(
  1. L0Storage _l0storage,
  2. Database database,
  3. KeyModel _key,
  4. Uint8List? _getBlock(
    1. Uint8List
    )
)

Creates a new BackupService

Saves the public key in the initialization.

Implementation

BackupService(this._l0storage, Database database, this._key, this._getBlock)
    : _repository = BackupRepository(database) {
  String keyBackupPath = '${Bytes.base64UrlEncode(_key.address)}/public.key';
  BackupModel? keyBackup = _repository.getByPath(keyBackupPath);

  if (keyBackup == null) {
    keyBackup = BackupModel(path: keyBackupPath);
    _repository.save(keyBackup);
  }

  if (keyBackup.timestamp == null) {
    Uint8List obj = base64.decode(_key.privateKey.public.encode());
    _l0storage.write(keyBackupPath, obj);
    keyBackup.timestamp = DateTime.now();
    _repository.update(keyBackup);
  }

  _pending();
}