improve --address flag on user_create
This commit is contained in:
parent
a3bba43360
commit
7da8864a1d
@ -13,8 +13,10 @@ use web3_proxy::frontend::authorization::UserKey;
|
|||||||
#[argh(subcommand, name = "create_user")]
|
#[argh(subcommand, name = "create_user")]
|
||||||
pub struct CreateUserSubCommand {
|
pub struct CreateUserSubCommand {
|
||||||
#[argh(option)]
|
#[argh(option)]
|
||||||
/// the user's ethereum address.
|
/// the user's ethereum address or descriptive string.
|
||||||
address: Address,
|
/// If a string is given, it will be converted to hex and potentially truncated.
|
||||||
|
/// Users from strings are only for testing since they won't be able to log in.
|
||||||
|
address: String,
|
||||||
|
|
||||||
#[argh(option)]
|
#[argh(option)]
|
||||||
/// the user's optional email.
|
/// the user's optional email.
|
||||||
@ -36,9 +38,23 @@ impl CreateUserSubCommand {
|
|||||||
let txn = db.begin().await?;
|
let txn = db.begin().await?;
|
||||||
|
|
||||||
// TODO: would be nice to use the fixed array instead of a Vec in the entities
|
// TODO: would be nice to use the fixed array instead of a Vec in the entities
|
||||||
// TODO: how can we use custom types with
|
// take a simple String. If it starts with 0x, parse as address. otherwise convert ascii to hex
|
||||||
// TODO: take a simple String. If it starts with 0x, parse as address. otherwise convert ascii to hex
|
// TODO: there has to be a cleaner way to convert a String to a [u8; 20]
|
||||||
let address = self.address.to_fixed_bytes().into();
|
let address = if self.address.starts_with("0x") {
|
||||||
|
let address = self.address.parse::<Address>()?;
|
||||||
|
|
||||||
|
address.to_fixed_bytes().into()
|
||||||
|
} else {
|
||||||
|
let bytes = self.address.as_bytes();
|
||||||
|
|
||||||
|
let mut address: [u8; 20] = [0; 20];
|
||||||
|
|
||||||
|
let len = 20.min(bytes.len());
|
||||||
|
|
||||||
|
address[..len].copy_from_slice(&bytes[..len]);
|
||||||
|
|
||||||
|
address.into()
|
||||||
|
};
|
||||||
|
|
||||||
// TODO: get existing or create a new one
|
// TODO: get existing or create a new one
|
||||||
let u = user::ActiveModel {
|
let u = user::ActiveModel {
|
||||||
|
Loading…
Reference in New Issue
Block a user