avoid checkReceivingAddressForTransactions altogether when reuse is set

This commit is contained in:
sneurlax 2024-07-04 15:05:25 -05:00 committed by julian-CStack
parent 4f40572366
commit bb7f0ff46f
4 changed files with 43 additions and 15 deletions

View file

@ -787,7 +787,9 @@ class FiroWallet<T extends ElectrumXCurrencyInterface> extends Bip39HDWallet<T>
for (final tuple in receiveResults) { for (final tuple in receiveResults) {
if (tuple.addresses.isEmpty) { if (tuple.addresses.isEmpty) {
await checkReceivingAddressForTransactions(); if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
await checkReceivingAddressForTransactions();
}
} else { } else {
highestReceivingIndexWithHistory = max( highestReceivingIndexWithHistory = max(
tuple.index, tuple.index,

View file

@ -522,8 +522,10 @@ abstract class Wallet<T extends CryptoCurrency> {
// TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided. // TODO: [prio=low] handle this differently. Extra modification of this file for coin specific functionality should be avoided.
if (this is MultiAddressInterface) { if (this is MultiAddressInterface) {
await (this as MultiAddressInterface) if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
.checkReceivingAddressForTransactions(); await (this as MultiAddressInterface)
.checkReceivingAddressForTransactions();
}
} }
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.2, walletId)); GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.2, walletId));

View file

@ -25,6 +25,7 @@ import '../../../utilities/amount/amount.dart';
import '../../../utilities/logger.dart'; import '../../../utilities/logger.dart';
import '../../../utilities/stack_file_system.dart'; import '../../../utilities/stack_file_system.dart';
import '../../crypto_currency/intermediate/cryptonote_currency.dart'; import '../../crypto_currency/intermediate/cryptonote_currency.dart';
import '../../isar/models/wallet_info.dart';
import '../intermediate/cryptonote_wallet.dart'; import '../intermediate/cryptonote_wallet.dart';
import 'multi_address_interface.dart'; import 'multi_address_interface.dart';
@ -286,7 +287,9 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
await updateTransactions(); await updateTransactions();
await updateBalance(); await updateBalance();
await checkReceivingAddressForTransactions(); if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
await checkReceivingAddressForTransactions();
}
if (cwWalletBase?.syncStatus is SyncedSyncStatus) { if (cwWalletBase?.syncStatus is SyncedSyncStatus) {
refreshMutex.release(); refreshMutex.release();
@ -342,6 +345,17 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
@override @override
Future<void> checkReceivingAddressForTransactions() async { Future<void> checkReceivingAddressForTransactions() async {
if (info.otherData[WalletInfoKeys.reuseAddress] == true) {
try {
throw Exception();
} catch (_, s) {
Logging.instance.log(
"checkReceivingAddressForTransactions called but reuse address flag set: $s",
level: LogLevel.Error,
);
}
}
try { try {
int highestIndex = -1; int highestIndex = -1;
final entries = cwWalletBase?.transactionHistory?.transactions?.entries; final entries = cwWalletBase?.transactionHistory?.transactions?.entries;
@ -380,8 +394,10 @@ mixin CwBasedInterface<T extends CryptonoteCurrency> on CryptonoteWallet<T>
// we need to update the address // we need to update the address
await mainDB.updateAddress(existing, newReceivingAddress); await mainDB.updateAddress(existing, newReceivingAddress);
} }
// keep checking until address with no tx history is set as current if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
await checkReceivingAddressForTransactions(); // keep checking until address with no tx history is set as current
await checkReceivingAddressForTransactions();
}
} }
} on SocketException catch (se, s) { } on SocketException catch (se, s) {
Logging.instance.log( Logging.instance.log(

View file

@ -1316,6 +1316,17 @@ mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
@override @override
Future<void> checkReceivingAddressForTransactions() async { Future<void> checkReceivingAddressForTransactions() async {
if (info.otherData[WalletInfoKeys.reuseAddress] == true) {
try {
throw Exception();
} catch (_, s) {
Logging.instance.log(
"checkReceivingAddressForTransactions called but reuse address flag set: $s",
level: LogLevel.Error,
);
}
}
try { try {
final currentReceiving = await getCurrentReceivingAddress(); final currentReceiving = await getCurrentReceivingAddress();
@ -1334,18 +1345,15 @@ mixin ElectrumXInterface<T extends ElectrumXCurrencyInterface>
needsGenerate = txCount > 0 || currentReceiving.derivationIndex < 0; needsGenerate = txCount > 0 || currentReceiving.derivationIndex < 0;
} }
// TODO this in the wrong place
// If reuseAddress is set, don't generate an address by default.
if (info.otherData[WalletInfoKeys.reuseAddress] as bool? ?? false) {
return;
}
if (needsGenerate) { if (needsGenerate) {
await generateNewReceivingAddress(); await generateNewReceivingAddress();
// TODO: get rid of this? Could cause problems (long loading/infinite loop or something) // TODO: [prio=low] Make sure we scan all addresses but only show one.
// keep checking until address with no tx history is set as current if (info.otherData[WalletInfoKeys.reuseAddress] != true) {
await checkReceivingAddressForTransactions(); // TODO: get rid of this? Could cause problems (long loading/infinite loop or something)
// keep checking until address with no tx history is set as current
await checkReceivingAddressForTransactions();
}
} }
} catch (e, s) { } catch (e, s) {
Logging.instance.log( Logging.instance.log(