Merge pull request #335 from cypherstack/paynyms

bug fixes
This commit is contained in:
Diego Salazar 2023-02-02 12:19:14 -07:00 committed by GitHub
commit 0d9066b517
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 147 additions and 62 deletions

View file

@ -103,9 +103,11 @@ class AddressCard extends StatelessWidget {
return RoundedWhiteContainer( return RoundedWhiteContainer(
child: Row( child: Row(
children: [ children: [
Text( Expanded(
address.value, child: Text(
style: STextStyles.itemSubtitle12(context), address.value,
style: STextStyles.itemSubtitle12(context),
),
) )
], ],
), ),

View file

@ -524,6 +524,7 @@ class BitcoinWallet extends CoinServiceAPI
required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
bool isRescan = false,
}) async { }) async {
longMutex = true; longMutex = true;
@ -697,14 +698,25 @@ class BitcoinWallet extends CoinServiceAPI
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await db.putAddresses([ if (isRescan) {
...p2wpkhReceiveAddressArray, await db.updateOrPutAddresses([
...p2wpkhChangeAddressArray, ...p2wpkhReceiveAddressArray,
...p2pkhReceiveAddressArray, ...p2wpkhChangeAddressArray,
...p2pkhChangeAddressArray, ...p2pkhReceiveAddressArray,
...p2shReceiveAddressArray, ...p2pkhChangeAddressArray,
...p2shChangeAddressArray, ...p2shReceiveAddressArray,
]); ...p2shChangeAddressArray,
]);
} else {
await db.putAddresses([
...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray,
...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
]);
}
// get own payment code // get own payment code
final myCode = await getPaymentCode(DerivePathType.bip44); final myCode = await getPaymentCode(DerivePathType.bip44);
@ -2932,6 +2944,7 @@ class BitcoinWallet extends CoinServiceAPI
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;

View file

@ -491,11 +491,13 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
} }
Future<void> _recoverWalletFromBIP32SeedPhrase( Future<void> _recoverWalletFromBIP32SeedPhrase({
{required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
Coin? coin}) async { bool isRescan = false,
Coin? coin,
}) async {
longMutex = true; longMutex = true;
Map<String, Map<String, String>> bip44P2pkhReceiveDerivations = {}; Map<String, Map<String, String>> bip44P2pkhReceiveDerivations = {};
@ -631,6 +633,13 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2shChangeAddressArray.add(address); p2shChangeAddressArray.add(address);
} }
final addressesToStore = [
...bip44P2pkhReceiveAddressArray,
...bip44P2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
];
if (!testnet) { if (!testnet) {
final resultReceiveBch44 = _checkGaps( final resultReceiveBch44 = _checkGaps(
maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck,
@ -689,21 +698,16 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
bch44P2pkhChangeAddressArray.add(address); bch44P2pkhChangeAddressArray.add(address);
} }
await db.putAddresses([ addressesToStore.addAll([
...bip44P2pkhReceiveAddressArray, ...bch44P2pkhReceiveAddressArray,
...bip44P2pkhChangeAddressArray, ...bch44P2pkhChangeAddressArray,
...bch44P2pkhReceiveAddressArray,
...bch44P2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
]); ]);
}
if (isRescan) {
await db.updateOrPutAddresses(addressesToStore);
} else { } else {
await db.putAddresses([ await db.putAddresses(addressesToStore);
...bip44P2pkhReceiveAddressArray,
...bip44P2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
]);
} }
await _updateUTXOs(); await _updateUTXOs();
@ -2732,19 +2736,28 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
// p2pkh / bip44 // p2pkh / bip44
final p2pkhLength = addressesP2PKH.length; final p2pkhLength = addressesP2PKH.length;
if (p2pkhLength > 0) { if (p2pkhLength > 0) {
final receiveDerivations = await _fetchDerivations( final receiveDerivationsBip44 = await _fetchDerivations(
chain: 0, chain: 0,
derivePathType: DerivePathType.bip44, derivePathType: DerivePathType.bip44,
); );
final changeDerivations = await _fetchDerivations( final changeDerivationsBip44 = await _fetchDerivations(
chain: 1, chain: 1,
derivePathType: DerivePathType.bip44, 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++) { for (int i = 0; i < p2pkhLength; i++) {
String address = addressesP2PKH[i]; String address = addressesP2PKH[i];
// receives // receives
final receiveDerivation = receiveDerivations[address]; final receiveDerivation = receiveDerivationsBip44[address] ??
receiveDerivationsBch44[address];
// if a match exists it will not be null // if a match exists it will not be null
if (receiveDerivation != null) { if (receiveDerivation != null) {
final data = P2PKH( final data = P2PKH(
@ -2765,7 +2778,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
} }
} else { } else {
// if its not a receive, check change // 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 a match exists it will not be null
if (changeDerivation != null) { if (changeDerivation != null) {
final data = P2PKH( final data = P2PKH(
@ -2976,6 +2990,7 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;

View file

@ -465,6 +465,7 @@ class DogecoinWallet extends CoinServiceAPI
required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
bool isRescan = false,
}) async { }) async {
longMutex = true; longMutex = true;
@ -541,11 +542,17 @@ class DogecoinWallet extends CoinServiceAPI
await _generateAddressForChain(1, 0, DerivePathType.bip44); await _generateAddressForChain(1, 0, DerivePathType.bip44);
p2pkhChangeAddressArray.add(address); p2pkhChangeAddressArray.add(address);
} }
if (isRescan) {
await db.putAddresses([ await db.updateOrPutAddresses([
...p2pkhReceiveAddressArray, ...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray, ...p2pkhChangeAddressArray,
]); ]);
} else {
await db.putAddresses([
...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray,
]);
}
// paynym stuff // paynym stuff
// // generate to ensure notification address is in db before refreshing transactions // // generate to ensure notification address is in db before refreshing transactions
@ -2574,6 +2581,7 @@ class DogecoinWallet extends CoinServiceAPI
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;

View file

@ -839,6 +839,10 @@ class EpicCashWallet extends CoinServiceAPI
isar_models.Address? address = await db isar_models.Address? address = await db
.getAddresses(walletId) .getAddresses(walletId)
.filter() .filter()
.subTypeEqualTo(isar_models.AddressSubType.receiving)
.and()
.typeEqualTo(isar_models.AddressType.mimbleWimble)
.and()
.derivationIndexEqualTo(index) .derivationIndexEqualTo(index)
.findFirst(); .findFirst();
@ -877,8 +881,14 @@ class EpicCashWallet extends CoinServiceAPI
(await _currentReceivingAddress)?.value ?? (await _currentReceivingAddress)?.value ??
(await _getReceivingAddressForIndex(0)).value; (await _getReceivingAddressForIndex(0)).value;
Future<isar_models.Address?> get _currentReceivingAddress => Future<isar_models.Address?> get _currentReceivingAddress => db
db.getAddresses(walletId).sortByDerivationIndexDesc().findFirst(); .getAddresses(walletId)
.filter()
.subTypeEqualTo(isar_models.AddressSubType.receiving)
.and()
.typeEqualTo(isar_models.AddressType.mimbleWimble)
.sortByDerivationIndexDesc()
.findFirst();
@override @override
Future<void> exit() async { Future<void> exit() async {

View file

@ -517,6 +517,7 @@ class LitecoinWallet extends CoinServiceAPI
required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
bool isRescan = false,
}) async { }) async {
longMutex = true; longMutex = true;
@ -690,14 +691,25 @@ class LitecoinWallet extends CoinServiceAPI
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await db.putAddresses([ if (isRescan) {
...p2wpkhReceiveAddressArray, await db.updateOrPutAddresses([
...p2wpkhChangeAddressArray, ...p2wpkhReceiveAddressArray,
...p2pkhReceiveAddressArray, ...p2wpkhChangeAddressArray,
...p2pkhChangeAddressArray, ...p2pkhReceiveAddressArray,
...p2shReceiveAddressArray, ...p2pkhChangeAddressArray,
...p2shChangeAddressArray, ...p2shReceiveAddressArray,
]); ...p2shChangeAddressArray,
]);
} else {
await db.putAddresses([
...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray,
...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
]);
}
await _updateUTXOs(); await _updateUTXOs();
@ -2895,6 +2907,7 @@ class LitecoinWallet extends CoinServiceAPI
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;

View file

@ -507,6 +507,7 @@ class NamecoinWallet extends CoinServiceAPI
required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
bool isRescan = false,
}) async { }) async {
longMutex = true; longMutex = true;
@ -680,14 +681,25 @@ class NamecoinWallet extends CoinServiceAPI
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await db.putAddresses([ if (isRescan) {
...p2wpkhReceiveAddressArray, await db.updateOrPutAddresses([
...p2wpkhChangeAddressArray, ...p2wpkhReceiveAddressArray,
...p2pkhReceiveAddressArray, ...p2wpkhChangeAddressArray,
...p2pkhChangeAddressArray, ...p2pkhReceiveAddressArray,
...p2shReceiveAddressArray, ...p2pkhChangeAddressArray,
...p2shChangeAddressArray, ...p2shReceiveAddressArray,
]); ...p2shChangeAddressArray,
]);
} else {
await db.putAddresses([
...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray,
...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray,
...p2shReceiveAddressArray,
...p2shChangeAddressArray,
]);
}
await _updateUTXOs(); await _updateUTXOs();
@ -2884,6 +2896,7 @@ class NamecoinWallet extends CoinServiceAPI
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;

View file

@ -489,6 +489,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
required String mnemonic, required String mnemonic,
int maxUnusedAddressGap = 20, int maxUnusedAddressGap = 20,
int maxNumberOfIndexesToCheck = 1000, int maxNumberOfIndexesToCheck = 1000,
bool isRescan = false,
}) async { }) async {
longMutex = true; longMutex = true;
@ -614,12 +615,21 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
p2wpkhChangeAddressArray.add(address); p2wpkhChangeAddressArray.add(address);
} }
await db.putAddresses([ if (isRescan) {
...p2wpkhReceiveAddressArray, await db.updateOrPutAddresses([
...p2wpkhChangeAddressArray, ...p2wpkhReceiveAddressArray,
...p2pkhReceiveAddressArray, ...p2wpkhChangeAddressArray,
...p2pkhChangeAddressArray, ...p2pkhReceiveAddressArray,
]); ...p2pkhChangeAddressArray,
]);
} else {
await db.putAddresses([
...p2wpkhReceiveAddressArray,
...p2wpkhChangeAddressArray,
...p2pkhReceiveAddressArray,
...p2pkhChangeAddressArray,
]);
}
await _updateUTXOs(); await _updateUTXOs();
@ -2982,6 +2992,7 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
mnemonic: mnemonic!, mnemonic: mnemonic!,
maxUnusedAddressGap: maxUnusedAddressGap, maxUnusedAddressGap: maxUnusedAddressGap,
maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck, maxNumberOfIndexesToCheck: maxNumberOfIndexesToCheck,
isRescan: true,
); );
longMutex = false; longMutex = false;