aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cmd.rs14
-rw-r--r--src/cmd/address.rs6
-rw-r--r--src/cmd/export.rs6
-rw-r--r--src/cmd/hash.rs6
-rw-r--r--src/cmd/hex.rs12
-rw-r--r--src/cmd/new.rs8
-rw-r--r--src/cmd/public_key.rs6
-rw-r--r--src/cmd/sign.rs24
-rw-r--r--src/main.rs22
9 files changed, 52 insertions, 52 deletions
diff --git a/src/cmd.rs b/src/cmd.rs
index 918ac84..7dca231 100644
--- a/src/cmd.rs
+++ b/src/cmd.rs
@@ -9,34 +9,34 @@ pub mod public_key;
pub mod sign;
use anyhow::Result;
+use clap::Parser;
use hdwallet::{account::PrivateKey, hdk, mnemonic::Mnemonic};
use std::{
fs,
io::{self, Read as _},
path::Path,
};
-use structopt::StructOpt;
/// Shared account options.
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
struct AccountOptions {
/// The BIP-0039 mnemonic phrase for seeding the HD wallet.
- #[structopt(short, long, env)]
+ #[clap(short, long, env, hide_env_values = true)]
mnemonic: Mnemonic,
/// The password to use with the mnemonic phrase for salting the seed used
/// for the HD wallet.
- #[structopt(long, env, default_value)]
+ #[clap(long, env, hide_env_values = true, default_value_t)]
password: String,
/// The BIP-44 account index for deriving a private from the mnemonic seed
/// phrase. The derived key will use the path "m/44'/60'/0'/0/{index}".
- #[structopt(long, env, default_value = "0")]
+ #[clap(long, env, default_value_t = 0)]
account_index: usize,
/// Manually specified HD path for deriving the account key. This option can
/// not be used in conjunction with the "--account-index" option.
- #[structopt(long, env, conflicts_with = "account-index")]
+ #[clap(long, env, conflicts_with = "account-index")]
hd_path: Option<String>,
}
@@ -58,7 +58,7 @@ fn permissive_hex(s: &str) -> Result<Box<[u8]>> {
let hex_string = trimmed.strip_prefix("0x").unwrap_or(&trimmed);
let bytes = ::hex::decode(&hex_string)?;
// NOTE: Use a boxed slice instead of a `Vec` as the former has special
- // scemantics with `structopt`.
+ // scemantics with `clap`.
Ok(bytes.into_boxed_slice())
}
diff --git a/src/cmd/address.rs b/src/cmd/address.rs
index 91476d3..28ed8fd 100644
--- a/src/cmd/address.rs
+++ b/src/cmd/address.rs
@@ -3,11 +3,11 @@
use crate::cmd::AccountOptions;
use anyhow::Result;
-use structopt::StructOpt;
+use clap::Parser;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
- #[structopt(flatten)]
+ #[clap(flatten)]
account: AccountOptions,
}
diff --git a/src/cmd/export.rs b/src/cmd/export.rs
index 957cd0e..df11d08 100644
--- a/src/cmd/export.rs
+++ b/src/cmd/export.rs
@@ -3,11 +3,11 @@
use crate::cmd::AccountOptions;
use anyhow::Result;
-use structopt::StructOpt;
+use clap::Parser;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
- #[structopt(flatten)]
+ #[clap(flatten)]
account: AccountOptions,
}
diff --git a/src/cmd/hash.rs b/src/cmd/hash.rs
index 4a650ff..4c8a9b8 100644
--- a/src/cmd/hash.rs
+++ b/src/cmd/hash.rs
@@ -2,14 +2,14 @@
use crate::cmd;
use anyhow::Result;
+use clap::Parser;
use hdwallet::hash;
use std::path::PathBuf;
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
/// Path to the data to hash. Use `-` for standard in.
- #[structopt(name = "DATA", default_value = "-")]
+ #[clap(name = "DATA", default_value = "-")]
data: PathBuf,
}
diff --git a/src/cmd/hex.rs b/src/cmd/hex.rs
index 48eb02f..143bc43 100644
--- a/src/cmd/hex.rs
+++ b/src/cmd/hex.rs
@@ -6,32 +6,32 @@
use crate::cmd;
use anyhow::Result;
+use clap::Parser;
use std::{
io::{self, Write},
path::PathBuf,
str,
};
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
- #[structopt(subcommand)]
+ #[clap(subcommand)]
op: Op,
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
enum Op {
/// Encode binary data as a hexadecimal string.
Encode {
/// Path to the data to encode. Use `-` for standard in.
- #[structopt(name = "DATA", default_value = "-")]
+ #[clap(name = "DATA", default_value = "-")]
data: PathBuf,
},
/// Decode a hexadecimal string as binary data.
Decode {
/// Path to the data to decode. Use `-` for standard in.
- #[structopt(name = "DATA", default_value = "-")]
+ #[clap(name = "DATA", default_value = "-")]
data: PathBuf,
},
}
diff --git a/src/cmd/new.rs b/src/cmd/new.rs
index 002e5d0..db89958 100644
--- a/src/cmd/new.rs
+++ b/src/cmd/new.rs
@@ -2,17 +2,17 @@
//! hierarchical deterministic wallet.
use anyhow::Result;
+use clap::Parser;
use hdwallet::mnemonic::{Language, Mnemonic};
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
/// The number of words for the mnemonic phrase.
- #[structopt(short = "n", long, default_value = "12")]
+ #[clap(short = 'n', long, default_value_t = 12)]
length: usize,
/// The language to generate the mnemonic for.
- #[structopt(short, long, default_value)]
+ #[clap(short, long, default_value_t)]
language: Language,
}
diff --git a/src/cmd/public_key.rs b/src/cmd/public_key.rs
index 31e5d0a..360255b 100644
--- a/src/cmd/public_key.rs
+++ b/src/cmd/public_key.rs
@@ -3,11 +3,11 @@
use crate::cmd::AccountOptions;
use anyhow::Result;
-use structopt::StructOpt;
+use clap::Parser;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
- #[structopt(flatten)]
+ #[clap(flatten)]
account: AccountOptions,
}
diff --git a/src/cmd/sign.rs b/src/cmd/sign.rs
index f292f0d..f0a7c89 100644
--- a/src/cmd/sign.rs
+++ b/src/cmd/sign.rs
@@ -2,40 +2,40 @@
use crate::cmd::{self, AccountOptions};
use anyhow::{ensure, Context as _, Result};
+use clap::Parser;
use hdwallet::{
hash,
transaction::{LegacyTransaction, Transaction},
typeddata::TypedData,
};
use std::{convert::TryInto, path::PathBuf};
-use structopt::StructOpt;
-#[derive(Debug, StructOpt)]
+#[derive(Debug, Parser)]
pub struct Options {
- #[structopt(subcommand)]
+ #[clap(subcommand)]
input: Input,
- #[structopt(flatten)]
+ #[clap(flatten)]
account: AccountOptions,
}
-#[derive(Debug, StructOpt)]
-#[structopt(rename_all = "lowercase")]
+#[derive(Debug, Parser)]
+#[clap(rename_all = "lowercase")]
enum Input {
/// Sign an Ethereum transaction.
Transaction {
/// Path to transaction to sign in JSON format.
- #[structopt(name = "TRANSACTION")]
+ #[clap(name = "TRANSACTION")]
transaction: PathBuf,
/// Only output the transaction signature instead of the RLP-encoded
/// signed transaction.
- #[structopt(long)]
+ #[clap(long)]
signature_only: bool,
/// Force allowing legacy transactions without a chain ID for relay
/// protection. Use this care!
- #[structopt(long)]
+ #[clap(long)]
allow_missing_relay_protection: bool,
},
@@ -44,21 +44,21 @@ enum Input {
/// Path to the message to sign in the "eth_sign" scheme. This message
/// will be prefixed with "\x19Ethereum Signed Message:\n" and its
/// length before hashing and singing.
- #[structopt(name = "MESSAGE")]
+ #[clap(name = "MESSAGE")]
message: PathBuf,
},
/// Sign EIP-712 typed data.
TypedData {
/// Path to the EIP-712 typed data in JSON format.
- #[structopt(name = "TYPEDDATA")]
+ #[clap(name = "TYPEDDATA")]
typed_data: PathBuf,
},
/// Sign a raw data.
Raw {
/// The 32 byte message to sign specified as a hexadecimal string.
- #[structopt(name = "BYTES", parse(try_from_str = permissive_hex_digest))]
+ #[clap(name = "BYTES", parse(try_from_str = permissive_hex_digest))]
message: [u8; 32],
},
}
diff --git a/src/main.rs b/src/main.rs
index 211cfb1..2c80f57 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,33 +1,33 @@
mod cmd;
+use clap::Parser;
use std::process;
-use structopt::StructOpt;
#[allow(clippy::large_enum_variant)]
-#[derive(Debug, StructOpt)]
-#[structopt(
+#[derive(Debug, Parser)]
+#[clap(
name = "hdwallet",
about = "Hierarchical deterministic wallet for Ethereum"
)]
enum Options {
- #[structopt(about = "Print account public address")]
+ #[clap(about = "Print account public address")]
Address(cmd::address::Options),
- #[structopt(about = "Export a private key")]
+ #[clap(about = "Export a private key")]
Export(cmd::export::Options),
- #[structopt(about = "Keccak256 hash data")]
+ #[clap(about = "Keccak256 hash data")]
Hash(cmd::hash::Options),
- #[structopt(about = "Hex encoding and decoding")]
+ #[clap(about = "Hex encoding and decoding")]
Hex(cmd::hex::Options),
- #[structopt(about = "Generate a new HD wallet mnemonic")]
+ #[clap(about = "Generate a new HD wallet mnemonic")]
New(cmd::new::Options),
- #[structopt(about = "Export the public key for an account")]
+ #[clap(about = "Export the public key for an account")]
PublicKey(cmd::public_key::Options),
- #[structopt(about = "Sign a message")]
+ #[clap(about = "Sign a message")]
Sign(cmd::sign::Options),
}
fn main() {
- if let Err(err) = match Options::from_args() {
+ if let Err(err) = match Options::parse() {
Options::Address(options) => cmd::address::run(options),
Options::Export(options) => cmd::export::run(options),
Options::Hash(options) => cmd::hash::run(options),