diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index 20f69da11..77f1f1509 100644 --- a/lib/services/coins/bitcoin/bitcoin_wallet.dart +++ b/lib/services/coins/bitcoin/bitcoin_wallet.dart @@ -524,6 +524,7 @@ class BitcoinWallet extends CoinServiceAPI required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -697,14 +698,25 @@ class BitcoinWallet extends CoinServiceAPI p2wpkhChangeAddressArray.add(address); } - await db.putAddresses([ - ...p2wpkhReceiveAddressArray, - ...p2wpkhChangeAddressArray, - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } // get own payment code final myCode = await getPaymentCode(DerivePathType.bip44); @@ -2924,6 +2936,7 @@ class BitcoinWallet extends CoinServiceAPI mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart index af495fba7..952a07746 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -487,6 +487,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -616,12 +617,21 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { p2shChangeAddressArray.add(address); } - await db.putAddresses([ - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } await _updateUTXOs(); @@ -2874,6 +2884,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/dogecoin/dogecoin_wallet.dart b/lib/services/coins/dogecoin/dogecoin_wallet.dart index 45f20b763..ff4ba9919 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -464,6 +464,7 @@ class DogecoinWallet extends CoinServiceAPI required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -540,11 +541,17 @@ class DogecoinWallet extends CoinServiceAPI await _generateAddressForChain(1, 0, DerivePathType.bip44); p2pkhChangeAddressArray.add(address); } - - await db.putAddresses([ - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ]); + } // paynym stuff // // generate to ensure notification address is in db before refreshing transactions @@ -2573,6 +2580,7 @@ class DogecoinWallet extends CoinServiceAPI mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index b0de62f75..5a3965357 100644 --- a/lib/services/coins/litecoin/litecoin_wallet.dart +++ b/lib/services/coins/litecoin/litecoin_wallet.dart @@ -517,6 +517,7 @@ class LitecoinWallet extends CoinServiceAPI required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -690,14 +691,25 @@ class LitecoinWallet extends CoinServiceAPI p2wpkhChangeAddressArray.add(address); } - await db.putAddresses([ - ...p2wpkhReceiveAddressArray, - ...p2wpkhChangeAddressArray, - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } await _updateUTXOs(); @@ -2887,6 +2899,7 @@ class LitecoinWallet extends CoinServiceAPI mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/namecoin/namecoin_wallet.dart b/lib/services/coins/namecoin/namecoin_wallet.dart index 470a6a0bc..01a1bdcd9 100644 --- a/lib/services/coins/namecoin/namecoin_wallet.dart +++ b/lib/services/coins/namecoin/namecoin_wallet.dart @@ -507,6 +507,7 @@ class NamecoinWallet extends CoinServiceAPI required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -680,14 +681,25 @@ class NamecoinWallet extends CoinServiceAPI p2wpkhChangeAddressArray.add(address); } - await db.putAddresses([ - ...p2wpkhReceiveAddressArray, - ...p2wpkhChangeAddressArray, - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]); + } await _updateUTXOs(); @@ -2877,6 +2889,7 @@ class NamecoinWallet extends CoinServiceAPI mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/particl/particl_wallet.dart b/lib/services/coins/particl/particl_wallet.dart index 3a63204a8..4c343be01 100644 --- a/lib/services/coins/particl/particl_wallet.dart +++ b/lib/services/coins/particl/particl_wallet.dart @@ -489,6 +489,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -614,12 +615,21 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { p2wpkhChangeAddressArray.add(address); } - await db.putAddresses([ - ...p2wpkhReceiveAddressArray, - ...p2wpkhChangeAddressArray, - ...p2pkhReceiveAddressArray, - ...p2pkhChangeAddressArray, - ]); + if (isRescan) { + await db.updateOrPutAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ]); + } else { + await db.putAddresses([ + ...p2wpkhReceiveAddressArray, + ...p2wpkhChangeAddressArray, + ...p2pkhReceiveAddressArray, + ...p2pkhChangeAddressArray, + ]); + } await _updateUTXOs(); @@ -2982,6 +2992,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB { mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false;