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

Add multi parent support to wallet #3228

Merged
merged 29 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
13c69e9
Allow storing arrays of parents.
arik-so Mar 6, 2024
b37e339
Update schema version.
arik-so Mar 6, 2024
065e5b6
Add multi parent support to wallet
raphjaph Mar 6, 2024
a032e9d
Parse arrays of parents.
arik-so Mar 6, 2024
7707206
Remove parent() method from Inscription struct.
arik-so Mar 6, 2024
2d1c52b
Update explorer
raphjaph Mar 6, 2024
4de9337
Merge branch 'multi-parent' of github.com:arik-so/ord into arik/multi…
raphjaph Mar 6, 2024
3a9b1b4
Merge pull request #1 from raphjaph/arik/multi-parent
arik-so Mar 6, 2024
eb6a4e3
Fix something
raphjaph Mar 6, 2024
481f0a1
Convert parent field to parents on various inscription structs.
arik-so Mar 6, 2024
501d315
Fix HTML serialization tests.
arik-so Mar 6, 2024
8fb27b2
Create unit test for two-parent-inscription.
arik-so Mar 7, 2024
23f6d8c
Deduplicate parents for inscription information.
arik-so Mar 7, 2024
f53db3c
Merge branch 'multi-parent' into add-multi-parent-to-wallet
raphjaph Mar 7, 2024
06dac5a
Stash
raphjaph Mar 7, 2024
9d549e8
Merge branch 'master' of github.com:ordinals/ord into add-multi-paren…
raphjaph Mar 16, 2024
9a643d8
Merge branch 'master' of github.com:ordinals/ord into add-multi-paren…
raphjaph Aug 16, 2024
7fb77e0
All existing tests pass, still have to write new ones
raphjaph Aug 16, 2024
4170777
Amend
raphjaph Aug 16, 2024
c4da40f
Merge branch 'master' of github.com:ordinals/ord into add-multi-paren…
raphjaph Aug 17, 2024
088a075
Amend
raphjaph Aug 17, 2024
170ab70
Some tests
raphjaph Aug 17, 2024
d31d29f
Merge branch 'master' of github.com:ordinals/ord into add-multi-paren…
raphjaph Aug 20, 2024
a2df4a4
Amend
raphjaph Aug 21, 2024
9b83021
Amend
raphjaph Aug 21, 2024
ae5fcc5
Amend
raphjaph Aug 21, 2024
a3ca35a
Amend
raphjaph Aug 22, 2024
bd21999
Merge branch 'master' of github.com:ordinals/ord into add-multi-paren…
raphjaph Sep 3, 2024
9bcc594
Merge branch 'master' into add-multi-parent-to-wallet
raphjaph Sep 30, 2024
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
5 changes: 3 additions & 2 deletions batch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# - `shared-output`: inscribe on a single output separated by postage
mode: separate-outputs

# parent inscription:
parent: 6ac5cacb768794f4fd7a78bf00f2074891fce68bd65c4ff36e77177237aacacai0
# parent inscriptions:
parents:
- 6ac5cacb768794f4fd7a78bf00f2074891fce68bd65c4ff36e77177237aacacai0

# postage for each inscription:
postage: 12345
Expand Down
11 changes: 6 additions & 5 deletions src/subcommand/wallet/batch_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ impl Batch {

let batchfile = batch::File::load(&self.batch)?;

let parent_info = wallet.get_parent_info(batchfile.parent)?;
let parents_info = wallet.get_parents_info(batchfile.parents.clone())?;
raphjaph marked this conversation as resolved.
Show resolved Hide resolved

let (inscriptions, reveal_satpoints, postages, destinations) = batchfile.inscriptions(
&wallet,
utxos,
parent_info.as_ref().map(|info| info.tx_out.value),
parents_info.iter().map(|info| info.tx_out.value).collect(),
self.shared.compress,
)?;

Expand All @@ -47,7 +47,7 @@ impl Batch {
mode: batchfile.mode,
no_backup: self.shared.no_backup,
no_limit: self.shared.no_limit,
parent_info,
parents_info,
postages,
reinscribe: batchfile.reinscribe,
reveal_fee_rate: self.shared.fee_rate,
Expand Down Expand Up @@ -204,7 +204,8 @@ mod tests {
&batch_path,
format!(
"mode: separate-outputs
parent: {parent}
parents:
- {parent}
inscriptions:
- file: {}
metadata:
Expand Down Expand Up @@ -241,7 +242,7 @@ inscriptions:
..default()
}
],
parent: Some(parent),
parents: vec![parent],
..default()
}
);
Expand Down
3 changes: 2 additions & 1 deletion src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ impl Inscribe {
mode: batch::Mode::SeparateOutputs,
no_backup: self.shared.no_backup,
no_limit: self.shared.no_limit,
parent_info: wallet.get_parent_info(self.parent)?,
parents_info: wallet
.get_parents_info(self.parent.map_or_else(Vec::new, |parent| vec![parent]))?,
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
postages: vec![self.postage.unwrap_or(TARGET_POSTAGE)],
reinscribe: self.reinscribe,
reveal_fee_rate: self.shared.fee_rate,
Expand Down
16 changes: 7 additions & 9 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,9 @@ impl Wallet {
)
}

pub(crate) fn get_parent_info(
&self,
parent: Option<InscriptionId>,
) -> Result<Option<ParentInfo>> {
if let Some(parent_id) = parent {
pub(crate) fn get_parents_info(&self, parents: Vec<InscriptionId>) -> Result<Vec<ParentInfo>> {
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
let mut parents_info = Vec::new();
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
for parent_id in parents {
if !self.inscription_exists(parent_id)? {
return Err(anyhow!("parent {parent_id} does not exist"));
}
Expand All @@ -221,15 +219,15 @@ impl Wallet {
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
.clone();

Ok(Some(ParentInfo {
parents_info.push(ParentInfo {
destination: self.get_change_address()?,
id: parent_id,
location: satpoint,
tx_out,
}))
} else {
Ok(None)
});
}

Ok(parents_info)
}

pub(crate) fn get_runic_outputs(&self) -> Result<BTreeSet<OutPoint>> {
Expand Down
34 changes: 17 additions & 17 deletions src/wallet/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Output {
pub commit: Txid,
pub commit_psbt: Option<String>,
pub inscriptions: Vec<InscriptionInfo>,
pub parent: Option<InscriptionId>,
pub parents: Vec<InscriptionId>,
pub reveal: Txid,
pub reveal_broadcast: bool,
pub reveal_psbt: Option<String>,
Expand Down Expand Up @@ -86,7 +86,7 @@ mod tests {
..
} = batch::Plan {
satpoint: Some(satpoint(1, 0)),
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -132,7 +132,7 @@ mod tests {
..
} = batch::Plan {
satpoint: Some(satpoint(1, 0)),
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -177,7 +177,7 @@ mod tests {

let error = batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -229,7 +229,7 @@ mod tests {

assert!(batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -279,7 +279,7 @@ mod tests {
..
} = batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(fee_rate).unwrap(),
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {
..
} = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions: vec![child_inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(fee_rate).unwrap(),
Expand Down Expand Up @@ -454,7 +454,7 @@ mod tests {
..
} = batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(commit_fee_rate).unwrap(),
Expand Down Expand Up @@ -513,7 +513,7 @@ mod tests {

let error = batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -554,7 +554,7 @@ mod tests {

let batch::Transactions { reveal_tx, .. } = batch::Plan {
satpoint,
parent_info: None,
parents_info: Vec::new(),
inscriptions: vec![inscription],
destinations: vec![reveal_address],
commit_fee_rate: FeeRate::try_from(1.0).unwrap(),
Expand Down Expand Up @@ -635,7 +635,7 @@ mod tests {
..
} = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -762,7 +762,7 @@ mod tests {
..
} = batch::Plan {
reveal_satpoints: reveal_satpoints.clone(),
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -864,7 +864,7 @@ mod tests {

let error = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: 4.0.try_into().unwrap(),
Expand Down Expand Up @@ -941,7 +941,7 @@ mod tests {

let _ = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: 4.0.try_into().unwrap(),
Expand Down Expand Up @@ -980,7 +980,7 @@ mod tests {

let error = batch::Plan {
satpoint: None,
parent_info: None,
parents_info: Vec::new(),
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: 1.0.try_into().unwrap(),
Expand Down Expand Up @@ -1034,7 +1034,7 @@ mod tests {

let batch::Transactions { reveal_tx, .. } = batch::Plan {
satpoint: None,
parent_info: None,
parents_info: Vec::new(),
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -1119,7 +1119,7 @@ mod tests {
..
} = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parents_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down
13 changes: 7 additions & 6 deletions src/wallet/batch/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ use super::*;
pub struct File {
pub inscriptions: Vec<Entry>,
pub mode: Mode,
pub parent: Option<InscriptionId>,
#[serde(default)]
pub parents: Vec<InscriptionId>,
pub postage: Option<u64>,
#[serde(default)]
pub reinscribe: bool,
Expand Down Expand Up @@ -107,7 +108,7 @@ impl File {
&self,
wallet: &Wallet,
utxos: &BTreeMap<OutPoint, TxOut>,
parent_value: Option<u64>,
parents_values: Vec<u64>,
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
compress: bool,
) -> Result<(
Vec<Inscription>,
Expand All @@ -119,7 +120,7 @@ impl File {
let mut reveal_satpoints = Vec::new();
let mut postages = Vec::new();

let mut pointer = parent_value.unwrap_or_default();
let mut pointer = parents_values.iter().sum();

for (i, entry) in self.inscriptions.iter().enumerate() {
if let Some(delegate) = entry.delegate {
Expand All @@ -135,7 +136,7 @@ impl File {
entry.delegate,
entry.metadata()?,
entry.metaprotocol.clone(),
self.parent.into_iter().collect(),
self.parents.clone(),
entry.file.clone(),
Some(pointer),
self
Expand Down Expand Up @@ -366,11 +367,11 @@ inscriptions:
batch::File::load(Path::new("batch.yaml")).unwrap(),
batch::File {
mode: batch::Mode::SeparateOutputs,
parent: Some(
parents: vec![
"6ac5cacb768794f4fd7a78bf00f2074891fce68bd65c4ff36e77177237aacacai0"
.parse()
.unwrap()
),
],
postage: Some(12345),
reinscribe: true,
sat: None,
Expand Down
32 changes: 11 additions & 21 deletions src/wallet/batch/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub struct Plan {
pub(crate) mode: Mode,
pub(crate) no_backup: bool,
pub(crate) no_limit: bool,
pub(crate) parent_info: Option<ParentInfo>,
pub(crate) parents_info: Vec<ParentInfo>,
pub(crate) postages: Vec<Amount>,
pub(crate) reinscribe: bool,
pub(crate) reveal_fee_rate: FeeRate,
Expand All @@ -28,7 +28,7 @@ impl Default for Plan {
mode: Mode::SharedOutput,
no_backup: false,
no_limit: false,
parent_info: None,
parents_info: Vec::new(),
postages: vec![Amount::from_sat(10_000)],
reinscribe: false,
reveal_fee_rate: 1.0.try_into().unwrap(),
Expand Down Expand Up @@ -206,19 +206,9 @@ impl Plan {
let index = u32::try_from(i).unwrap();

let vout = match self.mode {
Mode::SharedOutput | Mode::SameSat => {
if self.parent_info.is_some() {
1
} else {
0
}
}
Mode::SharedOutput | Mode::SameSat => self.parents_info.len().try_into().unwrap(),
Mode::SeparateOutputs | Mode::SatPoints => {
if self.parent_info.is_some() {
index + 1
} else {
index
}
index + u32::try_from(self.parents_info.len()).unwrap()
}
};

Expand Down Expand Up @@ -252,7 +242,7 @@ impl Plan {
commit,
commit_psbt,
inscriptions: inscriptions_output,
parent: self.parent_info.clone().map(|info| info.id),
parents: self.parents_info.iter().map(|info| info.id).collect(),
reveal,
reveal_broadcast,
reveal_psbt,
Expand All @@ -271,7 +261,7 @@ impl Plan {
commit_change: [Address; 2],
reveal_change: Address,
) -> Result<Transactions> {
if let Some(parent_info) = &self.parent_info {
for parent_info in &self.parents_info {
raphjaph marked this conversation as resolved.
Show resolved Hide resolved
for inscription in &self.inscriptions {
assert_eq!(inscription.parents(), vec![parent_info.id]);
}
Expand Down Expand Up @@ -396,12 +386,12 @@ impl Plan {
let mut reveal_inputs = Vec::new();
let mut reveal_outputs = Vec::new();

if let Some(ParentInfo {
for ParentInfo {
location,
id: _,
destination,
tx_out,
}) = self.parent_info.clone()
} in &self.parents_info
{
reveal_inputs.push(location.outpoint);
reveal_outputs.push(TxOut {
Expand Down Expand Up @@ -505,7 +495,7 @@ impl Plan {
runestone = None;
}

let commit_input = usize::from(self.parent_info.is_some()) + self.reveal_satpoints.len();
let commit_input = self.parents_info.len() + self.reveal_satpoints.len();

let (_reveal_tx, reveal_fee) = Self::build_reveal_transaction(
commit_input,
Expand Down Expand Up @@ -571,8 +561,8 @@ impl Plan {

let mut prevouts = Vec::new();

if let Some(parent_info) = self.parent_info.clone() {
prevouts.push(parent_info.tx_out);
for parent_info in &self.parents_info {
prevouts.push(parent_info.tx_out.clone());
}

if self.mode == Mode::SatPoints {
Expand Down
Loading
Loading