From 6f0674f64bfd44dcf6424660f60bd497fd1376dc Mon Sep 17 00:00:00 2001 From: Novo Date: Tue, 17 Oct 2023 09:15:35 +0100 Subject: [PATCH] Hndl RPC_INVALID_ADDRESS_OR_KEY err for transaction.get --- src/electrum.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/electrum.rs b/src/electrum.rs index fed999454..ceb759b40 100644 --- a/src/electrum.rs +++ b/src/electrum.rs @@ -17,7 +17,7 @@ use std::str::FromStr; use crate::{ cache::Cache, config::{Config, ELECTRS_VERSION}, - daemon::{self, extract_bitcoind_error, Daemon}, + daemon::{self, extract_bitcoind_error, CoreRPCErrorCode, Daemon}, merkle::Proof, metrics::{self, Histogram, Metrics}, signals::Signal, @@ -624,6 +624,17 @@ impl Params { } }) } + fn parse_rpc_error_code(&self, code: i32) -> Option { + match self { + Params::TransactionGet(_) => match CoreRPCErrorCode::from_error_code(code) { + Some(CoreRPCErrorCode::RpcInvalidAddressOrKey) => { + Some(RpcError::BadRequest(anyhow!("Transaction not found"))) + } + _ => None, + }, + _ => None, + } + } } struct Call { @@ -653,7 +664,10 @@ impl Call { .downcast_ref::() .and_then(extract_bitcoind_error) { - Some(e) => error_msg(&self.id, RpcError::DaemonError(e.clone())), + Some(e) => match self.params.parse_rpc_error_code(e.code) { + Some(err) => error_msg(&self.id, err), + None => error_msg(&self.id, RpcError::DaemonError(e.clone())), + }, None => error_msg(&self.id, RpcError::BadRequest(err)), } }