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 inscribing a delegate without content #3027

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions src/inscriptions/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,26 @@ impl Inscription {
})
}

pub(crate) fn without_file(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub(crate) fn without_file(
pub(crate) fn delegate_only(

delegate: Option<InscriptionId>,
metadata: Option<Vec<u8>>,
metaprotocol: Option<String>,
parent: Option<InscriptionId>,
pointer: Option<u64>,
) -> Result<Self, Error> {
Ok(Self {
body: None,
content_encoding: None,
content_type: None,
delegate: delegate.map(|delegate| delegate.value()),
metadata,
metaprotocol: metaprotocol.map(|metaprotocol| metaprotocol.into_bytes()),
parent: parent.map(|parent| parent.value()),
pointer: pointer.map(Self::pointer_value),
..Default::default()
})
}

pub(crate) fn pointer_value(pointer: u64) -> Vec<u8> {
let mut bytes = pointer.to_le_bytes().to_vec();

Expand Down
35 changes: 31 additions & 4 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::*;
#[clap(
group = ArgGroup::new("source")
.required(true)
.args(&["file", "batch"]),
.args(&["file", "batch", "delegate"]),
)]
pub(crate) struct Inscribe {
#[arg(
Expand Down Expand Up @@ -89,8 +89,8 @@ impl Inscribe {
let parent_info;
let sat;

match (self.file, self.batch) {
(Some(file), None) => {
match (self.file, self.batch, self.delegate) {
(Some(file), None, _) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would mean if we have a file and a delegate it would still inscribe the file. Same with the batch below. This should be tested.

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

postage = self.postage.unwrap_or(TARGET_POSTAGE);
Expand Down Expand Up @@ -122,7 +122,7 @@ impl Inscribe {
None => wallet.get_change_address()?,
}];
}
(None, Some(batch)) => {
(None, Some(batch), _) => {
let batchfile = Batchfile::load(&batch)?;

parent_info = wallet.get_parent_info(batchfile.parent, &utxos)?;
Expand All @@ -148,6 +148,33 @@ impl Inscribe {

sat = batchfile.sat;
}
(None, None, Some(delegate)) => {
parent_info = wallet.get_parent_info(self.parent, &utxos)?;

postage = self.postage.unwrap_or(TARGET_POSTAGE);

ensure! {
wallet.inscription_exists(delegate)?,
"delegate {delegate} does not exist"
}
Comment on lines +156 to +159
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a flag called --allow-non-existant-delegate and then skip this check if it is set.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the expected response for non-existent-delegate w/o payload and existent-delegate w/ payload?


inscriptions = vec![Inscription::without_file(
self.delegate,
metadata,
self.metaprotocol,
self.parent,
None,
)?];

mode = Mode::SeparateOutputs;

sat = self.sat;

destinations = vec![match self.destination.clone() {
Some(destination) => destination.require_network(chain.network())?,
None => wallet.get_change_address()?,
}];
}
_ => unreachable!(),
}

Expand Down
Loading