Skip to content

Commit

Permalink
Hndl RPC_INVALID_ADDRESS_OR_KEY err for transaction.get
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunovo committed Oct 18, 2023
1 parent fd06fd9 commit c2d5a70
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, Daemon, RPCErrorCode},
merkle::Proof,
metrics::{self, Histogram, Metrics},
signals::Signal,
Expand Down Expand Up @@ -624,6 +624,18 @@ impl Params {
}
})
}
fn parse_rpc_error_code(&self, code: i32) -> Option<RpcError> {
let rpc_err_code = RPCErrorCode::parse_code(code);
match self {
Params::TransactionGet(_) => match rpc_err_code {
Some(RPCErrorCode::RpcInvalidAddressOrKey(_)) => {
Some(RpcError::BadRequest(anyhow!("Transaction not found")))
}
_ => None,
},
_ => None,
}
}
}

struct Call {
Expand Down Expand Up @@ -653,7 +665,10 @@ impl Call {
.downcast_ref::<bitcoincore_rpc::Error>()
.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)),
}
}
Expand Down

0 comments on commit c2d5a70

Please sign in to comment.