CLI: Make derived address seed.len() check a clap validator
This commit is contained in:
committed by
mergify[bot]
parent
84e7ba0b3f
commit
16e0a4b412
@ -3,7 +3,7 @@ use chrono::DateTime;
|
|||||||
use solana_sdk::{
|
use solana_sdk::{
|
||||||
clock::{Epoch, Slot},
|
clock::{Epoch, Slot},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
pubkey::Pubkey,
|
pubkey::{Pubkey, MAX_SEED_LEN},
|
||||||
signature::{read_keypair_file, Signature},
|
signature::{read_keypair_file, Signature},
|
||||||
};
|
};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
@ -291,6 +291,21 @@ where
|
|||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn is_derived_address_seed<T>(value: T) -> Result<(), String>
|
||||||
|
where
|
||||||
|
T: AsRef<str> + Display,
|
||||||
|
{
|
||||||
|
let value = value.as_ref();
|
||||||
|
if value.len() > MAX_SEED_LEN {
|
||||||
|
Err(format!(
|
||||||
|
"Address seed must not be longer than {} bytes",
|
||||||
|
MAX_SEED_LEN
|
||||||
|
))
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -40,7 +40,7 @@ use solana_sdk::{
|
|||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::InstructionError,
|
instruction::InstructionError,
|
||||||
message::Message,
|
message::Message,
|
||||||
pubkey::{Pubkey, MAX_SEED_LEN},
|
pubkey::Pubkey,
|
||||||
signature::{Signature, Signer, SignerError},
|
signature::{Signature, Signer, SignerError},
|
||||||
system_instruction::{self, SystemError},
|
system_instruction::{self, SystemError},
|
||||||
system_program,
|
system_program,
|
||||||
@ -923,12 +923,6 @@ pub fn parse_create_address_with_seed(
|
|||||||
|
|
||||||
let seed = matches.value_of("seed").unwrap().to_string();
|
let seed = matches.value_of("seed").unwrap().to_string();
|
||||||
|
|
||||||
if seed.len() > MAX_SEED_LEN {
|
|
||||||
return Err(CliError::BadParameter(
|
|
||||||
"Address seed must not be longer than 32 bytes".to_string(),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(CliCommandInfo {
|
Ok(CliCommandInfo {
|
||||||
command: CliCommand::CreateAddressWithSeed {
|
command: CliCommand::CreateAddressWithSeed {
|
||||||
from_pubkey,
|
from_pubkey,
|
||||||
@ -1971,6 +1965,7 @@ pub fn app<'ab, 'v>(name: &str, about: &'ab str, version: &'v str) -> App<'ab, '
|
|||||||
.value_name("SEED_STRING")
|
.value_name("SEED_STRING")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.required(true)
|
.required(true)
|
||||||
|
.validator(is_derived_address_seed)
|
||||||
.help("The seed. Must not take more than 32 bytes to encode as utf-8"),
|
.help("The seed. Must not take more than 32 bytes to encode as utf-8"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
|
Reference in New Issue
Block a user