Skip to content

Commit

Permalink
Amend
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Nov 26, 2024
1 parent 260356a commit 8fa9cb7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/subcommand/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub(crate) struct Verify {

impl Verify {
pub(crate) fn run(self) -> SubcommandResult {
let message = if let Some(message) = &self.text {
message.as_bytes()
let message = if let Some(text) = &self.text {
text.as_bytes()
} else if let Some(file) = &self.file {
&fs::read(file)?
} else {
Expand Down
14 changes: 9 additions & 5 deletions src/subcommand/wallet/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ pub struct Output {
group(
ArgGroup::new("input")
.required(true)
.args(&["message", "file"])))
.args(&["text", "file"])))
]
pub(crate) struct Sign {
signer: Signer,
#[arg(
long,
help = "Sign with either <ADDRESS>, <OUTPUT> or <INSCRIPTION_ID>."
)]
sign_with: Signer,
#[arg(long, help = "Sign <TEXT>.")]
text: Option<String>,
#[arg(long, help = "Sign contents of <FILE>.")]
Expand All @@ -26,12 +30,12 @@ pub(crate) struct Sign {

impl Sign {
pub(crate) fn run(&self, wallet: Wallet) -> SubcommandResult {
let address = match &self.signer {
let address = match &self.sign_with {
Signer::Address(address) => address.clone().require_network(wallet.chain().network())?,
Signer::Inscription(inscription) => Address::from_str(
&wallet
.inscription_info()
.get(&inscription)
.get(inscription)
.ok_or_else(|| anyhow!("inscription {inscription} not in wallet"))?
.address
.clone()
Expand All @@ -41,7 +45,7 @@ impl Sign {
Signer::Output(output) => wallet.chain().address_from_script(
&wallet
.utxos()
.get(&output)
.get(output)
.ok_or_else(|| anyhow!("output {output} has no address"))?
.script_pubkey,
)?,
Expand Down
8 changes: 4 additions & 4 deletions tests/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn verify() {
CommandBuilder::new([
"verify",
"--address", "bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l",
"--message", "Hello World",
"--text", "Hello World",
"--witness", "AkcwRAIgZRfIY3p7/DoVTty6YZbWS71bc5Vct9p9Fia83eRmw2QCICK/ENGfwLtptFluMGs2KsqoNSk89pO7F29zJLUx9a/sASECx/EgAxlkQpQ9hYjgGu6EBCPMVPwVIVJqO4XCsMvViHI="
])
.run_and_extract_stdout(),
Expand All @@ -19,7 +19,7 @@ fn verify_fails() {
CommandBuilder::new([
"verify",
"--address", "bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l",
"--message", "Hello World - this should fail",
"--text", "Hello World - this should fail",
"--witness", "AkcwRAIgZRfIY3p7/DoVTty6YZbWS71bc5Vct9p9Fia83eRmw2QCICK/ENGfwLtptFluMGs2KsqoNSk89pO7F29zJLUx9a/sASECx/EgAxlkQpQ9hYjgGu6EBCPMVPwVIVJqO4XCsMvViHI="
])
.expected_exit_code(1)
Expand All @@ -32,7 +32,7 @@ fn witness_and_transaction_conflict() {
CommandBuilder::new([
"verify",
"--address", "bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l",
"--message", "Hello World",
"--text", "Hello World",
"--transaction", "asdf",
"--witness", "AkcwRAIgZRfIY3p7/DoVTty6YZbWS71bc5Vct9p9Fia83eRmw2QCICK/ENGfwLtptFluMGs2KsqoNSk89pO7F29zJLUx9a/sASECx/EgAxlkQpQ9hYjgGu6EBCPMVPwVIVJqO4XCsMvViHI="
])
Expand All @@ -55,7 +55,7 @@ fn verify_with_transaction() {
"verify",
"--address",
"bc1q9vza2e8x573nczrlzms0wvx3gsqjx7vavgkx0l",
"--message",
"--text",
"Hello World",
"--transaction",
&tx,
Expand Down
16 changes: 9 additions & 7 deletions tests/wallet/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn sign() {
let text = "HelloWorld";

let sign = CommandBuilder::new(format!(
"wallet sign --address {} --text {text}",
"wallet sign --sign-with {} --text {text}",
address.clone().assume_checked(),
))
.core(&core)
Expand Down Expand Up @@ -60,7 +60,7 @@ fn sign_file() {
let address = addresses.first_key_value().unwrap().0;

let sign = CommandBuilder::new(format!(
"wallet sign --address {} --file hello.txt",
"wallet sign --sign-with {} --file hello.txt",
address.clone().assume_checked(),
))
.write("hello.txt", "Hello World")
Expand Down Expand Up @@ -112,10 +112,12 @@ fn sign_for_inscription() {

let text = "HelloWorld";

let sign = CommandBuilder::new(format!("wallet sign --signer {inscription} --text {text}",))
.core(&core)
.ord(&ord)
.run_and_deserialize_output::<SignOutput>();
let sign = CommandBuilder::new(format!(
"wallet sign --sign-with {inscription} --text {text}",
))
.core(&core)
.ord(&ord)
.run_and_deserialize_output::<SignOutput>();

assert!(addresses.contains_key(&sign.address));
}
Expand All @@ -139,7 +141,7 @@ fn sign_for_output() {

let text = "HelloWorld";

let sign = CommandBuilder::new(format!("wallet sign --output {output} --text {text}",))
let sign = CommandBuilder::new(format!("wallet sign --sign-with {output} --text {text}",))
.core(&core)
.ord(&ord)
.run_and_deserialize_output::<SignOutput>();
Expand Down

0 comments on commit 8fa9cb7

Please sign in to comment.