Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying satpoint in batch inscription entry #3115

Merged
merged 26 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Inscribe {

let chain = wallet.chain();

let postage;
let postages;
let destinations;
let inscriptions;
let mode;
Expand All @@ -92,7 +92,7 @@ impl Inscribe {
(Some(file), None) => {
parent_info = wallet.get_parent_info(self.parent, &utxos)?;

postage = self.postage.unwrap_or(TARGET_POSTAGE);
postages = vec![self.postage.unwrap_or(TARGET_POSTAGE)];

if let Some(delegate) = self.delegate {
ensure! {
Expand Down Expand Up @@ -130,15 +130,10 @@ impl Inscribe {

parent_info = wallet.get_parent_info(batchfile.parent, &utxos)?;

postage = batchfile
.postage
.map(Amount::from_sat)
.unwrap_or(TARGET_POSTAGE);

(inscriptions, destinations) = batchfile.inscriptions(
(inscriptions, postages, destinations) = batchfile.inscriptions(
&wallet,
&utxos,
parent_info.as_ref().map(|info| info.tx_out.value),
postage,
self.compress,
)?;

Expand All @@ -162,7 +157,7 @@ impl Inscribe {
no_backup: self.no_backup,
no_limit: self.no_limit,
parent_info,
postage,
postages,
reinscribe: self.reinscribe,
reveal_fee_rate: self.fee_rate,
satpoint,
Expand Down Expand Up @@ -217,7 +212,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -258,7 +253,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -302,7 +297,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -353,7 +348,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -398,7 +393,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(fee_rate).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -481,7 +476,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(fee_rate).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -563,7 +558,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(fee_rate).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -621,7 +616,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: false,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -661,7 +656,7 @@ mod tests {
reveal_fee_rate: FeeRate::try_from(1.0).unwrap(),
no_limit: true,
reinscribe: false,
postage: TARGET_POSTAGE,
postages: vec![TARGET_POSTAGE],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -834,7 +829,7 @@ inscriptions:
reveal_fee_rate: fee_rate,
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000); 3],
mode,
..Default::default()
}
Expand Down Expand Up @@ -934,7 +929,7 @@ inscriptions:
reveal_fee_rate: 4.0.try_into().unwrap(),
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000); 3],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -1010,7 +1005,7 @@ inscriptions:
reveal_fee_rate: 4.0.try_into().unwrap(),
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000)],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -1048,7 +1043,7 @@ inscriptions:
reveal_fee_rate: 1.0.try_into().unwrap(),
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(30_000),
postages: vec![Amount::from_sat(30_000); 3],
mode: Mode::SharedOutput,
..Default::default()
}
Expand Down Expand Up @@ -1101,7 +1096,7 @@ inscriptions:
reveal_fee_rate: fee_rate,
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000); 3],
mode,
..Default::default()
}
Expand Down Expand Up @@ -1181,7 +1176,7 @@ inscriptions:
reveal_fee_rate: fee_rate,
no_limit: false,
reinscribe: false,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000); 3],
mode,
..Default::default()
}
Expand Down
85 changes: 55 additions & 30 deletions src/wallet/inscribe/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Batch {
pub(crate) no_backup: bool,
pub(crate) no_limit: bool,
pub(crate) parent_info: Option<ParentInfo>,
pub(crate) postage: Amount,
pub(crate) postages: Vec<Amount>,
pub(crate) reinscribe: bool,
pub(crate) reveal_fee_rate: FeeRate,
pub(crate) satpoint: Option<SatPoint>,
Expand All @@ -26,7 +26,7 @@ impl Default for Batch {
no_backup: false,
no_limit: false,
parent_info: None,
postage: Amount::from_sat(10_000),
postages: vec![Amount::from_sat(10_000)],
reinscribe: false,
reveal_fee_rate: 1.0.try_into().unwrap(),
satpoint: None,
Expand Down Expand Up @@ -138,7 +138,7 @@ impl Batch {
0
}
}
Mode::SeparateOutputs => {
Mode::SeparateOutputs | Mode::SatPoints => {
if self.parent_info.is_some() {
index + 1
} else {
Expand All @@ -148,8 +148,15 @@ impl Batch {
};

let offset = match self.mode {
Mode::SharedOutput => u64::from(index) * self.postage.to_sat(),
Mode::SeparateOutputs | Mode::SameSat => 0,
Mode::SharedOutput => {
u64::from(index)
* self
.postages
.first()
.map(|amount| amount.to_sat())
.unwrap_or_default()
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
}
Mode::SeparateOutputs | Mode::SameSat | Mode::SatPoints => 0,
};

inscriptions_output.push(InscriptionInfo {
Expand Down Expand Up @@ -190,21 +197,42 @@ impl Batch {
}

match self.mode {
Mode::SameSat => assert_eq!(
self.destinations.len(),
1,
"invariant: same-sat has only one destination"
),
Mode::SeparateOutputs => assert_eq!(
self.destinations.len(),
self.inscriptions.len(),
"invariant: destination addresses and number of inscriptions doesn't match"
),
Mode::SharedOutput => assert_eq!(
self.destinations.len(),
1,
"invariant: shared-output has only one destination"
),
Mode::SameSat => {
assert_eq!(
self.postages.len(),
1,
"invariant: same-sat has only one postage"
);
assert_eq!(
self.destinations.len(),
1,
"invariant: same-sat has only one destination"
);
}
Mode::SeparateOutputs | Mode::SatPoints => {
assert_eq!(
self.destinations.len(),
self.inscriptions.len(),
"invariant: destination addresses and number of inscriptions doesn't match"
);
assert_eq!(
self.destinations.len(),
self.postages.len(),
"invariant: destination addresses and number of postages doesn't match"
);
}
Mode::SharedOutput => {
assert_eq!(
self.destinations.len(),
1,
"invariant: shared-output has only one destination"
);
assert_eq!(
self.postages.len(),
self.inscriptions.len(),
"invariant: postages and number of inscriptions doesn't match"
);
}
}

let satpoint = if let Some(satpoint) = self.satpoint {
Expand Down Expand Up @@ -282,22 +310,19 @@ impl Batch {

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

let total_postage = match self.mode {
Mode::SameSat => self.postage,
Mode::SharedOutput | Mode::SeparateOutputs => {
self.postage * u64::try_from(self.inscriptions.len()).unwrap()
}
};
let total_postage = self.postages.iter().map(|amount| amount.to_sat()).sum();

let mut reveal_inputs = vec![OutPoint::null()];

let mut reveal_outputs = self
.destinations
.iter()
.map(|destination| TxOut {
.enumerate()
.map(|(i, destination)| TxOut {
script_pubkey: destination.script_pubkey(),
value: match self.mode {
Mode::SeparateOutputs => self.postage.to_sat(),
Mode::SharedOutput | Mode::SameSat => total_postage.to_sat(),
Mode::SeparateOutputs | Mode::SatPoints => self.postages[i].to_sat(), // This feels hacky
Mode::SharedOutput | Mode::SameSat => total_postage,
},
})
.collect::<Vec<TxOut>>();
Expand Down Expand Up @@ -339,7 +364,7 @@ impl Batch {
commit_tx_address.clone(),
change,
self.commit_fee_rate,
Target::Value(reveal_fee + total_postage),
Target::Value(reveal_fee + Amount::from_sat(total_postage)),
)
.build_transaction()?;

Expand Down
1 change: 1 addition & 0 deletions src/wallet/inscribe/batch_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct BatchEntry {
pub(crate) file: PathBuf,
pub(crate) metadata: Option<serde_yaml::Value>,
pub(crate) metaprotocol: Option<String>,
pub(crate) satpoint: Option<SatPoint>,
}

impl BatchEntry {
Expand Down
Loading
Loading