syncBlock method
void
syncBlock({
- String? accessToken,
- required Uint8List hash,
- required TikiSyncChainBlock block,
- void onSuccess()?,
- void onError()?,
Implementation
void syncBlock(
{String? accessToken,
required Uint8List hash,
required TikiSyncChainBlock block,
void Function(TikiSyncChainBlock)? onSuccess,
void Function(Object)? onError}) async {
if (_policy == null) {
await _authorizeService.policy(
address: _address,
onSuccess: (rsp) {
_policy = rsp;
syncBlock(
accessToken: accessToken,
block: block,
hash: hash,
onSuccess: onSuccess);
});
} else {
block.synced = DateTime.now();
block.signature = await _sign(
Uint8List.fromList(utf8.encode(json.encode(block.toJson()))));
await _s3service.write(
key:
'${_hexFromBase64(_address)}/chain/${_hexFromBase64(base64.encode(hash))}.json',
policy: _policy!,
object: utf8.encode(json.encode(block.toJson())),
onError: onError,
onSuccess: (ver) async {
// TODO bulk write
await _dbService.write([
DBModel(
hash: hash, versionId: ver.versionId, synced: block.synced)
]);
if (onSuccess != null) onSuccess(block);
});
}
}