Skip to content

Commit

Permalink
Add --reveal-fee flag to wallet inscribe.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmart7t2 committed Feb 18, 2024
1 parent cabdcbc commit 08dfb10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl Preview {
parent_satpoint: None,
postage: Some(TARGET_POSTAGE),
reinscribe: false,
reveal_fee: None,
reveal_input: Vec::new(),
satpoint: None,
sat: None,
Expand Down Expand Up @@ -180,6 +181,7 @@ impl Preview {
parent_satpoint: None,
postage: Some(TARGET_POSTAGE),
reinscribe: false,
reveal_fee: None,
reveal_input: Vec::new(),
satpoint: None,
sat: None,
Expand Down
4 changes: 4 additions & 0 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ pub(crate) struct Inscribe {
pub(crate) postage: Option<Amount>,
#[clap(long, help = "Allow reinscription.")]
pub(crate) reinscribe: bool,
#[arg(long, help = "Specify the reveal tx fee.")]
pub(crate) reveal_fee: Option<Amount>,
#[arg(long, help = "Inscribe <SATPOINT>.")]
pub(crate) satpoint: Option<SatPoint>,
#[clap(long, help = "Use provided recovery key instead of a random one.")]
Expand Down Expand Up @@ -367,6 +369,7 @@ impl Inscribe {
parent_info,
postage,
reinscribe: self.reinscribe,
reveal_fee: self.reveal_fee,
reveal_fee_rate: self.fee_rate,
reveal_input: self.reveal_input,
reveal_psbt: None,
Expand Down Expand Up @@ -740,6 +743,7 @@ impl Inscribe {
parent_info,
postage,
reinscribe: false,
reveal_fee: None,
reveal_fee_rate: FeeRate::try_from(0.0).unwrap(),
reveal_input: Vec::new(),
reveal_psbt,
Expand Down
12 changes: 12 additions & 0 deletions src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(super) struct Batch {
pub(super) parent_info: Option<ParentInfo>,
pub(super) postage: Amount,
pub(super) reinscribe: bool,
pub(super) reveal_fee: Option<Amount>,
pub(super) reveal_fee_rate: FeeRate,
pub(super) reveal_input: Vec<OutPoint>,
pub(super) reveal_psbt: Option<Psbt>,
Expand Down Expand Up @@ -52,6 +53,7 @@ impl Default for Batch {
parent_info: None,
postage: Amount::from_sat(10_000),
reinscribe: false,
reveal_fee: None,
reveal_fee_rate: 1.0.try_into().unwrap(),
reveal_input: Vec::new(),
reveal_psbt: None,
Expand Down Expand Up @@ -471,6 +473,10 @@ impl Batch {
return Err(anyhow!("--next-file doesn't work without --commitment"));
}

if !self.fee_utxos.is_empty() && self.reveal_fee.is_some() {
return Err(anyhow!("--reveal-fee doesn't work when specifying fee_utxos"));
}

match self.mode {
Mode::SameSat => assert_eq!(
self.destinations.len(),
Expand Down Expand Up @@ -712,6 +718,12 @@ impl Batch {
// eprintln!("total_vsize {} = commit_vsize {} + reveal_vsize {}", total_vsize, commit_vsize, reveal_vsize);
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()));
}

reveal_fee = r;
}

let unsigned_commit_tx = if self.commitment.is_some() {
Expand Down

0 comments on commit 08dfb10

Please sign in to comment.