diff --git a/lib/pages/receive_view/receiving_addresses_view.dart b/lib/pages/receive_view/receiving_addresses_view.dart index 260e33cd1..e5f1d88bf 100644 --- a/lib/pages/receive_view/receiving_addresses_view.dart +++ b/lib/pages/receive_view/receiving_addresses_view.dart @@ -103,9 +103,11 @@ class AddressCard extends StatelessWidget { return RoundedWhiteContainer( child: Row( children: [ - Text( - address.value, - style: STextStyles.itemSubtitle12(context), + Expanded( + child: Text( + address.value, + style: STextStyles.itemSubtitle12(context), + ), ) ], ), diff --git a/lib/services/coins/bitcoin/bitcoin_wallet.dart b/lib/services/coins/bitcoin/bitcoin_wallet.dart index e20e9f74c..3bf151ccc 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); @@ -2932,6 +2944,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 4274c524c..4a4ff041b 100644 --- a/lib/services/coins/bitcoincash/bitcoincash_wallet.dart +++ b/lib/services/coins/bitcoincash/bitcoincash_wallet.dart @@ -491,11 +491,13 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { } } - Future _recoverWalletFromBIP32SeedPhrase( - {required String mnemonic, - int maxUnusedAddressGap = 20, - int maxNumberOfIndexesToCheck = 1000, - Coin? coin}) async { + Future _recoverWalletFromBIP32SeedPhrase({ + required String mnemonic, + int maxUnusedAddressGap = 20, + int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, + Coin? coin, + }) async { longMutex = true; Map> bip44P2pkhReceiveDerivations = {}; @@ -631,6 +633,13 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { p2shChangeAddressArray.add(address); } + final addressesToStore = [ + ...bip44P2pkhReceiveAddressArray, + ...bip44P2pkhChangeAddressArray, + ...p2shReceiveAddressArray, + ...p2shChangeAddressArray, + ]; + if (!testnet) { final resultReceiveBch44 = _checkGaps( maxNumberOfIndexesToCheck, @@ -689,21 +698,16 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { bch44P2pkhChangeAddressArray.add(address); } - await db.putAddresses([ - ...bip44P2pkhReceiveAddressArray, - ...bip44P2pkhChangeAddressArray, - ...bch44P2pkhReceiveAddressArray, - ...bch44P2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, + addressesToStore.addAll([ + ...bch44P2pkhReceiveAddressArray, + ...bch44P2pkhChangeAddressArray, ]); + } + + if (isRescan) { + await db.updateOrPutAddresses(addressesToStore); } else { - await db.putAddresses([ - ...bip44P2pkhReceiveAddressArray, - ...bip44P2pkhChangeAddressArray, - ...p2shReceiveAddressArray, - ...p2shChangeAddressArray, - ]); + await db.putAddresses(addressesToStore); } await _updateUTXOs(); @@ -2732,19 +2736,28 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { // p2pkh / bip44 final p2pkhLength = addressesP2PKH.length; if (p2pkhLength > 0) { - final receiveDerivations = await _fetchDerivations( + final receiveDerivationsBip44 = await _fetchDerivations( chain: 0, derivePathType: DerivePathType.bip44, ); - final changeDerivations = await _fetchDerivations( + final changeDerivationsBip44 = await _fetchDerivations( chain: 1, derivePathType: DerivePathType.bip44, ); + final receiveDerivationsBch44 = await _fetchDerivations( + chain: 0, + derivePathType: DerivePathType.bch44, + ); + final changeDerivationsBch44 = await _fetchDerivations( + chain: 1, + derivePathType: DerivePathType.bch44, + ); for (int i = 0; i < p2pkhLength; i++) { String address = addressesP2PKH[i]; // receives - final receiveDerivation = receiveDerivations[address]; + final receiveDerivation = receiveDerivationsBip44[address] ?? + receiveDerivationsBch44[address]; // if a match exists it will not be null if (receiveDerivation != null) { final data = P2PKH( @@ -2765,7 +2778,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB { } } else { // if its not a receive, check change - final changeDerivation = changeDerivations[address]; + final changeDerivation = changeDerivationsBip44[address] ?? + changeDerivationsBch44[address]; // if a match exists it will not be null if (changeDerivation != null) { final data = P2PKH( @@ -2976,6 +2990,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 b4dce7a89..85a2abc81 100644 --- a/lib/services/coins/dogecoin/dogecoin_wallet.dart +++ b/lib/services/coins/dogecoin/dogecoin_wallet.dart @@ -465,6 +465,7 @@ class DogecoinWallet extends CoinServiceAPI required String mnemonic, int maxUnusedAddressGap = 20, int maxNumberOfIndexesToCheck = 1000, + bool isRescan = false, }) async { longMutex = true; @@ -541,11 +542,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 @@ -2574,6 +2581,7 @@ class DogecoinWallet extends CoinServiceAPI mnemonic: mnemonic!, maxUnusedAddressGap: maxUnusedAddressGap, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, + isRescan: true, ); longMutex = false; diff --git a/lib/services/coins/epiccash/epiccash_wallet.dart b/lib/services/coins/epiccash/epiccash_wallet.dart index d6505889b..42198104c 100644 --- a/lib/services/coins/epiccash/epiccash_wallet.dart +++ b/lib/services/coins/epiccash/epiccash_wallet.dart @@ -839,6 +839,10 @@ class EpicCashWallet extends CoinServiceAPI isar_models.Address? address = await db .getAddresses(walletId) .filter() + .subTypeEqualTo(isar_models.AddressSubType.receiving) + .and() + .typeEqualTo(isar_models.AddressType.mimbleWimble) + .and() .derivationIndexEqualTo(index) .findFirst(); @@ -877,8 +881,14 @@ class EpicCashWallet extends CoinServiceAPI (await _currentReceivingAddress)?.value ?? (await _getReceivingAddressForIndex(0)).value; - Future get _currentReceivingAddress => - db.getAddresses(walletId).sortByDerivationIndexDesc().findFirst(); + Future get _currentReceivingAddress => db + .getAddresses(walletId) + .filter() + .subTypeEqualTo(isar_models.AddressSubType.receiving) + .and() + .typeEqualTo(isar_models.AddressType.mimbleWimble) + .sortByDerivationIndexDesc() + .findFirst(); @override Future exit() async { diff --git a/lib/services/coins/litecoin/litecoin_wallet.dart b/lib/services/coins/litecoin/litecoin_wallet.dart index 32cddf47f..ecbc9cbc0 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(); @@ -2895,6 +2907,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 338089331..1ee89d95f 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(); @@ -2884,6 +2896,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 fc9971e89..625b4d384 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;