mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-02-02 11:16:36 +00:00
check paynym receiving addresses based on payment code notification tx history
This commit is contained in:
parent
4170ca958f
commit
9cc0d74b16
2 changed files with 66 additions and 0 deletions
|
@ -762,6 +762,8 @@ class DogecoinWallet extends CoinServiceAPI
|
|||
GlobalEventBus.instance.fire(RefreshPercentChangedEvent(0.3, walletId));
|
||||
await _checkCurrentReceivingAddressesForTransactions();
|
||||
|
||||
await checkAllCurrentReceivingPaynymAddressesForTransactions();
|
||||
|
||||
final fetchFuture = _refreshTransactions();
|
||||
final utxosRefreshFuture = _updateUTXOs();
|
||||
GlobalEventBus.instance
|
||||
|
|
|
@ -108,6 +108,70 @@ mixin PaynymWalletInterface {
|
|||
// convenience getter
|
||||
btc_dart.NetworkType get networkType => _network;
|
||||
|
||||
Future<Address> currentReceivingPaynymAddress(PaymentCode sender) async {
|
||||
final address = await _db
|
||||
.getAddresses(_walletId)
|
||||
.filter()
|
||||
.group((q) => q
|
||||
.subTypeEqualTo(AddressSubType.paynymReceive)
|
||||
.and()
|
||||
.otherDataEqualTo(sender.toString()))
|
||||
.sortByDerivationIndexDesc()
|
||||
.findFirst();
|
||||
|
||||
if (address == null) {
|
||||
final generatedAddress = await _generatePaynymReceivingAddress(sender, 0);
|
||||
await _db.putAddress(generatedAddress);
|
||||
return currentReceivingPaynymAddress(sender);
|
||||
} else {
|
||||
return address;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Address> _generatePaynymReceivingAddress(
|
||||
PaymentCode sender,
|
||||
int index,
|
||||
) async {
|
||||
final myPrivateKey =
|
||||
await deriveNotificationPrivateKey(mnemonic: await _getMnemonic());
|
||||
final paymentAddress = PaymentAddress.initWithPrivateKey(
|
||||
myPrivateKey,
|
||||
sender,
|
||||
index,
|
||||
);
|
||||
final pair = paymentAddress.getReceiveAddressKeyPair();
|
||||
final address = generatePaynymReceivingAddressFromKeyPair(
|
||||
pair: pair,
|
||||
derivationIndex: index,
|
||||
derivePathType: DerivePathType.bip44,
|
||||
fromPaymentCode: sender,
|
||||
);
|
||||
return address;
|
||||
}
|
||||
|
||||
Future<void> checkCurrentPaynymReceivingAddressForTransactions(
|
||||
PaymentCode sender) async {
|
||||
final address = await currentReceivingPaynymAddress(sender);
|
||||
final txCount = await _getTxCount(address: address.value);
|
||||
if (txCount > 0) {
|
||||
// generate next address and add to db
|
||||
final nextAddress = await _generatePaynymReceivingAddress(
|
||||
sender,
|
||||
address.derivationIndex + 1,
|
||||
);
|
||||
await _db.putAddress(nextAddress);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> checkAllCurrentReceivingPaynymAddressesForTransactions() async {
|
||||
final codes = await getAllPaymentCodesFromNotificationTransactions();
|
||||
final List<Future<void>> futures = [];
|
||||
for (final code in codes) {
|
||||
futures.add(checkCurrentPaynymReceivingAddressForTransactions(code));
|
||||
}
|
||||
await Future.wait(futures);
|
||||
}
|
||||
|
||||
// generate bip32 payment code root
|
||||
Future<bip32.BIP32> getRootNode({
|
||||
required List<String> mnemonic,
|
||||
|
|
Loading…
Reference in a new issue