mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-11-17 17:57:40 +00:00
null address fix
This commit is contained in:
parent
a135404d67
commit
54cabe935f
9 changed files with 189 additions and 187 deletions
|
@ -185,24 +185,28 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip84);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip84);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -1163,6 +1167,8 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1856,7 +1862,7 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1875,12 +1881,9 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1898,7 +1901,7 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1917,12 +1920,9 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -162,24 +162,28 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip44);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip44);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -1093,6 +1097,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1740,7 +1746,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1759,12 +1765,9 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1787,7 +1790,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1806,12 +1809,9 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -160,25 +160,29 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip44);
|
||||
|
||||
// @override
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip44);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -998,6 +1002,8 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
}
|
||||
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1644,7 +1650,7 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1663,12 +1669,9 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1691,7 +1694,7 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1710,12 +1713,9 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await checkChangeAddressForTransactions();
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -871,24 +871,28 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2pkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0);
|
||||
|
||||
late String _walletName;
|
||||
@override
|
||||
|
@ -1831,6 +1835,8 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await checkChangeAddressForTransactions();
|
||||
await checkReceivingAddressForTransactions();
|
||||
}
|
||||
|
||||
Future<bool> refreshIfThereIsNewData() async {
|
||||
|
@ -3144,7 +3150,7 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -3165,12 +3171,9 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await checkReceivingAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -3194,7 +3197,7 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
'Number of txs for current change address: $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -3215,12 +3218,9 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -185,24 +185,28 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip84);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip84);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -1181,6 +1185,8 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1879,7 +1885,7 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1898,12 +1904,9 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1921,7 +1924,7 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1940,12 +1943,9 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -288,6 +288,8 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
}
|
||||
walletBase = (await walletService!.openWallet(_walletId, password))
|
||||
as MoneroWalletBase;
|
||||
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
// walletBase!.onNewBlock = onNewBlock;
|
||||
// walletBase!.onNewTransaction = onNewTransaction;
|
||||
// walletBase!.syncStatusChanged = syncStatusChanged;
|
||||
|
|
|
@ -180,24 +180,28 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip84);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip84);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -1170,6 +1174,8 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// hack to add tx to txData before refresh completes
|
||||
|
@ -1861,7 +1867,7 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1880,12 +1886,9 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1903,7 +1906,7 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1922,12 +1925,10 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -176,24 +176,28 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
Future<String> get currentReceivingAddress async =>
|
||||
(await _currentReceivingAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentReceivingAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentReceivingAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.receiving)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(0, 0, DerivePathType.bip84);
|
||||
|
||||
Future<String> get currentChangeAddress async =>
|
||||
(await _currentChangeAddress).value;
|
||||
|
||||
Future<isar_models.Address> get _currentChangeAddress async => (await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst())!;
|
||||
Future<isar_models.Address> get _currentChangeAddress async =>
|
||||
(await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.typeEqualTo(isar_models.AddressType.p2wpkh)
|
||||
.subTypeEqualTo(isar_models.AddressSubType.change)
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst()) ??
|
||||
await _generateAddressForChain(1, 0, DerivePathType.bip84);
|
||||
|
||||
@override
|
||||
Future<void> exit() async {
|
||||
|
@ -1100,6 +1104,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
"Attempted to initialize an existing wallet using an unknown wallet ID!");
|
||||
}
|
||||
await _prefs.init();
|
||||
await _checkCurrentChangeAddressesForTransactions();
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
}
|
||||
|
||||
// TODO make sure this copied implementation from bitcoin_wallet.dart applies for particl just as well--or import it
|
||||
|
@ -1749,7 +1755,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current receiving address $currentReceiving: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentReceiving.derivationIndex < 0) {
|
||||
// First increment the receiving index
|
||||
final newReceivingIndex = currentReceiving.derivationIndex + 1;
|
||||
|
||||
|
@ -1768,12 +1774,9 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1791,7 +1794,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
'Number of txs for current change address $currentChange: $txCount',
|
||||
level: LogLevel.Info);
|
||||
|
||||
if (txCount >= 1) {
|
||||
if (txCount >= 1 || currentChange.derivationIndex < 0) {
|
||||
// First increment the change index
|
||||
final newChangeIndex = currentChange.derivationIndex + 1;
|
||||
|
||||
|
@ -1810,12 +1813,9 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newChangeAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkChangeAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -306,6 +306,8 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
walletBase = (await walletService?.openWallet(_walletId, password!))
|
||||
as WowneroWalletBase;
|
||||
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
|
||||
Logging.instance.log(
|
||||
"Opened existing ${coin.prettyName} wallet $walletName",
|
||||
level: LogLevel.Info,
|
||||
|
@ -1245,12 +1247,9 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
} else {
|
||||
// we need to update the address
|
||||
await db.updateAddress(existing, newReceivingAddress);
|
||||
|
||||
// since we updated an existing address there is a chance it has
|
||||
// some tx history. To prevent address reuse we will call check again
|
||||
// recursively
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
// keep checking until address with no tx history is set as current
|
||||
await _checkReceivingAddressForTransactions();
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
Loading…
Reference in a new issue