mirror of
https://github.com/mimblewimble/grin-wallet.git
synced 2025-02-08 12:21:10 +03:00
add --txid to the wallet txs
command (#176)
* add --txid to the `wallet txs` command * add test for `wallet txs` command with `--txid` parameter
This commit is contained in:
parent
21dd3d5377
commit
7b6d597d39
4 changed files with 58 additions and 7 deletions
|
@ -587,6 +587,7 @@ pub fn outputs(
|
||||||
/// Txs command args
|
/// Txs command args
|
||||||
pub struct TxsArgs {
|
pub struct TxsArgs {
|
||||||
pub id: Option<u32>,
|
pub id: Option<u32>,
|
||||||
|
pub tx_slate_id: Option<Uuid>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn txs(
|
pub fn txs(
|
||||||
|
@ -597,8 +598,8 @@ pub fn txs(
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
controller::owner_single_use(wallet.clone(), |api| {
|
controller::owner_single_use(wallet.clone(), |api| {
|
||||||
let res = api.node_height()?;
|
let res = api.node_height()?;
|
||||||
let (validated, txs) = api.retrieve_txs(true, args.id, None)?;
|
let (validated, txs) = api.retrieve_txs(true, args.id, args.tx_slate_id)?;
|
||||||
let include_status = !args.id.is_some();
|
let include_status = !args.id.is_some() && !args.tx_slate_id.is_some();
|
||||||
display::txs(
|
display::txs(
|
||||||
&g_args.account,
|
&g_args.account,
|
||||||
res.height,
|
res.height,
|
||||||
|
@ -607,16 +608,31 @@ pub fn txs(
|
||||||
include_status,
|
include_status,
|
||||||
dark_scheme,
|
dark_scheme,
|
||||||
)?;
|
)?;
|
||||||
// if given a particular transaction id, also get and display associated
|
|
||||||
|
// if given a particular transaction id or uuid, also get and display associated
|
||||||
// inputs/outputs and messages
|
// inputs/outputs and messages
|
||||||
if args.id.is_some() {
|
let id = if args.id.is_some() {
|
||||||
let (_, outputs) = api.retrieve_outputs(true, false, args.id)?;
|
args.id
|
||||||
|
} else if args.tx_slate_id.is_some() {
|
||||||
|
if let Some(tx) = txs.iter().find(|t| t.tx_slate_id == args.tx_slate_id) {
|
||||||
|
Some(tx.id)
|
||||||
|
} else {
|
||||||
|
println!("Could not find a transaction matching given txid.\n");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if id.is_some() {
|
||||||
|
let (_, outputs) = api.retrieve_outputs(true, false, id)?;
|
||||||
display::outputs(&g_args.account, res.height, validated, outputs, dark_scheme)?;
|
display::outputs(&g_args.account, res.height, validated, outputs, dark_scheme)?;
|
||||||
// should only be one here, but just in case
|
// should only be one here, but just in case
|
||||||
for tx in txs {
|
for tx in txs {
|
||||||
display::tx_messages(&tx, dark_scheme)?;
|
display::tx_messages(&tx, dark_scheme)?;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -667,7 +667,24 @@ pub fn parse_txs_args(args: &ArgMatches) -> Result<command::TxsArgs, ParseError>
|
||||||
None => None,
|
None => None,
|
||||||
Some(tx) => Some(parse_u64(tx, "id")? as u32),
|
Some(tx) => Some(parse_u64(tx, "id")? as u32),
|
||||||
};
|
};
|
||||||
Ok(command::TxsArgs { id: tx_id })
|
let tx_slate_id = match args.value_of("txid") {
|
||||||
|
None => None,
|
||||||
|
Some(tx) => match tx.parse() {
|
||||||
|
Ok(t) => Some(t),
|
||||||
|
Err(e) => {
|
||||||
|
let msg = format!("Could not parse txid parameter. e={}", e);
|
||||||
|
return Err(ParseError::ArgumentError(msg));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
if tx_id.is_some() && tx_slate_id.is_some() {
|
||||||
|
let msg = format!("At most one of 'id' (-i) or 'txid' (-t) may be provided.");
|
||||||
|
return Err(ParseError::ArgumentError(msg));
|
||||||
|
}
|
||||||
|
Ok(command::TxsArgs {
|
||||||
|
id: tx_id,
|
||||||
|
tx_slate_id: tx_slate_id,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_repost_args(args: &ArgMatches) -> Result<command::RepostArgs, ParseError> {
|
pub fn parse_repost_args(args: &ArgMatches) -> Result<command::RepostArgs, ParseError> {
|
||||||
|
|
|
@ -555,6 +555,19 @@ mod wallet_tests {
|
||||||
let arg_vec = vec!["grin-wallet", "-p", "password", "outputs"];
|
let arg_vec = vec!["grin-wallet", "-p", "password", "outputs"];
|
||||||
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;
|
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;
|
||||||
|
|
||||||
|
// get tx output via -tx parameter
|
||||||
|
let mut tx_id = "".to_string();
|
||||||
|
grin_wallet_controller::controller::owner_single_use(wallet2.clone(), |api| {
|
||||||
|
api.set_active_account("default")?;
|
||||||
|
let (_, txs) = api.retrieve_txs(true, None, None)?;
|
||||||
|
let some_tx_id = txs[0].tx_slate_id.clone();
|
||||||
|
assert!(some_tx_id.is_some());
|
||||||
|
tx_id = some_tx_id.unwrap().to_hyphenated().to_string().clone();
|
||||||
|
Ok(())
|
||||||
|
})?;
|
||||||
|
let arg_vec = vec!["grin-wallet", "-p", "password", "txs", "-t", &tx_id[..]];
|
||||||
|
execute_command(&app, test_dir, "wallet2", &client2, arg_vec)?;
|
||||||
|
|
||||||
// let logging finish
|
// let logging finish
|
||||||
thread::sleep(Duration::from_millis(200));
|
thread::sleep(Duration::from_millis(200));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -239,6 +239,11 @@ subcommands:
|
||||||
short: i
|
short: i
|
||||||
long: id
|
long: id
|
||||||
takes_value: true
|
takes_value: true
|
||||||
|
- txid:
|
||||||
|
help: If specified, display transaction with given TxID UUID and all associated Inputs/Outputs
|
||||||
|
short: t
|
||||||
|
long: txid
|
||||||
|
takes_value: true
|
||||||
- repost:
|
- repost:
|
||||||
about: Reposts a stored, completed but unconfirmed transaction to the chain, or dumps it to a file
|
about: Reposts a stored, completed but unconfirmed transaction to the chain, or dumps it to a file
|
||||||
args:
|
args:
|
||||||
|
|
Loading…
Reference in a new issue