@@ -10,6 +10,9 @@ use coinswap::{
1010#[ derive( Parser , Debug ) ]
1111#[ clap( author, version, about, long_about = None ) ]
1212struct App {
13+ /// Sets the rpc-port of Makerd
14+ #[ clap( long, short = 'p' , default_value = "127.0.0.1:6103" ) ]
15+ rpc_port : String ,
1316 /// The command to execute
1417 #[ clap( subcommand) ]
1518 command : Commands ,
@@ -37,77 +40,86 @@ enum Commands {
3740 FidelityBalance ,
3841 /// Gets a new address
3942 NewAddress ,
40- // Send to an external wallet address.
43+ /// Send to an external address and returns the transaction hex .
4144 SendToAddress {
4245 address : String ,
4346 amount : u64 ,
4447 fee : u64 ,
4548 } ,
4649 /// Returns the tor address
4750 GetTorAddress ,
48- /// Returns the data dir
51+ /// Returns the data directory path
4952 GetDataDir ,
53+ /// Stops the maker server
54+ Stop ,
5055}
5156
5257fn main ( ) -> Result < ( ) , MakerError > {
5358 setup_maker_logger ( log:: LevelFilter :: Info ) ;
5459 let cli = App :: parse ( ) ;
5560
61+ let stream = TcpStream :: connect ( cli. rpc_port ) ?;
62+
5663 match cli. command {
5764 Commands :: Ping => {
58- send_rpc_req ( & RpcMsgReq :: Ping ) ?;
65+ send_rpc_req ( stream , RpcMsgReq :: Ping ) ?;
5966 }
6067 Commands :: ContractUtxo => {
61- send_rpc_req ( & RpcMsgReq :: ContractUtxo ) ?;
68+ send_rpc_req ( stream , RpcMsgReq :: ContractUtxo ) ?;
6269 }
6370 Commands :: ContractBalance => {
64- send_rpc_req ( & RpcMsgReq :: ContractBalance ) ?;
71+ send_rpc_req ( stream , RpcMsgReq :: ContractBalance ) ?;
6572 }
6673 Commands :: FidelityBalance => {
67- send_rpc_req ( & RpcMsgReq :: FidelityBalance ) ?;
74+ send_rpc_req ( stream , RpcMsgReq :: FidelityBalance ) ?;
6875 }
6976 Commands :: FidelityUtxo => {
70- send_rpc_req ( & RpcMsgReq :: FidelityUtxo ) ?;
77+ send_rpc_req ( stream , RpcMsgReq :: FidelityUtxo ) ?;
7178 }
7279 Commands :: SeedBalance => {
73- send_rpc_req ( & RpcMsgReq :: SeedBalance ) ?;
80+ send_rpc_req ( stream , RpcMsgReq :: SeedBalance ) ?;
7481 }
7582 Commands :: SeedUtxo => {
76- send_rpc_req ( & RpcMsgReq :: SeedUtxo ) ?;
83+ send_rpc_req ( stream , RpcMsgReq :: SeedUtxo ) ?;
7784 }
7885 Commands :: SwapBalance => {
79- send_rpc_req ( & RpcMsgReq :: SwapBalance ) ?;
86+ send_rpc_req ( stream , RpcMsgReq :: SwapBalance ) ?;
8087 }
8188 Commands :: SwapUtxo => {
82- send_rpc_req ( & RpcMsgReq :: SwapUtxo ) ?;
89+ send_rpc_req ( stream , RpcMsgReq :: SwapUtxo ) ?;
8390 }
8491 Commands :: NewAddress => {
85- send_rpc_req ( & RpcMsgReq :: NewAddress ) ?;
92+ send_rpc_req ( stream , RpcMsgReq :: NewAddress ) ?;
8693 }
8794 Commands :: SendToAddress {
8895 address,
8996 amount,
9097 fee,
9198 } => {
92- send_rpc_req ( & RpcMsgReq :: SendToAddress {
93- address,
94- amount,
95- fee,
96- } ) ?;
99+ send_rpc_req (
100+ stream,
101+ RpcMsgReq :: SendToAddress {
102+ address,
103+ amount,
104+ fee,
105+ } ,
106+ ) ?;
97107 }
98108 Commands :: GetTorAddress => {
99- send_rpc_req ( & RpcMsgReq :: GetTorAddress ) ?;
109+ send_rpc_req ( stream , RpcMsgReq :: GetTorAddress ) ?;
100110 }
101111 Commands :: GetDataDir => {
102- send_rpc_req ( & RpcMsgReq :: GetDataDir ) ?;
112+ send_rpc_req ( stream, RpcMsgReq :: GetDataDir ) ?;
113+ }
114+ Commands :: Stop => {
115+ send_rpc_req ( stream, RpcMsgReq :: Stop ) ?;
103116 }
104117 }
105118
106119 Ok ( ( ) )
107120}
108121
109- fn send_rpc_req ( req : & RpcMsgReq ) -> Result < ( ) , MakerError > {
110- let mut stream = TcpStream :: connect ( "127.0.0.1:6103" ) ?;
122+ fn send_rpc_req ( mut stream : TcpStream , req : RpcMsgReq ) -> Result < ( ) , MakerError > {
111123 stream. set_read_timeout ( Some ( Duration :: from_secs ( 20 ) ) ) ?;
112124 stream. set_write_timeout ( Some ( Duration :: from_secs ( 20 ) ) ) ?;
113125
@@ -116,7 +128,7 @@ fn send_rpc_req(req: &RpcMsgReq) -> Result<(), MakerError> {
116128 let response_bytes = read_message ( & mut stream) ?;
117129 let response: RpcMsgResp = serde_cbor:: from_slice ( & response_bytes) ?;
118130
119- println ! ( "{:? }" , response) ;
131+ println ! ( "{}" , response) ;
120132
121133 Ok ( ( ) )
122134}
0 commit comments