payment code lookup fix

This commit is contained in:
julian 2023-02-01 16:46:49 -06:00
parent ce5586d675
commit aec33094d6

View file

@ -148,15 +148,13 @@ mixin PaynymWalletInterface {
btc_dart.NetworkType get networkType => _network; btc_dart.NetworkType get networkType => _network;
Future<Address> currentReceivingPaynymAddress(PaymentCode sender) async { Future<Address> currentReceivingPaynymAddress(PaymentCode sender) async {
final key = await lookupKey(sender.toString()); final keys = await lookupKey(sender.toString());
final address = await _db final address = await _db
.getAddresses(_walletId) .getAddresses(_walletId)
.filter() .filter()
.subTypeEqualTo(AddressSubType.paynymReceive) .subTypeEqualTo(AddressSubType.paynymReceive)
.and() .and()
.otherDataEqualTo(key) .anyOf<String, Address>(keys, (q, String e) => q.otherDataEqualTo(e))
.and()
.otherDataIsNotNull()
.sortByDerivationIndexDesc() .sortByDerivationIndexDesc()
.findFirst(); .findFirst();
@ -331,15 +329,13 @@ mixin PaynymWalletInterface {
const maxCount = 2147483647; const maxCount = 2147483647;
for (int i = startIndex; i < maxCount; i++) { for (int i = startIndex; i < maxCount; i++) {
final key = await lookupKey(pCode.toString()); final keys = await lookupKey(pCode.toString());
final address = await _db final address = await _db
.getAddresses(_walletId) .getAddresses(_walletId)
.filter() .filter()
.subTypeEqualTo(AddressSubType.paynymSend) .subTypeEqualTo(AddressSubType.paynymSend)
.and() .and()
.otherDataEqualTo(key) .anyOf<String, Address>(keys, (q, String e) => q.otherDataEqualTo(e))
.and()
.otherDataIsNotNull()
.and() .and()
.derivationIndexEqualTo(i) .derivationIndexEqualTo(i)
.findFirst(); .findFirst();
@ -1215,16 +1211,17 @@ mixin PaynymWalletInterface {
} }
/// look up a key that corresponds to a payment code string /// look up a key that corresponds to a payment code string
Future<String?> lookupKey(String paymentCodeString) async { Future<List<String>> lookupKey(String paymentCodeString) async {
final keys = final keys =
(await _secureStorage.keys).where((e) => e.startsWith(kPCodeKeyPrefix)); (await _secureStorage.keys).where((e) => e.startsWith(kPCodeKeyPrefix));
final List<String> result = [];
for (final key in keys) { for (final key in keys) {
final value = await _secureStorage.read(key: key); final value = await _secureStorage.read(key: key);
if (value == paymentCodeString) { if (value == paymentCodeString) {
return key; result.add(key);
} }
} }
return null; return result;
} }
/// fetch a payment code string /// fetch a payment code string