Skip to content

Commit

Permalink
refactor: include source string in hex error
Browse files Browse the repository at this point in the history
  • Loading branch information
doitian committed Jul 3, 2024
1 parent 3e72e08 commit 5421614
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/cch/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ impl CchActor {
.wrapped_btc_type_script_args
.trim_start_matches("0x"),
)
.map_err(|_| CchError::HexDecodingError)?
.map_err(|_| {
CchError::HexDecodingError(self.config.wrapped_btc_type_script_args.clone())
})?
.as_ref(),
)
.into();
Expand Down Expand Up @@ -488,7 +490,7 @@ impl CchActor {
) -> Result<ReceiveBTCOrder, CchError> {
let duration_since_epoch = SystemTime::now().duration_since(UNIX_EPOCH)?;
let hash_bin = hex::decode(&receive_btc.payment_hash.trim_start_matches("0x"))
.map_err(|_| CchError::HexDecodingError)?;
.map_err(|_| CchError::HexDecodingError(receive_btc.payment_hash.clone()))?;

let amount_sats = receive_btc.amount_sats as u128;
let fee_sats = amount_sats * (self.config.fee_rate_per_million_sats as u128)
Expand Down Expand Up @@ -524,7 +526,9 @@ impl CchActor {
.wrapped_btc_type_script_args
.trim_start_matches("0x"),
)
.map_err(|_| CchError::HexDecodingError)?
.map_err(|_| {
CchError::HexDecodingError(self.config.wrapped_btc_type_script_args.clone())
})?
.as_ref(),
)
.into();
Expand Down
4 changes: 2 additions & 2 deletions src/cch/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub enum CchError {
SystemTimeError(#[from] SystemTimeError),
#[error("JSON serialization error: {0}")]
JSONSerializationError(#[from] serde_json::Error),
#[error("Hex decoding error")]
HexDecodingError,
#[error("Hex decoding error from string: {0}")]
HexDecodingError(String),
#[error("Lnd channel error: {0}")]
LndChannelError(#[from] lnd_grpc_tonic_client::channel::Error),
#[error("Lnd RPC error: {0}")]
Expand Down
3 changes: 2 additions & 1 deletion src/cch/order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ impl SendBTCOrder {
let invoice_builder = InvoiceBuilder::new(self.currency)
.amount(Some(self.amount_sats))
.payment_hash(
Hash256::from_str(&self.payment_hash).map_err(|_| CchError::HexDecodingError)?,
Hash256::from_str(&self.payment_hash)
.map_err(|_| CchError::HexDecodingError(self.payment_hash.clone()))?,
)
.expiry_time(Duration::from_secs(self.expires_after))
.final_cltv(self.ckb_final_tlc_expiry)
Expand Down

0 comments on commit 5421614

Please sign in to comment.