handle dropped mempool/blockchain transactions

This commit is contained in:
julian 2023-01-27 12:49:25 -06:00
parent 2dd8a5b190
commit 451edbfc67
5 changed files with 39 additions and 3 deletions

View file

@ -137,7 +137,9 @@ class ElectrumX {
.toString()
.contains("No such mempool or blockchain transaction")) {
throw NoSuchTransactionException(
"No such mempool or blockchain transaction: ${args.first}");
"No such mempool or blockchain transaction",
args.first.toString(),
);
}
throw Exception(

View file

@ -1,5 +1,7 @@
import 'package:stackwallet/exceptions/sw_exception.dart';
class NoSuchTransactionException extends SWException {
NoSuchTransactionException(super.message);
final String txid;
NoSuchTransactionException(super.message, this.txid);
}

View file

@ -14,6 +14,7 @@ import 'package:isar/isar.dart';
import 'package:stackwallet/db/main_db.dart';
import 'package:stackwallet/electrumx_rpc/cached_electrumx.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart';
import 'package:stackwallet/models/balance.dart';
import 'package:stackwallet/models/isar/models/isar_models.dart' as isar_models;
import 'package:stackwallet/models/paymint/fee_object_model.dart';
@ -611,6 +612,13 @@ class DogecoinWallet extends CoinServiceAPI
}
}
return needsRefresh;
} on NoSuchTransactionException catch (e) {
// TODO: move direct transactions elsewhere
await db.isar.writeTxn(() async {
await db.isar.transactions.deleteByTxidWalletId(e.txid, walletId);
});
await txTracker.deleteTransaction(e.txid);
return true;
} catch (e, s) {
Logging.instance.log(
"Exception caught in refreshIfThereIsNewData: $e\n$s",

View file

@ -2,6 +2,7 @@ import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:stackwallet/electrumx_rpc/electrumx.dart';
import 'package:stackwallet/exceptions/electrumx/no_such_transaction.dart';
import 'package:stackwallet/hive/db.dart';
import 'package:stackwallet/models/exchange/response_objects/trade.dart';
import 'package:stackwallet/models/notification_model.dart';
@ -169,12 +170,14 @@ class NotificationsService extends ChangeNotifier {
}
// replaces the current notification with the updated one
add(updatedNotification, true);
await add(updatedNotification, true);
}
} else {
// TODO: check non electrumx coins
}
}
} on NoSuchTransactionException catch (e, s) {
await _deleteWatchedTxNotification(notification);
} catch (e, s) {
Logging.instance.log("$e $s", level: LogLevel.Error);
}

View file

@ -54,4 +54,25 @@ class TransactionNotificationTracker {
key: "notifiedConfirmedTransactions",
value: notifiedConfirmedTransactions);
}
Future<void> deleteTransaction(String txid) async {
final notifiedPendingTransactions = DB.instance.get<dynamic>(
boxName: walletId, key: "notifiedPendingTransactions") as Map? ??
{};
final notifiedConfirmedTransactions = DB.instance.get<dynamic>(
boxName: walletId, key: "notifiedConfirmedTransactions") as Map? ??
{};
notifiedPendingTransactions.remove(txid);
notifiedConfirmedTransactions.remove(txid);
await DB.instance.put<dynamic>(
boxName: walletId,
key: "notifiedConfirmedTransactions",
value: notifiedConfirmedTransactions);
await DB.instance.put<dynamic>(
boxName: walletId,
key: "notifiedPendingTransactions",
value: notifiedPendingTransactions);
}
}