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 22, 2023
1 parent eb63c2c commit fbaa2c3
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 @@ -5,6 +5,7 @@ use bitcoin::{
BlockHash, Txid,
};
use crossbeam_channel::Receiver;
use num_traits::FromPrimitive;
use rayon::prelude::*;
use serde_derive::Deserialize;
use serde_json::{self, json, Value};
Expand All @@ -17,7 +18,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 +625,17 @@ impl Params {
}
})
}
fn parse_rpc_error_code(&self, code: i32) -> Option<RpcError> {
match self {
Params::TransactionGet(_) => match RPCErrorCode::from_i32(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 fbaa2c3

Please sign in to comment.