diff --git a/src/subcommand/wallet/inscribe.rs b/src/subcommand/wallet/inscribe.rs index a0f9c641a4..202360e85e 100644 --- a/src/subcommand/wallet/inscribe.rs +++ b/src/subcommand/wallet/inscribe.rs @@ -45,6 +45,11 @@ pub(crate) struct ParentInfo { } #[derive(Debug, Parser)] +#[clap( + group = ArgGroup::new("source") + .required(true) + .args(&["file", "batch"]), +)] pub(crate) struct Inscribe { #[arg( long, @@ -121,43 +126,47 @@ impl Inscribe { let mode; let parent_info; - if let Some(batch) = self.batch { - let batchfile = Batchfile::load(&batch)?; + match (self.file, self.batch) { + (Some(file), None) => { + parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain)?; + inscriptions = vec![Inscription::from_file( + chain, + file, + self.parent, + None, + self.metaprotocol, + metadata, + )?]; + mode = Mode::SeparateOutputs; + destinations = vec![match self.destination.clone() { + Some(destination) => destination.require_network(chain.network())?, + None => get_change_address(&client, chain)?, + }]; + } + (None, Some(batch)) => { + let batchfile = Batchfile::load(&batch)?; - parent_info = Inscribe::get_parent_info(batchfile.parent, &index, &utxos, &client, chain)?; + parent_info = Inscribe::get_parent_info(batchfile.parent, &index, &utxos, &client, chain)?; - inscriptions = batchfile.inscriptions( - chain, - parent_info.as_ref().map(|info| info.tx_out.value), - metadata, - postage, - )?; + inscriptions = batchfile.inscriptions( + chain, + parent_info.as_ref().map(|info| info.tx_out.value), + metadata, + postage, + )?; - mode = batchfile.mode; + mode = batchfile.mode; - let destination_count = match batchfile.mode { - Mode::SharedOutput => 1, - Mode::SeparateOutputs => inscriptions.len(), - }; + let destination_count = match batchfile.mode { + Mode::SharedOutput => 1, + Mode::SeparateOutputs => inscriptions.len(), + }; - destinations = (0..destination_count) - .map(|_| get_change_address(&client, chain)) - .collect::>>()?; - } else { - parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain)?; - inscriptions = vec![Inscription::from_file( - chain, - self.file.clone().unwrap(), - self.parent, - None, - self.metaprotocol.clone(), - metadata.clone(), - )?]; - mode = Mode::SeparateOutputs; - destinations = vec![match self.destination.clone() { - Some(destination) => destination.require_network(chain.network())?, - None => get_change_address(&client, chain)?, - }]; + destinations = (0..destination_count) + .map(|_| get_change_address(&client, chain)) + .collect::>>()?; + } + _ => unreachable!(), } Batch { @@ -1281,4 +1290,14 @@ inscriptions: .contains("the argument '--batch ' cannot be used with")); } } + + #[test] + fn batch_or_file_is_required() { + assert!( + Arguments::try_parse_from(["ord", "wallet", "inscribe", "--fee-rate", "1",]) + .unwrap_err() + .to_string() + .contains("error: the following required arguments were not provided:\n <--file |--batch >") + ); + } }