Skip to content

Commit

Permalink
cln-grpc: Add conversion from pb Amount to json Amount
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Feb 28, 2022
1 parent bb4946a commit d95c9d2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cln-grpc/src/pb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,20 @@ impl From<Amount> for JAmount {
JAmount::from_msat(a.msat)
}
}

impl From<&Amount> for JAmount {
fn from(a: &Amount) -> Self {
match a {
Amount {
unit: Some(amount::Unit::Millisatoshi(v)),
} => JAmount::Millisatoshi(*v),
Amount {
unit: Some(amount::Unit::Satoshi(v)),
} => JAmount::Satoshi(*v),
Amount {
unit: Some(amount::Unit::Bitcoin(v)),
} => JAmount::Bitcoin(*v),
o => panic!("Unhandled conversion from pb:Amount to json:Amount: {:?}", o),
}
}
}

0 comments on commit d95c9d2

Please sign in to comment.