Skip to content

Commit

Permalink
Requre --batch or --file for ord wallet inscribe (ordinals#2581)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 25, 2023
1 parent f8ce0d2 commit 7e1ed85
Showing 1 changed file with 51 additions and 32 deletions.
83 changes: 51 additions & 32 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Result<Vec<Address>>>()?;
} 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::<Result<Vec<Address>>>()?;
}
_ => unreachable!(),
}

Batch {
Expand Down Expand Up @@ -1281,4 +1290,14 @@ inscriptions:
.contains("the argument '--batch <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 <FILE>|--batch <BATCH>>")
);
}
}

0 comments on commit 7e1ed85

Please sign in to comment.