Add cancel tx by tx_slate_id

This commit is contained in:
Quentin Le Sceller
2018-11-13 11:53:23 +01:00
parent 1b264595e3
commit 59b0f1b1d7
6 changed files with 86 additions and 26 deletions
+40 -13
View File
@@ -603,22 +603,49 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
}
}
("cancel", Some(tx_args)) => {
let tx_id = tx_args
.value_of("id")
.ok_or_else(|| {
ErrorKind::GenericError("'id' argument (-i) is required.".to_string())
}).and_then(|v| {
v.parse().map_err(|e| {
ErrorKind::GenericError(format!(
let mut tx_id_string = "";
let tx_id = match tx_args.value_of("id") {
None => None,
Some(tx) => match tx.parse() {
Ok(t) => {
tx_id_string = tx;
Some(t)
}
Err(e) => {
return Err(ErrorKind::GenericError(format!(
"Could not parse id parameter. e={:?}",
e
))
})
})?;
let result = api.cancel_tx(tx_id);
e,
)).into());
}
},
};
let tx_slate_id = match tx_args.value_of("txid") {
None => None,
Some(tx) => match tx.parse() {
Ok(t) => {
tx_id_string = tx;
Some(t)
}
Err(e) => {
return Err(ErrorKind::GenericError(format!(
"Could not parse txid parameter. e={:?}",
e,
)).into());
}
},
};
if (tx_id.is_none() && tx_slate_id.is_none())
|| (tx_id.is_some() && tx_slate_id.is_some())
{
return Err(ErrorKind::GenericError(format!(
"'id' (-i) or 'txid' (-t) argument is required."
)).into());
}
let result = api.cancel_tx(tx_id, tx_slate_id);
match result {
Ok(_) => {
info!("Transaction {} Cancelled", tx_id);
info!("Transaction {} Cancelled", tx_id_string);
Ok(())
}
Err(e) => {
+5
View File
@@ -321,6 +321,11 @@ fn real_main() -> i32 {
.help("The ID of the transaction to cancel")
.short("i")
.long("id")
.takes_value(true))
.arg(Arg::with_name("txid")
.help("The TxID of the transaction to cancel")
.short("t")
.long("txid")
.takes_value(true)))
.subcommand(SubCommand::with_name("info")