Skip to content

Commit

Permalink
esplora: if an API will timeout we log the error
Browse files Browse the repository at this point in the history
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
  • Loading branch information
vincenzopalazzo committed Mar 13, 2024
1 parent aedd703 commit de39d1c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion folgore-esplora/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use folgore_common::cln;
use folgore_common::cln::json_utils;
use folgore_common::cln::plugin::error;
use folgore_common::cln::plugin::errors::PluginError;
use folgore_common::cln::plugin::types::LogLevel;
use folgore_common::prelude::log;

Check warning on line 20 in folgore-esplora/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly

Check warning on line 20 in folgore-esplora/src/lib.rs

View workflow job for this annotation

GitHub Actions / Build (nightly)

the item `log` is imported redundantly
use folgore_common::stragegy::RecoveryStrategy;
use folgore_common::utils::ByteBuf;
Expand Down Expand Up @@ -241,7 +242,7 @@ impl<T: Clone, S: RecoveryStrategy> FolgoreBackend<T> for Esplora<S> {

fn sync_get_utxo(
&self,
_: &mut cln::plugin::plugin::Plugin<T>,
plugin: &mut cln::plugin::plugin::Plugin<T>,
txid: &str,
idx: u64,
) -> Result<serde_json::Value, PluginError> {
Expand All @@ -260,9 +261,16 @@ impl<T: Clone, S: RecoveryStrategy> FolgoreBackend<T> for Esplora<S> {
let utxo = self.recovery_strategy.apply(|| {
let result = self.client.call::<Tx>(&format!("/tx/{txid}"));
if let Err(err) = result {
log::debug!("call to `tx/{txid}` API return error: {:?}", err);
let err_code = err.code();
if err_code == 404 {
return Ok(Tx { vout: vec![] });
} else if err_code == 400 {
plugin.log(
LogLevel::Warn,
&format!("error from esplora API `{:?}`", err),
);
return Ok(Tx { vout: vec![] });
} else {
return Err(error!("{err}"));
}
Expand Down

0 comments on commit de39d1c

Please sign in to comment.