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 17, 2023
1 parent 45e113a commit e5b899c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/electrum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@ impl Params {
}
})
}
fn parse_rpc_error_code(&self, code: i32) -> Option<RpcError> {
match self {
Params::TransactionGet(_) => match code {
daemon::RPC_INVALID_ADDRESS_OR_KEY => {
Some(RpcError::BadRequest(anyhow!("Transaction not found")))
}
_ => None,
},
_ => None,
}
}
}

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

Please sign in to comment.