Add Slatepack file output override (#455)

This commit is contained in:
Yeastplume
2020-06-26 10:39:17 +01:00
committed by GitHub
parent f8ea76732b
commit dea5850e2b
3 changed files with 75 additions and 2 deletions
+17 -2
View File
@@ -258,6 +258,7 @@ pub struct SendArgs {
pub payment_proof_address: Option<SlatepackAddress>, pub payment_proof_address: Option<SlatepackAddress>,
pub ttl_blocks: Option<u64>, pub ttl_blocks: Option<u64>,
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>,
//TODO: Remove HF3 //TODO: Remove HF3
pub output_v4_slate: bool, pub output_v4_slate: bool,
} }
@@ -486,6 +487,7 @@ where
keychain_mask, keychain_mask,
&slate, &slate,
args.dest.as_str(), args.dest.as_str(),
args.outfile,
true, true,
false, false,
is_pre_fork, is_pre_fork,
@@ -501,6 +503,7 @@ pub fn output_slatepack<L, C, K>(
keychain_mask: Option<&SecretKey>, keychain_mask: Option<&SecretKey>,
slate: &Slate, slate: &Slate,
dest: &str, dest: &str,
out_file_override: Option<String>,
lock: bool, lock: bool,
finalizing: bool, finalizing: bool,
is_pre_fork: bool, is_pre_fork: bool,
@@ -532,7 +535,10 @@ where
// create a directory to which files will be output // create a directory to which files will be output
let slate_dir = format!("{}/{}", tld, "slatepack"); let slate_dir = format!("{}/{}", tld, "slatepack");
let _ = std::fs::create_dir_all(slate_dir.clone()); 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 { if lock {
controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| { controller::owner_single_use(None, keychain_mask, Some(owner_api), |api, m| {
@@ -663,6 +669,7 @@ pub struct ReceiveArgs {
pub input_file: Option<String>, pub input_file: Option<String>,
pub input_slatepack_message: Option<String>, pub input_slatepack_message: Option<String>,
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>,
} }
pub fn receive<L, C, K>( pub fn receive<L, C, K>(
@@ -726,6 +733,7 @@ where
keychain_mask, keychain_mask,
&slate, &slate,
&dest, &dest,
args.outfile,
false, false,
false, false,
slate.version_info.version < 4, slate.version_info.version < 4,
@@ -821,6 +829,7 @@ pub struct FinalizeArgs {
pub input_slatepack_message: Option<String>, pub input_slatepack_message: Option<String>,
pub fluff: bool, pub fluff: bool,
pub nopost: bool, pub nopost: bool,
pub outfile: Option<String>,
} }
pub fn finalize<L, C, K>( pub fn finalize<L, C, K>(
@@ -893,6 +902,7 @@ where
keychain_mask, keychain_mask,
&slate, &slate,
"", "",
args.outfile,
false, false,
true, true,
slate.version_info.version < 4, slate.version_info.version < 4,
@@ -903,12 +913,14 @@ where
/// Issue Invoice Args /// Issue Invoice Args
pub struct IssueInvoiceArgs { pub struct IssueInvoiceArgs {
/// output file /// Slatepack address
pub dest: String, pub dest: String,
/// issue invoice tx args /// issue invoice tx args
pub issue_args: IssueInvoiceTxArgs, pub issue_args: IssueInvoiceTxArgs,
/// whether to output a V4 slate /// whether to output a V4 slate
pub output_v4_slate: bool, pub output_v4_slate: bool,
/// output file override
pub outfile: Option<String>,
} }
pub fn issue_invoice_tx<L, C, K>( pub fn issue_invoice_tx<L, C, K>(
@@ -964,6 +976,7 @@ where
keychain_mask, keychain_mask,
&slate, &slate,
args.dest.as_str(), args.dest.as_str(),
args.outfile,
false, false,
false, false,
is_pre_fork, is_pre_fork,
@@ -981,6 +994,7 @@ pub struct ProcessInvoiceArgs {
pub estimate_selection_strategies: bool, pub estimate_selection_strategies: bool,
pub ttl_blocks: Option<u64>, pub ttl_blocks: Option<u64>,
pub skip_tor: bool, pub skip_tor: bool,
pub outfile: Option<String>,
} }
/// Process invoice /// Process invoice
@@ -1081,6 +1095,7 @@ where
keychain_mask, keychain_mask,
&slate, &slate,
&dest, &dest,
args.outfile,
true, true,
false, false,
slate.version_info.version < 4, slate.version_info.version < 4,
+25
View File
@@ -145,6 +145,11 @@ subcommands:
help: If present, don't attempt to send the resulting Slatepack via TOR help: If present, don't attempt to send the resulting Slatepack via TOR
short: m short: m
long: manual 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 #TODO: Remove HF3
- v4: - v4:
help: Output a V4 slate prior to HF3 block 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 help: If present, don't attempt to send the resulting Slatepack via TOR
short: m short: m
long: manual long: manual
- outfile:
help: If present, overrides the filename and location of the output Slatepack file.
short: u
long: outfile
takes_value: true
- finalize: - finalize:
about: Processes a Slatepack Message to finalize a transfer. about: Processes a Slatepack Message to finalize a transfer.
args: args:
@@ -186,6 +196,11 @@ subcommands:
help: Do not post the transaction. help: Do not post the transaction.
short: n short: n
long: nopost long: nopost
- outfile:
help: If present, overrides the filename and location of the output Slatepack file.
short: u
long: outfile
takes_value: true
- invoice: - invoice:
about: Initialize an invoice transaction, outputting a Slatepack Message with the result about: Initialize an invoice transaction, outputting a Slatepack Message with the result
args: args:
@@ -197,6 +212,11 @@ subcommands:
short: d short: d
long: dest long: dest
takes_value: true 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 #TODO: Remove HF3
- v4: - v4:
help: Output a V4 slate prior to HF3 block 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 help: If present, don't attempt to send the resulting Slatepack via TOR
short: m short: m
long: manual long: manual
- outfile:
help: If present, overrides the filename and location of the output Slatepack file.
short: u
long: outfile
takes_value: true
- outputs: - outputs:
about: Raw wallet output info (list of outputs) about: Raw wallet output info (list of outputs)
- txs: - txs:
+33
View File
@@ -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<Option<String>, 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 // parses a number, or throws error with message otherwise
fn parse_u64(arg: &str, name: &str) -> Result<u64, ParseError> { fn parse_u64(arg: &str, name: &str) -> Result<u64, ParseError> {
let val = arg.parse::<u64>(); let val = arg.parse::<u64>();
@@ -514,6 +529,8 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
} }
}; };
let outfile = parse_optional(args, "outfile")?;
Ok(command::SendArgs { Ok(command::SendArgs {
amount: amount, amount: amount,
minimum_confirmations: min_c, minimum_confirmations: min_c,
@@ -527,6 +544,7 @@ pub fn parse_send_args(args: &ArgMatches) -> Result<command::SendArgs, ParseErro
ttl_blocks, ttl_blocks,
target_slate_version: target_slate_version, target_slate_version: target_slate_version,
output_v4_slate, output_v4_slate,
outfile,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
}) })
} }
@@ -551,10 +569,13 @@ pub fn parse_receive_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Par
input_slatepack_message = Some(prompt_slatepack()?); input_slatepack_message = Some(prompt_slatepack()?);
} }
let outfile = parse_optional(args, "outfile")?;
Ok(command::ReceiveArgs { Ok(command::ReceiveArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile,
}) })
} }
@@ -578,10 +599,13 @@ pub fn parse_unpack_args(args: &ArgMatches) -> Result<command::ReceiveArgs, Pars
input_slatepack_message = Some(prompt_slatepack()?); input_slatepack_message = Some(prompt_slatepack()?);
} }
let outfile = parse_optional(args, "outfile")?;
Ok(command::ReceiveArgs { Ok(command::ReceiveArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile,
}) })
} }
@@ -607,11 +631,14 @@ pub fn parse_finalize_args(args: &ArgMatches) -> Result<command::FinalizeArgs, P
input_slatepack_message = Some(prompt_slatepack()?); input_slatepack_message = Some(prompt_slatepack()?);
} }
let outfile = parse_optional(args, "outfile")?;
Ok(command::FinalizeArgs { Ok(command::FinalizeArgs {
input_file, input_file,
input_slatepack_message, input_slatepack_message,
fluff: fluff, fluff: fluff,
nopost: nopost, nopost: nopost,
outfile,
}) })
} }
@@ -651,6 +678,8 @@ pub fn parse_issue_invoice_args(
None => "default", None => "default",
}; };
let outfile = parse_optional(args, "outfile")?;
Ok(command::IssueInvoiceArgs { Ok(command::IssueInvoiceArgs {
dest: dest.into(), dest: dest.into(),
output_v4_slate, output_v4_slate,
@@ -659,6 +688,7 @@ pub fn parse_issue_invoice_args(
amount, amount,
target_slate_version, target_slate_version,
}, },
outfile,
}) })
} }
@@ -732,6 +762,8 @@ pub fn parse_process_invoice_args(
prompt_pay_invoice(&slate, &dest)?; prompt_pay_invoice(&slate, &dest)?;
} }
let outfile = parse_optional(args, "outfile")?;
Ok(command::ProcessInvoiceArgs { Ok(command::ProcessInvoiceArgs {
minimum_confirmations: min_c, minimum_confirmations: min_c,
selection_strategy: selection_strategy.to_owned(), selection_strategy: selection_strategy.to_owned(),
@@ -741,6 +773,7 @@ pub fn parse_process_invoice_args(
max_outputs, max_outputs,
ttl_blocks, ttl_blocks,
skip_tor: args.is_present("manual"), skip_tor: args.is_present("manual"),
outfile,
}) })
} }