Add cancel_tx and retrieve by tx_slate_id in owner_api (#1963)

* Add retrieve by tx_id in owner_api
* Add cancel tx by tx_slate_id
* Add doc
This commit is contained in:
Ignotus Peverell
2018-11-13 09:34:33 -08:00
committed by GitHub
11 changed files with 143 additions and 62 deletions
+41 -14
View File
@@ -532,7 +532,7 @@ pub fn wallet_command(wallet_args: &ArgMatches, config: GlobalWalletConfig) -> i
},
};
let (height, _) = api.node_height()?;
let (validated, txs) = api.retrieve_txs(true, tx_id)?;
let (validated, txs) = api.retrieve_txs(true, tx_id, None)?;
let include_status = !tx_id.is_some();
display::txs(
account,
@@ -611,22 +611,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")