Skip to content

Commit

Permalink
Add --next-batch flag, analogous to --next-file, but for batches …
Browse files Browse the repository at this point in the history
…of inscriptions.
  • Loading branch information
gmart7t2 committed Feb 18, 2024
1 parent 08dfb10 commit 26dab6a
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl Preview {
json_metadata: None,
key: None,
metaprotocol: None,
next_batch: None,
next_file: None,
no_backup: true,
no_broadcast: false,
Expand Down Expand Up @@ -172,6 +173,7 @@ impl Preview {
json_metadata: None,
key: None,
metaprotocol: None,
next_batch: None,
next_file: None,
no_backup: true,
no_broadcast: false,
Expand Down
68 changes: 47 additions & 21 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ pub(crate) struct Inscribe {
pub(crate) commit_only: bool,
#[clap(long, help = "Don't make a commit transaction; just create a reveal tx that reveals the inscription committed to by output <COMMITMENT>. Requires the same --key as was used to make the commitment. Implies --no-backup. This doesn't work if the --key has ever been backed up to the wallet.")]
pub(crate) commitment: Option<OutPoint>,
#[arg(long, help = "Make the change of the reveal tx commit to the contents of multiple inscriptions defined in a yaml <NEXT-BATCH>.")]
pub(crate) next_batch: Option<PathBuf>,
#[clap(long, help = "Make the change of the reveal tx commit to the contents of <NEXT-FILE>.")]
pub(crate) next_file: Option<PathBuf>,
#[clap(long, help = "Use <REVEAL-INPUT> as an extra input to the reveal tx. For use with `--commitment`.")]
Expand Down Expand Up @@ -179,8 +181,16 @@ impl Inscribe {
return Err(anyhow!("--commit-only and --commitment don't work together"));
}

if self.next_batch.is_some() && self.next_file.is_some() {
return Err(anyhow!("--next-batch and --next-file don't work together"));
}

if self.commit_only && self.next_batch.is_some() {
return Err(anyhow!("--commit-only and --next-batch don't work together"));
}

if self.commit_only && self.next_file.is_some() {
return Err(anyhow!("--commit-only and --next_file don't work together"));
return Err(anyhow!("--commit-only and --next-file don't work together"));
}

if self.commitment.is_none() && !self.reveal_input.is_empty() {
Expand Down Expand Up @@ -251,9 +261,40 @@ impl Inscribe {
let inscriptions;
let mode;
let parent_info;
let next_inscription;
let sat;

let next_inscriptions = if self.next_file.is_some() {
vec![Inscription::from_file(
chain,
self.next_file.unwrap(),
self.parent,
None,
self.metaprotocol.clone(),
metadata.clone(),
self.compress,
None,
)?]
} else if self.next_batch.is_some() {
let batchfile = Batchfile::load(&self.next_batch.unwrap())?;
let parent_info = Inscribe::get_parent_info(batchfile.parent, &index, &utxos, &client, chain, batchfile.parent_satpoint, self.no_wallet)?;
let postage = batchfile
.postage
.map(Amount::from_sat)
.unwrap_or(TARGET_POSTAGE);

batchfile.inscriptions(
&client,
chain,
parent_info.as_ref().map(|info| info.tx_out.value),
metadata.clone(),
postage,
self.compress,
&mut utxos,
)?.0
} else {
Vec::new()
};

match (self.file, self.batch) {
(Some(file), None) => {
parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain, self.parent_satpoint, self.no_wallet)?;
Expand All @@ -270,20 +311,6 @@ impl Inscribe {
self.compress,
None,
)?];
next_inscription = if self.next_file.is_some() {
Some(Inscription::from_file(
chain,
self.next_file.unwrap(),
self.parent,
None,
self.metaprotocol,
metadata,
self.compress,
None,
)?)
} else {
None
};

mode = Mode::SeparateOutputs;

Expand Down Expand Up @@ -316,7 +343,6 @@ impl Inscribe {
self.compress,
&mut utxos,
)?;
next_inscription = None;

mode = batchfile.mode;

Expand Down Expand Up @@ -361,7 +387,7 @@ impl Inscribe {
inscriptions,
key: self.key,
mode,
next_inscription,
next_inscriptions,
no_backup,
no_broadcast: self.no_broadcast,
no_limit: self.no_limit,
Expand Down Expand Up @@ -673,7 +699,7 @@ impl Inscribe {
let inscriptions;
let mode;
let parent_info;
let next_inscription;
let next_inscriptions;

let compress = false;

Expand All @@ -693,7 +719,7 @@ impl Inscribe {
compress,
&mut utxos,
)?;
next_inscription = None;
next_inscriptions = Vec::new();

mode = batchfile.mode;

Expand Down Expand Up @@ -735,7 +761,7 @@ impl Inscribe {
inscriptions,
key,
mode,
next_inscription,
next_inscriptions,
no_backup: true,
no_broadcast: true,
no_limit: false,
Expand Down
13 changes: 6 additions & 7 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(super) struct Batch {
pub(super) inscriptions: Vec<Inscription>,
pub(super) key: Option<String>,
pub(super) mode: Mode,
pub(super) next_inscription: Option<Inscription>,
pub(super) next_inscriptions: Vec<Inscription>,
pub(super) no_backup: bool,
pub(super) no_broadcast: bool,
pub(super) no_limit: bool,
Expand Down Expand Up @@ -45,7 +45,7 @@ impl Default for Batch {
inscriptions: Vec::new(),
key: None,
mode: Mode::SharedOutput,
next_inscription: None,
next_inscriptions: Vec::new(),
no_backup: false,
no_broadcast: false,
no_limit: false,
Expand Down Expand Up @@ -469,8 +469,8 @@ impl Batch {
return Err(anyhow!("listing utxos to use as fees only works when inscribing on specified utxos"));
}

if self.next_inscription.is_some() && self.commitment.is_none() {
return Err(anyhow!("--next-file doesn't work without --commitment"));
if !self.next_inscriptions.is_empty() && self.commitment.is_none() {
return Err(anyhow!("--next-batch and --next-file don't work without --commitment"));
}

if !self.fee_utxos.is_empty() && self.reveal_fee.is_some() {
Expand Down Expand Up @@ -585,10 +585,9 @@ impl Batch {

let commit_tx_address = Address::p2tr_tweaked(taproot_spend_info.output_key(), chain.network());

let reveal_change_address = if self.next_inscription.is_some() {
let next_inscriptions = vec![self.next_inscription.clone().unwrap()];
let reveal_change_address = if !self.next_inscriptions.is_empty() {
let next_reveal_script = Inscription::append_batch_reveal_script(
&next_inscriptions,
&self.next_inscriptions,
ScriptBuf::builder()
.push_slice(public_key.serialize())
.push_opcode(opcodes::all::OP_CHECKSIG),
Expand Down

0 comments on commit 26dab6a

Please sign in to comment.