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 31, 2023
1 parent fbae265 commit 2f4e29d
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 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, CoreRPCErrorCode, Daemon},
merkle::Proof,
metrics::{self, Histogram, Metrics},
signals::Signal,
Expand Down Expand Up @@ -624,6 +624,17 @@ impl Params {
}
})
}
fn parse_rpc_error_code(&self, code: i16) -> Option<RpcError> {
match self {
Params::TransactionGet(_) => match CoreRPCErrorCode::from_error_code(code) {
Some(CoreRPCErrorCode::RpcInvalidAddressOrKey) => {
Some(RpcError::BadRequest(anyhow!("Transaction not found")))
}
_ => None,
},
_ => None,
}
}
}

struct Call {
Expand Down Expand Up @@ -653,7 +664,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 2f4e29d

Please sign in to comment.