Skip to content

Commit 3eae2fc

Browse files
author
Conor Okus
committed
Use Amount type for balance
1 parent 9e9bb3f commit 3eae2fc

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

examples/bitcoind-rpc-client/src/convert.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::convert::TryInto;
22

3-
use bitcoin::{BlockHash, hashes::hex::FromHex};
3+
use bitcoin::{Amount, BlockHash, hashes::hex::FromHex};
44
use lightning_block_sync::http::JsonResponse;
55

66
/// TryInto implementation specifies the conversion logic from json response to BlockchainInfo object.
@@ -36,12 +36,13 @@ impl TryInto<CreateWalletResponse> for JsonResponse {
3636
})
3737
}
3838
}
39-
pub struct GetBalanceResponse(pub usize);
39+
pub struct GetBalanceResponse(pub Amount);
4040

4141
impl TryInto<GetBalanceResponse> for JsonResponse {
4242
type Error = std::io::Error;
4343
fn try_into(self) -> std::io::Result<GetBalanceResponse> {
44-
Ok(GetBalanceResponse(self.0.as_f64().unwrap() as usize))
44+
let balance = Amount::from_btc(self.0.as_f64().unwrap()).unwrap();
45+
Ok(GetBalanceResponse(balance))
4546
}
4647
}
4748

0 commit comments

Comments
 (0)