From dc9054138c5ba0fac5f680d316577cf93391094c Mon Sep 17 00:00:00 2001 From: julian Date: Thu, 11 Jan 2024 12:50:42 -0600 Subject: [PATCH] ensure litescribe api call failures don't block wallet functionality --- .../ordinals_interface.dart | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/lib/wallets/wallet/wallet_mixin_interfaces/ordinals_interface.dart b/lib/wallets/wallet/wallet_mixin_interfaces/ordinals_interface.dart index d0a741513..e78021544 100644 --- a/lib/wallets/wallet/wallet_mixin_interfaces/ordinals_interface.dart +++ b/lib/wallets/wallet/wallet_mixin_interfaces/ordinals_interface.dart @@ -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/ordinal.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'; mixin OrdinalsInterface on ElectrumXInterface { @@ -11,10 +12,11 @@ mixin OrdinalsInterface on ElectrumXInterface { // check if an inscription is in a given output Future _inscriptionInAddress(String address) async { - var inscriptions = await litescribeAPI.getInscriptionsByAddress(address); - if (inscriptions.isNotEmpty) { - return true; - } else { + try { + return (await litescribeAPI.getInscriptionsByAddress(address)).isNotEmpty; + } catch (_) { + Logging.instance.log("Litescribe api failure!", level: LogLevel.Error); + return false; } } @@ -63,12 +65,11 @@ mixin OrdinalsInterface on ElectrumXInterface { // 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) - if (utxoOwnerAddress != null) { - if (await _inscriptionInAddress(utxoOwnerAddress)) { - shouldBlock = true; - blockReason = "Ordinal"; - label = "Ordinal detected at address"; - } + if (utxoOwnerAddress != null && + await _inscriptionInAddress(utxoOwnerAddress)) { + shouldBlock = true; + blockReason = "Ordinal"; + label = "Ordinal detected at address"; } else { // TODO implement inscriptionInOutput if (utxoAmount <= 10000) { @@ -85,7 +86,11 @@ mixin OrdinalsInterface on ElectrumXInterface { Future updateUTXOs() async { final newUtxosAdded = await super.updateUTXOs(); 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;