11use crate :: rpc_call:: make_rpc_call;
22use anyhow:: Context ;
3- use jsonrpsee :: core :: params :: ObjectParams ;
3+ use serde_json :: { json , Value } ;
44
55use crate :: util:: pretty_print_value;
66
@@ -9,81 +9,59 @@ pub enum NodeType {
99 BitcoinCli ,
1010}
1111
12- pub async fn handle_rpc_commands (
12+ pub fn handle_rpc_commands (
1313 node_type : NodeType ,
1414 node_index : & u64 ,
1515 method : & String ,
1616 rpc_params : & Option < Vec < String > > ,
17- mut params : ObjectParams ,
17+ mut params : Value ,
1818) -> anyhow:: Result < ( ) > {
19- params
20- . insert ( "node" , node_index)
21- . context ( "add node_index param" ) ?;
22- params
23- . insert ( "method" , method)
24- . context ( "add method param" ) ?;
19+ params[ "node" ] = json ! ( node_index) ;
20+ params[ "method" ] = json ! ( method) ;
2521 if let Some ( p) = rpc_params {
26- params. insert ( "params" , p ) . context ( "add rpc params" ) ? ;
22+ params[ "params" ] = json ! ( p ) ;
2723 }
2824 let data = match node_type {
29- NodeType :: LnCli => make_rpc_call ( "tank_lncli" , params)
30- . await
31- . context ( "make RPC call lncli" ) ?,
32- NodeType :: BitcoinCli => make_rpc_call ( "tank_bcli" , params)
33- . await
34- . context ( "make RPC call bitcoin-cli" ) ?,
25+ NodeType :: LnCli => make_rpc_call ( "tank_lncli" , & params) . context ( "make RPC call lncli" ) ?,
26+ NodeType :: BitcoinCli => {
27+ make_rpc_call ( "tank_bcli" , & params) . context ( "make RPC call bitcoin-cli" ) ?
28+ }
3529 } ;
3630 pretty_print_value ( & data) . context ( "Pretty print the result" ) ?;
3731 Ok ( ( ) )
3832}
3933
40- pub async fn handle_debug_log_command ( node : & u64 , mut params : ObjectParams ) -> anyhow:: Result < ( ) > {
41- params
42- . insert ( "node" , node)
43- . context ( "add node_index param" ) ?;
44- let data = make_rpc_call ( "tank_debug_log" , params)
45- . await
46- . context ( "make RPC call tank_debug_log" ) ?;
34+ pub fn handle_debug_log_command ( node : & u64 , mut params : Value ) -> anyhow:: Result < ( ) > {
35+ params[ "node" ] = json ! ( node) ;
36+ let data = make_rpc_call ( "tank_debug_log" , & params) . context ( "make RPC call tank_debug_log" ) ?;
4737 pretty_print_value ( & data) . context ( "pretty print result" ) ?;
4838 Ok ( ( ) )
4939}
5040
51- pub async fn handle_messages_command (
41+ pub fn handle_messages_command (
5242 node_a : & u64 ,
5343 node_b : & u64 ,
54- mut params : ObjectParams ,
44+ mut params : Value ,
5545) -> anyhow:: Result < ( ) > {
56- params
57- . insert ( "node_a" , node_a)
58- . context ( "add node_b param" ) ?;
59- params
60- . insert ( "node_b" , node_b)
61- . context ( "add node_b param" ) ?;
62- let data = make_rpc_call ( "tank_messages" , params)
63- . await
64- . context ( "Failed to make RPC call tank_messages" ) ?;
46+ params[ "node_a" ] = json ! ( node_a) ;
47+ params[ "node_b" ] = json ! ( node_b) ;
48+ let data =
49+ make_rpc_call ( "tank_messages" , & params) . context ( "Failed to make RPC call tank_messages" ) ?;
6550 pretty_print_value ( & data) . context ( "pretty print result" ) ?;
6651 Ok ( ( ) )
6752}
6853
69- pub async fn handle_grep_logs_command (
70- pattern : & String ,
71- mut params : ObjectParams ,
72- ) -> anyhow:: Result < ( ) > {
73- params
74- . insert ( "pattern" , pattern)
75- . context ( "add pattern param" ) ?;
76- let data = make_rpc_call ( "logs_grep" , params)
77- . await
78- . context ( "Failed to make RPC call tank_messages" ) ?;
54+ pub fn handle_grep_logs_command ( pattern : & String , mut params : Value ) -> anyhow:: Result < ( ) > {
55+ params[ "pattern" ] = json ! ( pattern) ;
56+ let data =
57+ make_rpc_call ( "logs_grep" , & params) . context ( "Failed to make RPC call tank_messages" ) ?;
7958 pretty_print_value ( & data) . context ( "pretty print result" ) ?;
8059 Ok ( ( ) )
8160}
8261
83- pub async fn handle_stop_command ( params : ObjectParams ) -> anyhow:: Result < ( ) > {
84- let data = make_rpc_call ( "server_stop" , params)
85- . await
86- . context ( "Failed to make RPC call server_stop" ) ?;
62+ pub fn handle_stop_command ( params : Value ) -> anyhow:: Result < ( ) > {
63+ let data =
64+ make_rpc_call ( "server_stop" , & params) . context ( "Failed to make RPC call server_stop" ) ?;
8765 pretty_print_value ( & data) . context ( "pretty print result" ) ?;
8866 Ok ( ( ) )
8967}
0 commit comments