mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-03-15 20:09:18 +01:00
rs: Implement a best-effort msat to sat conversion
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.
This commit is contained in:
parent
394e926cb7
commit
76c5e6aa65
1 changed files with 9 additions and 3 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -559,14 +565,14 @@ mod test {
|
|||
(
|
||||
"{\"amount\": \"42sat\"}",
|
||||
Amount { msat: 42_000 },
|
||||
"42000msat",
|
||||
"42sat",
|
||||
),
|
||||
(
|
||||
"{\"amount\": \"31337btc\"}",
|
||||
Amount {
|
||||
msat: 3_133_700_000_000_000,
|
||||
},
|
||||
"3133700000000000msat",
|
||||
"3133700000000sat",
|
||||
),
|
||||
];
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue