Skip to content

Commit

Permalink
Add --parent-satpoint to help with using an unconfirmed parent insc…
Browse files Browse the repository at this point in the history
…ription.
  • Loading branch information
gmart7t2 committed Jan 14, 2024
1 parent e11bbac commit b5a2363
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/subcommand/preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl Preview {
no_broadcast: false,
no_limit: false,
parent: None,
parent_satpoint: None,
postage: Some(TARGET_POSTAGE),
reinscribe: false,
reveal_input: Vec::new(),
Expand Down Expand Up @@ -172,6 +173,7 @@ impl Preview {
no_broadcast: false,
no_limit: false,
parent: None,
parent_satpoint: None,
postage: Some(TARGET_POSTAGE),
reinscribe: false,
reveal_input: Vec::new(),
Expand Down
19 changes: 14 additions & 5 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub(crate) struct Inscribe {
pub(crate) no_limit: bool,
#[clap(long, help = "Make inscription a child of <PARENT>.")]
pub(crate) parent: Option<InscriptionId>,
#[clap(long, help = "The satpoint of the parent inscription, in case it isn't confirmed yet.")]
pub(crate) parent_satpoint: Option<SatPoint>,
#[arg(
long,
help = "Amount of postage to include in the inscription. Default `10000sat`."
Expand Down Expand Up @@ -219,7 +221,7 @@ impl Inscribe {

match (self.file, self.batch) {
(Some(file), None) => {
parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain)?;
parent_info = Inscribe::get_parent_info(self.parent, &index, &utxos, &client, chain, self.parent_satpoint)?;

postage = self.postage.unwrap_or(TARGET_POSTAGE);

Expand Down Expand Up @@ -258,7 +260,7 @@ impl Inscribe {
(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, batchfile.parent_satpoint)?;

postage = batchfile
.postage
Expand Down Expand Up @@ -354,9 +356,19 @@ impl Inscribe {
utxos: &BTreeMap<OutPoint, Amount>,
client: &Client,
chain: Chain,
satpoint: Option<SatPoint>,
) -> Result<Option<ParentInfo>> {
if let Some(parent_id) = parent {
let satpoint = if let Some(satpoint) = satpoint {
satpoint
} else {
if let Some(satpoint) = index.get_inscription_satpoint_by_id(parent_id)? {
satpoint
} else {
return Err(anyhow!(format!("parent {parent_id} does not exist")));
}
};

if !utxos.contains_key(&satpoint.outpoint) {
return Err(anyhow!(format!("parent {parent_id} not in wallet")));
}
Expand All @@ -373,9 +385,6 @@ impl Inscribe {
.nth(satpoint.outpoint.vout.try_into().unwrap())
.expect("current transaction output"),
}))
} else {
Err(anyhow!(format!("parent {parent_id} does not exist")))
}
} else {
Ok(None)
}
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl Batch {
});
}

let signed_reveal_tx = if reveal_input_info.is_empty() {
let signed_reveal_tx = if reveal_input_info.is_empty() && self.parent_info.is_none() {
consensus::encode::serialize(&reveal_tx)
} else {
client
Expand Down Expand Up @@ -764,6 +764,7 @@ pub(crate) struct Batchfile {
pub(crate) inscriptions: Vec<BatchEntry>,
pub(crate) mode: Mode,
pub(crate) parent: Option<InscriptionId>,
pub(crate) parent_satpoint: Option<SatPoint>,
pub(crate) postage: Option<u64>,
pub(crate) sat: Option<Sat>,
}
Expand Down

0 comments on commit b5a2363

Please sign in to comment.