Skip to content

Commit c2d5a70

Browse files
committed
Hndl RPC_INVALID_ADDRESS_OR_KEY err for transaction.get
1 parent fd06fd9 commit c2d5a70

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/electrum.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::str::FromStr;
1717
use crate::{
1818
cache::Cache,
1919
config::{Config, ELECTRS_VERSION},
20-
daemon::{self, extract_bitcoind_error, Daemon},
20+
daemon::{self, extract_bitcoind_error, Daemon, RPCErrorCode},
2121
merkle::Proof,
2222
metrics::{self, Histogram, Metrics},
2323
signals::Signal,
@@ -624,6 +624,18 @@ impl Params {
624624
}
625625
})
626626
}
627+
fn parse_rpc_error_code(&self, code: i32) -> Option<RpcError> {
628+
let rpc_err_code = RPCErrorCode::parse_code(code);
629+
match self {
630+
Params::TransactionGet(_) => match rpc_err_code {
631+
Some(RPCErrorCode::RpcInvalidAddressOrKey(_)) => {
632+
Some(RpcError::BadRequest(anyhow!("Transaction not found")))
633+
}
634+
_ => None,
635+
},
636+
_ => None,
637+
}
638+
}
627639
}
628640

629641
struct Call {
@@ -653,7 +665,10 @@ impl Call {
653665
.downcast_ref::<bitcoincore_rpc::Error>()
654666
.and_then(extract_bitcoind_error)
655667
{
656-
Some(e) => error_msg(&self.id, RpcError::DaemonError(e.clone())),
668+
Some(e) => match self.params.parse_rpc_error_code(e.code) {
669+
Some(err) => error_msg(&self.id, err),
670+
None => error_msg(&self.id, RpcError::DaemonError(e.clone())),
671+
},
657672
None => error_msg(&self.id, RpcError::BadRequest(err)),
658673
}
659674
}

0 commit comments

Comments
 (0)