Skip to content

Commit 5a94d3e

Browse files
vid277cdxker
authored andcommitted
feature: add check balance function to cli
1 parent 48403b6 commit 5a94d3e

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

bin/cli/src/main.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use base64::{engine::general_purpose::STANDARD as BASE64, Engine as _};
1616
use clap::{Parser, Subcommand};
1717
use directories::ProjectDirs;
1818
use libp2p::identity::Keypair;
19-
use rpc_client::{rpc_create_deposit_intent, rpc_spend, rpc_start_signing};
19+
use rpc_client::{rpc_check_balance, rpc_create_deposit_intent, rpc_spend, rpc_start_signing};
2020
use std::{fs, path::PathBuf};
2121

2222
use crate::{
@@ -173,6 +173,11 @@ enum Commands {
173173
#[arg(short, long)]
174174
endpoint: Option<String>,
175175
},
176+
CheckBalance {
177+
#[arg(short, long)]
178+
endpoint: Option<String>,
179+
address: String,
180+
},
176181
}
177182

178183
#[tokio::main]
@@ -244,6 +249,11 @@ async fn main() -> Result<(), CliError> {
244249
.await
245250
.map_err(CliError::RpcError)?;
246251
}
252+
Commands::CheckBalance { endpoint, address } => {
253+
rpc_check_balance(endpoint, address)
254+
.await
255+
.map_err(CliError::RpcError)?;
256+
}
247257
}
248258

249259
Ok(())

bin/cli/src/rpc_client.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use node::grpc::grpc_handler::node_proto::{
2-
self, node_control_client::NodeControlClient, CreateDepositIntentResponse,
3-
GetPendingDepositIntentsResponse, SpendFundsResponse, StartSigningResponse,
2+
self, node_control_client::NodeControlClient, CheckBalanceResponse,
3+
CreateDepositIntentResponse, GetPendingDepositIntentsResponse, SpendFundsResponse,
4+
StartSigningResponse,
45
};
56
use tonic::Status;
67

@@ -86,3 +87,21 @@ pub async fn rpc_get_pending_deposit_intents(
8687

8788
Ok(get_pending_deposit_intents_response.into_inner())
8889
}
90+
91+
pub async fn rpc_check_balance(
92+
endpoint: Option<String>,
93+
address: String,
94+
) -> Result<CheckBalanceResponse, Status> {
95+
let mut client =
96+
NodeControlClient::connect(endpoint.unwrap_or("http://[::1]:50051".to_string()))
97+
.await
98+
.expect("Failed to connect");
99+
100+
let check_balance_response = client
101+
.check_balance(tonic::Request::new(node_proto::CheckBalanceRequest {
102+
address,
103+
}))
104+
.await?;
105+
106+
Ok(check_balance_response.into_inner())
107+
}

0 commit comments

Comments
 (0)