Skip to content

Commit 26c3b4c

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

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{sync::{Arc}, io::{Result, Error, ErrorKind}};
1+
use std::{sync::{Arc}, io};
22

33
use bitcoin::{BlockHash, Block};
44
use lightning_block_sync::{rpc::RpcClient, http::{HttpEndpoint}, BlockSource, AsyncBlockSourceResult, BlockHeaderData};
@@ -44,7 +44,7 @@ impl BlockSource for &BitcoindClient {
4444
}
4545

4646
impl BitcoindClient {
47-
pub async fn new(host: String, port: u16, rpc_user: String, rpc_password: String) -> Result<Self> {
47+
pub async fn new(host: String, port: u16, rpc_user: String, rpc_password: String) -> io::Result<Self> {
4848
let http_endpoint = HttpEndpoint::for_host(host.clone()).with_port(port);
4949
let rpc_creditials =
5050
base64::encode(format!("{}:{}", rpc_user.clone(), rpc_password.clone()));
@@ -53,7 +53,7 @@ impl BitcoindClient {
5353
.call_method::<BlockchainInfoResponse>("getblockchaininfo", &vec![])
5454
.await
5555
.map_err(|_| {
56-
Error::new(ErrorKind::PermissionDenied,
56+
io::Error::new(io::ErrorKind::PermissionDenied,
5757
"Failed to make initial call to bitcoind - please check your RPC user/password and access settings")
5858
})?;
5959

@@ -68,7 +68,7 @@ impl BitcoindClient {
6868
Ok(client)
6969
}
7070

71-
pub fn get_new_rpc_client(&self) -> Result<RpcClient> {
71+
pub fn get_new_rpc_client(&self) -> io::Result<RpcClient> {
7272
let http_endpoint = HttpEndpoint::for_host(self.host.clone()).with_port(self.port);
7373
let rpc_credentials =
7474
base64::encode(format!("{}:{}", self.rpc_user.clone(), self.rpc_password.clone()));

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)