mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-19 22:51:03 +00:00
Fix generate node name with less then 32 characters (#1596)
* fix generate node name with less then 32 characters * refactor generate_node_name
This commit is contained in:
@@ -60,6 +60,8 @@ use lazy_static::lazy_static;
|
|||||||
|
|
||||||
use futures::Future;
|
use futures::Future;
|
||||||
|
|
||||||
|
const MAX_NODE_NAME_LENGTH: usize = 32;
|
||||||
|
|
||||||
/// Executable version. Used to pass version information from the root crate.
|
/// Executable version. Used to pass version information from the root crate.
|
||||||
pub struct VersionInfo {
|
pub struct VersionInfo {
|
||||||
/// Implemtation name.
|
/// Implemtation name.
|
||||||
@@ -91,6 +93,19 @@ fn get_chain_key(cli: &SharedParams) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn generate_node_name() -> String {
|
||||||
|
let result = loop {
|
||||||
|
let node_name = Generator::with_naming(Name::Numbered).next().unwrap();
|
||||||
|
let count = node_name.chars().count();
|
||||||
|
|
||||||
|
if count < MAX_NODE_NAME_LENGTH {
|
||||||
|
break node_name
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
fn load_spec<F, G>(cli: &SharedParams, factory: F) -> error::Result<ChainSpec<G>>
|
fn load_spec<F, G>(cli: &SharedParams, factory: F) -> error::Result<ChainSpec<G>>
|
||||||
where G: RuntimeGenesis, F: FnOnce(&str) -> Result<Option<ChainSpec<G>>, String>,
|
where G: RuntimeGenesis, F: FnOnce(&str) -> Result<Option<ChainSpec<G>>, String>,
|
||||||
{
|
{
|
||||||
@@ -121,7 +136,6 @@ fn create_input_err<T: Into<String>>(msg: T) -> error::Error {
|
|||||||
|
|
||||||
/// Check whether a node name is considered as valid
|
/// Check whether a node name is considered as valid
|
||||||
fn is_node_name_valid(_name: &str) -> Result<(), &str> {
|
fn is_node_name_valid(_name: &str) -> Result<(), &str> {
|
||||||
const MAX_NODE_NAME_LENGTH: usize = 32;
|
|
||||||
let name = _name.to_string();
|
let name = _name.to_string();
|
||||||
if name.chars().count() >= MAX_NODE_NAME_LENGTH {
|
if name.chars().count() >= MAX_NODE_NAME_LENGTH {
|
||||||
return Err("Node name too long");
|
return Err("Node name too long");
|
||||||
@@ -284,7 +298,7 @@ where
|
|||||||
config.impl_version = version.version;
|
config.impl_version = version.version;
|
||||||
|
|
||||||
config.name = match cli.name {
|
config.name = match cli.name {
|
||||||
None => Generator::with_naming(Name::Numbered).next().unwrap(),
|
None => generate_node_name(),
|
||||||
Some(name) => name,
|
Some(name) => name,
|
||||||
};
|
};
|
||||||
match is_node_name_valid(&config.name) {
|
match is_node_name_valid(&config.name) {
|
||||||
|
|||||||
Reference in New Issue
Block a user