ensure litescribe api call failures don't block wallet functionality

This commit is contained in:
julian 2024-01-11 12:50:42 -06:00
parent 73767a474e
commit dc9054138c

View file

@ -3,6 +3,7 @@ import 'package:stackwallet/dto/ordinals/inscription_data.dart';
import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart'; import 'package:stackwallet/models/isar/models/blockchain_data/utxo.dart';
import 'package:stackwallet/models/isar/ordinal.dart'; import 'package:stackwallet/models/isar/ordinal.dart';
import 'package:stackwallet/services/litescribe_api.dart'; import 'package:stackwallet/services/litescribe_api.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart'; import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/electrumx_interface.dart';
mixin OrdinalsInterface on ElectrumXInterface { mixin OrdinalsInterface on ElectrumXInterface {
@ -11,10 +12,11 @@ mixin OrdinalsInterface on ElectrumXInterface {
// check if an inscription is in a given <UTXO> output // check if an inscription is in a given <UTXO> output
Future<bool> _inscriptionInAddress(String address) async { Future<bool> _inscriptionInAddress(String address) async {
var inscriptions = await litescribeAPI.getInscriptionsByAddress(address); try {
if (inscriptions.isNotEmpty) { return (await litescribeAPI.getInscriptionsByAddress(address)).isNotEmpty;
return true; } catch (_) {
} else { Logging.instance.log("Litescribe api failure!", level: LogLevel.Error);
return false; return false;
} }
} }
@ -63,12 +65,11 @@ mixin OrdinalsInterface on ElectrumXInterface {
// TODO check the specific output, not just the address in general // TODO check the specific output, not just the address in general
// TODO optimize by freezing output in OrdinalsInterface, so one ordinal API calls is made (or at least many less) // TODO optimize by freezing output in OrdinalsInterface, so one ordinal API calls is made (or at least many less)
if (utxoOwnerAddress != null) { if (utxoOwnerAddress != null &&
if (await _inscriptionInAddress(utxoOwnerAddress)) { await _inscriptionInAddress(utxoOwnerAddress)) {
shouldBlock = true; shouldBlock = true;
blockReason = "Ordinal"; blockReason = "Ordinal";
label = "Ordinal detected at address"; label = "Ordinal detected at address";
}
} else { } else {
// TODO implement inscriptionInOutput // TODO implement inscriptionInOutput
if (utxoAmount <= 10000) { if (utxoAmount <= 10000) {
@ -85,7 +86,11 @@ mixin OrdinalsInterface on ElectrumXInterface {
Future<bool> updateUTXOs() async { Future<bool> updateUTXOs() async {
final newUtxosAdded = await super.updateUTXOs(); final newUtxosAdded = await super.updateUTXOs();
if (newUtxosAdded) { if (newUtxosAdded) {
await refreshInscriptions(); try {
await refreshInscriptions();
} catch (_) {
// do nothing but do not block/fail this updateUTXOs call based on litescribe call failures
}
} }
return newUtxosAdded; return newUtxosAdded;