mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-22 19:39:22 +00:00
update address in case of bad index from migrate or any other reason
This commit is contained in:
parent
6784e6aab4
commit
575cce1a7d
10 changed files with 283 additions and 32 deletions
|
@ -42,6 +42,17 @@ class MainDB {
|
|||
await isar.addresses.putAll(addresses);
|
||||
});
|
||||
|
||||
Future<void> updateAddress(Address oldAddress, Address newAddress) =>
|
||||
isar.writeTxn(() async {
|
||||
newAddress.id = oldAddress.id;
|
||||
await oldAddress.transaction.load();
|
||||
final txns = oldAddress.transaction.toList();
|
||||
await isar.addresses.delete(oldAddress.id);
|
||||
await isar.addresses.put(newAddress);
|
||||
newAddress.transaction.addAll(txns);
|
||||
await newAddress.transaction.save();
|
||||
});
|
||||
|
||||
// transactions
|
||||
QueryBuilder<Transaction, Transaction, QAfterWhereClause> getTransactions(
|
||||
String walletId) =>
|
||||
|
|
|
@ -1859,8 +1859,23 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1886,8 +1901,23 @@ class BitcoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1746,8 +1746,23 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip44);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1778,8 +1793,23 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip44);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1650,8 +1650,23 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip44);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1682,8 +1697,23 @@ class DogecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip44);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -3147,8 +3147,23 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
newReceivingIndex,
|
||||
);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -3182,8 +3197,23 @@ class FiroWallet extends CoinServiceAPI with WalletCache, WalletDB, FiroHive {
|
|||
newChangeIndex,
|
||||
);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1885,8 +1885,23 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1912,8 +1927,23 @@ class LitecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1131,8 +1131,23 @@ class MoneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress =
|
||||
await _generateAddressForChain(0, newReceivingIndex);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1867,8 +1867,23 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1894,8 +1909,23 @@ class NamecoinWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1754,8 +1754,23 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress = await _generateAddressForChain(
|
||||
0, newReceivingIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} catch (e, s) {
|
||||
Logging.instance.log(
|
||||
|
@ -1781,8 +1796,23 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newChangeAddress = await _generateAddressForChain(
|
||||
1, newChangeIndex, DerivePathType.bip84);
|
||||
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newChangeAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newChangeAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
|
@ -1200,8 +1200,23 @@ class WowneroWallet extends CoinServiceAPI with WalletCache, WalletDB {
|
|||
final newReceivingAddress =
|
||||
await _generateAddressForChain(0, newReceivingIndex);
|
||||
|
||||
// Add that new receiving address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
final existing = await db
|
||||
.getAddresses(walletId)
|
||||
.filter()
|
||||
.valueEqualTo(newReceivingAddress.value)
|
||||
.findFirst();
|
||||
if (existing == null) {
|
||||
// Add that new change address
|
||||
await db.putAddress(newReceivingAddress);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
} on SocketException catch (se, s) {
|
||||
Logging.instance.log(
|
||||
|
|
Loading…
Reference in a new issue