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 delegate without file #3451

Merged
merged 17 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Amend
  • Loading branch information
raphjaph committed Apr 11, 2024
commit abb03f3ba19faa283e0be3c1145a458ecac30eaa
57 changes: 55 additions & 2 deletions src/subcommand/wallet/inscribe.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use super::*;

#[derive(Debug, Parser)]
#[clap(group(ArgGroup::new("input").required(true).multiple(true).args(&["delegate", "file"])))]
#[clap(group(
ArgGroup::new("input")
.required(true)
.multiple(true)
.args(&["delegate", "file"]))
)]
pub(crate) struct Inscribe {
#[command(flatten)]
shared: SharedArgs,
Expand All @@ -15,7 +20,10 @@ pub(crate) struct Inscribe {
pub(crate) delegate: Option<InscriptionId>,
#[arg(long, help = "Send inscription to <DESTINATION>.")]
pub(crate) destination: Option<Address<NetworkUnchecked>>,
#[arg(long, help = "Inscribe sat with contents of <FILE>.")]
#[arg(
long,
help = "Inscribe sat with contents of <FILE>. May be omitted if --delegate is present."
)]
pub(crate) file: Option<PathBuf>,
#[arg(
long,
Expand Down Expand Up @@ -156,4 +164,49 @@ mod tests {
".*--sat.*cannot be used with.*--satpoint.*"
);
}

#[test]
fn delegate_or_file_must_be_set() {
assert_regex_match!(
Arguments::try_parse_from(["ord", "wallet", "inscribe", "--fee-rate", "1"])
.unwrap_err()
.to_string(),
".*required arguments.*--delegate <DELEGATE|--file <FILE>.*"
);

assert!(Arguments::try_parse_from([
"ord",
"wallet",
"inscribe",
"--file",
"hello.txt",
"--fee-rate",
"1"
])
.is_ok());

assert!(Arguments::try_parse_from([
"ord",
"wallet",
"inscribe",
"--delegate",
"038112028c55f3f77cc0b8b413df51f70675f66be443212da0642b7636f68a00i0",
"--fee-rate",
"1"
])
.is_ok());

assert!(Arguments::try_parse_from([
"ord",
"wallet",
"inscribe",
"--file",
"hello.txt",
"--delegate",
"038112028c55f3f77cc0b8b413df51f70675f66be443212da0642b7636f68a00i0",
"--fee-rate",
"1"
])
.is_ok());
}
}
17 changes: 17 additions & 0 deletions src/wallet/batch/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,4 +446,21 @@ inscriptions:
}
);
}

#[test]
fn batchfile_no_delegate_no_file_allowed() {
let tempdir = TempDir::new().unwrap();
let batch_file = tempdir.path().join("batch.yaml");
fs::write(
batch_file.clone(),
r#"
mode: shared-output
inscriptions:
-
"#,
)
.unwrap();

assert!(batch::File::load(batch_file.as_path()).is_ok());
}
}