mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-23 11:59:30 +00:00
reserve in batch
This commit is contained in:
parent
f915a705dc
commit
b82cd05fd9
1 changed files with 20 additions and 14 deletions
|
@ -326,18 +326,22 @@ mixin FusionWalletInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reserve an address for fusion.
|
/// Reserve an address for fusion.
|
||||||
Future<Address> _reserveAddress(Address address) async {
|
Future<List<Address>> _reserveAddresses(Iterable<Address> addresses) async {
|
||||||
address = address.copyWith(otherData: kReservedFusionAddress);
|
if (addresses.isEmpty) {
|
||||||
|
return [];
|
||||||
// Make sure the address is updated in the database as reserved for Fusion.
|
|
||||||
final _address = await _db.getAddress(_walletId, address.value);
|
|
||||||
if (_address != null) {
|
|
||||||
await _db.updateAddress(_address, address);
|
|
||||||
} else {
|
|
||||||
await _db.putAddress(address);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return address;
|
final updatedAddresses = addresses
|
||||||
|
.map((e) => e.copyWith(otherData: kReservedFusionAddress))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
await _db.isar.writeTxn(() async {
|
||||||
|
await _db.isar.addresses
|
||||||
|
.deleteAll(updatedAddresses.map((e) => e.id).toList());
|
||||||
|
await _db.isar.addresses.putAll(updatedAddresses);
|
||||||
|
});
|
||||||
|
|
||||||
|
return updatedAddresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// un reserve a fusion reserved address.
|
/// un reserve a fusion reserved address.
|
||||||
|
@ -366,10 +370,12 @@ mixin FusionWalletInterface {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initialize a list of unused reserved change addresses.
|
// Initialize a list of unused reserved change addresses.
|
||||||
final List<Address> unusedReservedAddresses = [];
|
final List<Address> unusedReservedAddresses = unusedChangeAddresses
|
||||||
for (final address in unusedChangeAddresses) {
|
.where((e) => e.otherData == kReservedFusionAddress)
|
||||||
unusedReservedAddresses.add(await _reserveAddress(address));
|
.toList();
|
||||||
}
|
|
||||||
|
unusedReservedAddresses.addAll(await _reserveAddresses(
|
||||||
|
unusedChangeAddresses.where((e) => e.otherData == null)));
|
||||||
|
|
||||||
// Return the list of unused reserved change addresses.
|
// Return the list of unused reserved change addresses.
|
||||||
return unusedReservedAddresses
|
return unusedReservedAddresses
|
||||||
|
|
Loading…
Reference in a new issue