From 45100b5cc413b1f691abfbe2b89378448b449b43 Mon Sep 17 00:00:00 2001 From: Roei Erez Date: Wed, 3 Jul 2024 15:36:09 +0300 Subject: [PATCH] Use json as command output --- libs/sdk-core/src/greenlight/node_api.rs | 17 +++++++++-------- tools/sdk-cli/src/command_handlers.rs | 5 +---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index 92efab6cb..7770f28d6 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -1464,7 +1464,8 @@ impl NodeAPI for Greenlight { .list_peers(cln::ListpeersRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::ListPeerChannels => { let resp = self @@ -1473,7 +1474,7 @@ impl NodeAPI for Greenlight { .list_peer_channels(cln::ListpeerchannelsRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::ListFunds => { let resp = self @@ -1482,7 +1483,7 @@ impl NodeAPI for Greenlight { .list_funds(cln::ListfundsRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::ListPayments => { let resp = self @@ -1491,7 +1492,7 @@ impl NodeAPI for Greenlight { .list_pays(cln::ListpaysRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::ListInvoices => { let resp = self @@ -1500,7 +1501,7 @@ impl NodeAPI for Greenlight { .list_invoices(cln::ListinvoicesRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::CloseAllChannels => { let peers_res = self @@ -1522,11 +1523,11 @@ impl NodeAPI for Greenlight { .getinfo(cln::GetinfoRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::GenerateDiagnosticData => { let resp = self.generate_diagnostic_data().await?; - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } NodeCommand::Stop => { let resp = self @@ -1535,7 +1536,7 @@ impl NodeAPI for Greenlight { .stop(cln::StopRequest::default()) .await? .into_inner(); - Ok(format!("{resp:?}")) + Ok(serde_json::to_string_pretty(&resp)?) } } } diff --git a/tools/sdk-cli/src/command_handlers.rs b/tools/sdk-cli/src/command_handlers.rs index afd9bce66..db9e8873f 100644 --- a/tools/sdk-cli/src/command_handlers.rs +++ b/tools/sdk-cli/src/command_handlers.rs @@ -562,10 +562,7 @@ pub(crate) async fn handle_command( .await?; Ok("Report sent".into()) } - Commands::ExecuteDevCommand { command } => { - serde_json::to_string_pretty(&sdk()?.execute_dev_command(command).await?) - .map_err(|e| e.into()) - } + Commands::ExecuteDevCommand { command } => Ok(sdk()?.execute_dev_command(command).await?), Commands::GenerateDiagnosticData {} => Ok(sdk()?.generate_diagnostic_data().await?), Commands::BuyBitcoin { provider } => { let res = sdk()?