Skip to content

Commit aba4bce

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

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

Lines changed: 7 additions & 3 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());

0 commit comments

Comments
 (0)