Skip to content

Commit

Permalink
feat(db): implement method to get vtt
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Aug 25, 2023
1 parent d4fbc00 commit 0e28359
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/shared/api_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ class ApiDatabase {
params: {'type': 'mint', 'value': transaction.jsonMap()});
}

Future<ValueTransferInfo?> getVtt(String hash) async {
try {
return await _processIsolate(method: 'getVtt', params: {"hash": hash});
} catch (err) {
print('Error getting vtt:: $err');
return null;
}
}

Future getAllVtts() async {
try {
return await _processIsolate(method: 'getAllVtts', params: {});
Expand Down
10 changes: 10 additions & 0 deletions lib/util/storage/database/database_isolate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Map<String, Function(DatabaseService, SendPort, Map<String, dynamic>)>
'delete': _deleteRecord,
'deleteDatabase': _deleteDatabase,
'getKeychain': _getKeychain,
'getVtt': _getVtt,
'loadWallets': _getAllWallets,
'lock': _lock,
'masterKeySet': _masterKeySet,
Expand Down Expand Up @@ -228,3 +229,12 @@ Future<void> _getKeychain(
await dbService.getKey();
port.send(dbService.keyChain.keyHash);
}

Future<void> _getVtt(
DatabaseService dbService,
SendPort port,
Map<String, dynamic> params,
) async {
ValueTransferInfo? vtt = await dbService.getVtt(params);
port.send(vtt);
}
4 changes: 4 additions & 0 deletions lib/util/storage/database/database_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,8 @@ class DatabaseService {
unlocked = false;
return true;
}

Future<ValueTransferInfo?> getVtt(params) async {
return await vttRepository.getTransaction(params["hash"], _database);
}
}
15 changes: 15 additions & 0 deletions lib/util/storage/database/transaction_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ class VttRepository extends _TransactionRepository {
return false;
}
}

Future<ValueTransferInfo?> getTransaction(
String txHash, DatabaseClient databaseClient) async {
try {
Map<String, dynamic> valueTransferInfoDbJson =
await _store.record(txHash).get(databaseClient);

ValueTransferInfo valueTransferInfo =
ValueTransferInfo.fromDbJson(valueTransferInfoDbJson);

return valueTransferInfo;
} catch (e) {
return null;
}
}
}

class DataRequestRepository extends _TransactionRepository {
Expand Down

0 comments on commit 0e28359

Please sign in to comment.