Skip to content

Commit

Permalink
Until now, using --commitment caused the reveal tx to create a change…
Browse files Browse the repository at this point in the history
… output. This change allows us to skip the change output by setting --reveal-fee to 0sat.
  • Loading branch information
gmart7t2 committed Feb 20, 2024
1 parent 0127ac9 commit 639f8bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ pub(crate) struct Inscribe {
pub(crate) key: Option<String>,
#[clap(long, help = "Don't make a reveal tx; just create a commit tx that sends all the sats to a new commitment. Either specify --key if you have one, or note the --key it generates for you. Implies --no-backup.")]
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.")]
#[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. When using --commitment, the reveal tx will create a change output unless --reveal-fee is set to '0 sats', in which case the whole commitment will go to postage and fees.")]
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>,
Expand Down
28 changes: 17 additions & 11 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,11 +658,13 @@ impl Batch {

let commit_input = if self.parent_info.is_some() { 1 } else { 0 };

if self.commitment.is_some() {
reveal_outputs.push(TxOut {
script_pubkey: reveal_change_address.unwrap().script_pubkey(),
value: 0,
});
if self.reveal_fee != Some(Amount::from_sat(0)) {
if self.commitment.is_some() {
reveal_outputs.push(TxOut {
script_pubkey: reveal_change_address.unwrap().script_pubkey(),
value: 0,
});
}
}

let (_, mut reveal_fee, reveal_vsize) = Self::build_reveal_transaction(
Expand Down Expand Up @@ -718,11 +720,13 @@ impl Batch {
reveal_fee = (fee_utxos_value * reveal_vsize + Amount::from_sat(total_vsize - 1)) / total_vsize;
// eprintln!("reveal_fee = (fee_utxos {} * reveal_vsize {} + total_vsize {} - 1) / total_vsize {} = reveal_fee {}", fee_utxos_value.to_sat(), reveal_vsize, total_vsize, total_vsize, reveal_fee.to_sat());
} else if let Some(r) = self.reveal_fee {
if r < reveal_fee {
return Err(anyhow!("requested reveal_fee is too small; should be at least {} sats", reveal_fee.to_sat()));
}
if r != Amount::from_sat(0) {
if r < reveal_fee {
return Err(anyhow!("requested reveal_fee is too small; should be at least {} sats", reveal_fee.to_sat()));
}

reveal_fee = r;
reveal_fee = r;
}
}

let unsigned_commit_tx = if self.commitment.is_some() {
Expand Down Expand Up @@ -767,8 +771,10 @@ impl Batch {
let vout = if self.commitment.is_some() {
reveal_inputs[commit_input] = self.commitment.unwrap();

if let Some(last) = reveal_outputs.last_mut() {
(*last).value = (reveal_input_value + self.commitment_output.clone().unwrap().value - total_postage - reveal_fee).to_sat();
if self.reveal_fee != Some(Amount::from_sat(0)) {
if let Some(last) = reveal_outputs.last_mut() {
(*last).value = (reveal_input_value + self.commitment_output.clone().unwrap().value - total_postage - reveal_fee).to_sat();
}
}

0
Expand Down

0 comments on commit 639f8bf

Please sign in to comment.