diff --git a/lib/src/commands.rs b/lib/src/commands.rs index f529753..f6cca28 100644 --- a/lib/src/commands.rs +++ b/lib/src/commands.rs @@ -265,7 +265,10 @@ impl Command for SendCommand { }; lightclient.do_sync(true); - return lightclient.do_send(send_args); + match lightclient.do_send(send_args) { + Ok(txid) => { object!{ "txid" => txid } }, + Err(e) => { object!{ "error" => e } } + }.pretty(2) } else if args.len() == 2 || args.len() == 3 { // Make sure we can parse the amount let value = match args[1].parse::() { @@ -278,10 +281,13 @@ impl Command for SendCommand { let memo = if args.len() == 3 { Some(args[2].to_string()) } else {None}; lightclient.do_sync(true); - return lightclient.do_send(vec!((args[0], value, memo))); + match lightclient.do_send(vec!((args[0], value, memo))) { + Ok(txid) => { object!{ "txid" => txid } }, + Err(e) => { object!{ "error" => e } } + }.pretty(2) + } else { + self.help() } - - self.help() } } diff --git a/lib/src/lightclient.rs b/lib/src/lightclient.rs index a242d63..fb4ef62 100644 --- a/lib/src/lightclient.rs +++ b/lib/src/lightclient.rs @@ -789,7 +789,7 @@ impl LightClient { responses.join("\n") } - pub fn do_send(&self, addrs: Vec<(&str, u64, Option)>) -> String { + pub fn do_send(&self, addrs: Vec<(&str, u64, Option)>) -> Result { info!("Creating transaction"); let rawtx = self.wallet.write().unwrap().send_to_address( @@ -799,11 +799,8 @@ impl LightClient { ); match rawtx { - Ok(txbytes) => match broadcast_raw_tx(&self.get_server_uri(), self.config.no_cert_verification, txbytes) { - Ok(k) => k, - Err(e) => e, - }, - Err(e) => format!("Error: No Tx to broadcast. Error was: {}", e) + Ok(txbytes) => broadcast_raw_tx(&self.get_server_uri(), self.config.no_cert_verification, txbytes), + Err(e) => Err(format!("Error: No Tx to broadcast. Error was: {}", e)) } } }