diff --git a/controller/src/command.rs b/controller/src/command.rs index dba46ae..5721787 100644 --- a/controller/src/command.rs +++ b/controller/src/command.rs @@ -258,6 +258,7 @@ pub struct SendArgs { pub payment_proof_address: Option, pub ttl_blocks: Option, pub skip_tor: bool, + pub outfile: Option, //TODO: Remove HF3 pub output_v4_slate: bool, } @@ -486,6 +487,7 @@ where keychain_mask, &slate, args.dest.as_str(), + args.outfile, true, false, is_pre_fork, @@ -501,6 +503,7 @@ pub fn output_slatepack( keychain_mask: Option<&SecretKey>, slate: &Slate, dest: &str, + out_file_override: Option, lock: bool, finalizing: bool, is_pre_fork: bool, @@ -532,7 +535,10 @@ where // create a directory to which files will be output let slate_dir = format!("{}/{}", tld, "slatepack"); let _ = std::fs::create_dir_all(slate_dir.clone()); - let out_file_name = format!("{}/{}.{}.slatepack", slate_dir, slate.id, slate.state); + let out_file_name = match out_file_override { + None => format!("{}/{}.{}.slatepack", slate_dir, slate.id, slate.state), + Some(f) => f, + }; if lock { controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| { @@ -663,6 +669,7 @@ pub struct ReceiveArgs { pub input_file: Option, pub input_slatepack_message: Option, pub skip_tor: bool, + pub outfile: Option, } pub fn receive( @@ -726,6 +733,7 @@ where keychain_mask, &slate, &dest, + args.outfile, false, false, slate.version_info.version < 4, @@ -821,6 +829,7 @@ pub struct FinalizeArgs { pub input_slatepack_message: Option, pub fluff: bool, pub nopost: bool, + pub outfile: Option, } pub fn finalize( @@ -893,6 +902,7 @@ where keychain_mask, &slate, "", + args.outfile, false, true, slate.version_info.version < 4, @@ -903,12 +913,14 @@ where /// Issue Invoice Args pub struct IssueInvoiceArgs { - /// output file + /// Slatepack address pub dest: String, /// issue invoice tx args pub issue_args: IssueInvoiceTxArgs, /// whether to output a V4 slate pub output_v4_slate: bool, + /// output file override + pub outfile: Option, } pub fn issue_invoice_tx( @@ -964,6 +976,7 @@ where keychain_mask, &slate, args.dest.as_str(), + args.outfile, false, false, is_pre_fork, @@ -981,6 +994,7 @@ pub struct ProcessInvoiceArgs { pub estimate_selection_strategies: bool, pub ttl_blocks: Option, pub skip_tor: bool, + pub outfile: Option, } /// Process invoice @@ -1081,6 +1095,7 @@ where keychain_mask, &slate, &dest, + args.outfile, true, false, slate.version_info.version < 4, diff --git a/src/bin/grin-wallet.yml b/src/bin/grin-wallet.yml index 26b8776..2009e92 100644 --- a/src/bin/grin-wallet.yml +++ b/src/bin/grin-wallet.yml @@ -145,6 +145,11 @@ subcommands: help: If present, don't attempt to send the resulting Slatepack via TOR short: m long: manual + - outfile: + help: If present, overrides the filename and location of the output Slatepack file. + short: u + long: outfile + takes_value: true #TODO: Remove HF3 - v4: help: Output a V4 slate prior to HF3 block @@ -170,6 +175,11 @@ subcommands: help: If present, don't attempt to send the resulting Slatepack via TOR short: m long: manual + - outfile: + help: If present, overrides the filename and location of the output Slatepack file. + short: u + long: outfile + takes_value: true - finalize: about: Processes a Slatepack Message to finalize a transfer. args: @@ -186,6 +196,11 @@ subcommands: help: Do not post the transaction. short: n long: nopost + - outfile: + help: If present, overrides the filename and location of the output Slatepack file. + short: u + long: outfile + takes_value: true - invoice: about: Initialize an invoice transaction, outputting a Slatepack Message with the result args: @@ -197,6 +212,11 @@ subcommands: short: d long: dest takes_value: true + - outfile: + help: If present, overrides the filename and location of the output Slatepack file. + short: u + long: outfile + takes_value: true #TODO: Remove HF3 - v4: help: Output a V4 slate prior to HF3 block @@ -243,6 +263,11 @@ subcommands: help: If present, don't attempt to send the resulting Slatepack via TOR short: m long: manual + - outfile: + help: If present, overrides the filename and location of the output Slatepack file. + short: u + long: outfile + takes_value: true - outputs: about: Raw wallet output info (list of outputs) - txs: diff --git a/src/cmd/wallet_args.rs b/src/cmd/wallet_args.rs index baf95f1..8ceaeb4 100644 --- a/src/cmd/wallet_args.rs +++ b/src/cmd/wallet_args.rs @@ -283,6 +283,21 @@ fn parse_required<'a>(args: &'a ArgMatches, name: &str) -> Result<&'a str, Parse } } +// parses an optional value, throws error if value isn't provided +fn parse_optional(args: &ArgMatches, name: &str) -> Result, ParseError> { + if !args.is_present(name) { + return Ok(None); + } + let arg = args.value_of(name); + match arg { + Some(ar) => Ok(Some(ar.into())), + None => { + let msg = format!("Value for argument '{}' is required in this context", name,); + Err(ParseError::ArgumentError(msg)) + } + } +} + // parses a number, or throws error with message otherwise fn parse_u64(arg: &str, name: &str) -> Result { let val = arg.parse::(); @@ -514,6 +529,8 @@ pub fn parse_send_args(args: &ArgMatches) -> Result Result Result Result Result "default", }; + let outfile = parse_optional(args, "outfile")?; + Ok(command::IssueInvoiceArgs { dest: dest.into(), output_v4_slate, @@ -659,6 +688,7 @@ pub fn parse_issue_invoice_args( amount, target_slate_version, }, + outfile, }) } @@ -732,6 +762,8 @@ pub fn parse_process_invoice_args( prompt_pay_invoice(&slate, &dest)?; } + let outfile = parse_optional(args, "outfile")?; + Ok(command::ProcessInvoiceArgs { minimum_confirmations: min_c, selection_strategy: selection_strategy.to_owned(), @@ -741,6 +773,7 @@ pub fn parse_process_invoice_args( max_outputs, ttl_blocks, skip_tor: args.is_present("manual"), + outfile, }) }