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 all 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
9 changes: 5 additions & 4 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 parent_info = wallet.get_parent_info(&batchfile.parents)?;

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

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)?,
parent_info: wallet
.get_parent_info(&self.parent.map(|parent| vec![parent]).unwrap_or_default())?,
postages: vec![self.postage.unwrap_or(TARGET_POSTAGE)],
reinscribe: self.reinscribe,
reveal_fee_rate: self.shared.fee_rate,
Expand Down
22 changes: 10 additions & 12 deletions src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,16 @@ impl Wallet {
)
}

pub(crate) fn get_parent_info(
&self,
parent: Option<InscriptionId>,
) -> Result<Option<ParentInfo>> {
if let Some(parent_id) = parent {
if !self.inscription_exists(parent_id)? {
pub(crate) fn get_parent_info(&self, parents: &[InscriptionId]) -> Result<Vec<ParentInfo>> {
let mut parent_info = Vec::new();
for parent_id in parents {
if !self.inscription_exists(*parent_id)? {
return Err(anyhow!("parent {parent_id} does not exist"));
}

let satpoint = self
.inscription_info
.get(&parent_id)
.get(parent_id)
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
.satpoint;

Expand All @@ -237,15 +235,15 @@ impl Wallet {
.ok_or_else(|| anyhow!("parent {parent_id} not in wallet"))?
.clone();

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

Ok(parent_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,
parent_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,
parent_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,
parent_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,
parent_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,
parent_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()),
parent_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,
parent_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,
parent_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,
parent_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()),
parent_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -766,7 +766,7 @@ mod tests {
..
} = batch::Plan {
reveal_satpoints: reveal_satpoints.clone(),
parent_info: Some(parent_info.clone()),
parent_info: vec![parent_info.clone()],
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -868,7 +868,7 @@ mod tests {

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

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

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

let batch::Transactions { reveal_tx, .. } = batch::Plan {
satpoint: None,
parent_info: None,
parent_info: Vec::new(),
inscriptions,
destinations: reveal_addresses,
commit_fee_rate: fee_rate,
Expand Down Expand Up @@ -1131,7 +1131,7 @@ mod tests {
..
} = batch::Plan {
satpoint: None,
parent_info: Some(parent_info.clone()),
parent_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::*;
#[serde(deny_unknown_fields)]
pub struct File {
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 @@ -108,7 +109,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 @@ -120,7 +121,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 @@ -136,7 +137,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 @@ -367,11 +368,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
Loading
Loading