Skip to content

Commit

Permalink
rs: Implement a best-effort msat to sat conversion
Browse files Browse the repository at this point in the history
Some methods (`withdraw`) require their parameter to be in satoshis
rather than millisats. In order for us not to have to come up with yet
another triple of sat, sat_or_all, and sat_or_any, we just bolt it
onto the conversion.
  • Loading branch information
cdecker committed Sep 28, 2023
1 parent 7f7bbd6 commit f46b132
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cln-rpc/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,13 @@ impl TryFrom<&str> for Amount {

impl From<Amount> for String {
fn from(a: Amount) -> String {
format!("{}msat", a.msat)
// Best effort msat to sat conversion, for methods that accept
// sats but not msats
if a.msat % 1000 == 0 {
format!("{}sat", a.msat / 1000)
} else {
format!("{}msat", a.msat)
}
}
}

Expand Down

0 comments on commit f46b132

Please sign in to comment.