mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 03:49:22 +00:00
add convenience function to add or update a list of addresses
This commit is contained in:
parent
b09b3d0e1f
commit
d59d25cb04
1 changed files with 21 additions and 0 deletions
|
@ -48,6 +48,27 @@ class MainDB {
|
|||
await isar.addresses.putAll(addresses);
|
||||
});
|
||||
|
||||
Future<void> updateOrPutAddresses(List<Address> addresses) async {
|
||||
await isar.writeTxn(() async {
|
||||
for (final address in addresses) {
|
||||
final storedAddress = await isar.addresses
|
||||
.getByValueWalletId(address.value, address.walletId);
|
||||
|
||||
if (storedAddress == null) {
|
||||
await isar.addresses.put(address);
|
||||
} else {
|
||||
address.id = storedAddress.id;
|
||||
await storedAddress.transactions.load();
|
||||
final txns = storedAddress.transactions.toList();
|
||||
await isar.addresses.delete(storedAddress.id);
|
||||
await isar.addresses.put(address);
|
||||
address.transactions.addAll(txns);
|
||||
await address.transactions.save();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<Address?> getAddress(String walletId, String address) async {
|
||||
return isar.addresses.getByValueWalletId(address, walletId);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue