Skip to content

Commit 4927f5d

Browse files
committed
potential way to handle the bad f64->u64 conversion
1 parent 69475ad commit 4927f5d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/interledger-service-util/src/exchange_rates_service.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,13 @@ where
9999

100100
match outgoing_amount {
101101
Ok(outgoing_amount) => {
102-
// NOTE: If the f64 amount could not fit in a u64, then the
103-
// typecast makes the outgoing amount 0.
104-
request.prepare.set_amount(outgoing_amount as u64);
102+
let outgoing_amount_u64 =
103+
if outgoing_amount != 0.0 && outgoing_amount as u64 == 0 {
104+
std::u64::MAX
105+
} else {
106+
outgoing_amount as u64
107+
};
108+
request.prepare.set_amount(outgoing_amount_u64);
105109
trace!("Converted incoming amount of: {} {} (scale {}) from account {} to outgoing amount of: {} {} (scale {}) for account {}",
106110
request.original_amount, request.from.asset_code(), request.from.asset_scale(), request.from.id(),
107111
outgoing_amount, request.to.asset_code(), request.to.asset_scale(), request.to.id());
@@ -110,11 +114,12 @@ where
110114
return Box::new(err(RejectBuilder {
111115
code: ErrorCode::F08_AMOUNT_TOO_LARGE,
112116
message: format!(
113-
"Could not convert exchange rate from {}:{} to: {}:{}",
117+
"Could not convert exchange rate from {}:{} to: {}:{}. Got incoming amount: {}",
114118
request.from.asset_code(),
115119
request.from.asset_scale(),
116120
request.to.asset_code(),
117121
request.to.asset_scale(),
122+
request.prepare.amount(),
118123
)
119124
.as_bytes(),
120125
triggered_by: Some(&self.ilp_address),

0 commit comments

Comments
 (0)