mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
test-utils: add chain-spec-builder cli (#1061)
* test-utils: add chain-spec-builder cli * style changes, mostly indentation * fix padding * add issue to todo * more style fixes * share seed padding with keystore * fix master rebase error
This commit is contained in:
@@ -131,6 +131,24 @@ pub struct Store {
|
||||
additional: HashMap<Public, Seed>,
|
||||
}
|
||||
|
||||
pub fn pad_seed(seed: &str) -> Seed {
|
||||
let mut s: [u8; 32] = [' ' as u8; 32];
|
||||
|
||||
let was_hex = if seed.len() == 66 && &seed[0..2] == "0x" {
|
||||
if let Ok(d) = hex::decode(&seed[2..]) {
|
||||
s.copy_from_slice(&d);
|
||||
true
|
||||
} else { false }
|
||||
} else { false };
|
||||
|
||||
if !was_hex {
|
||||
let len = ::std::cmp::min(32, seed.len());
|
||||
&mut s[..len].copy_from_slice(&seed.as_bytes()[..len]);
|
||||
}
|
||||
|
||||
s
|
||||
}
|
||||
|
||||
impl Store {
|
||||
/// Create a new store at the given path.
|
||||
pub fn open(path: PathBuf) -> Result<Self> {
|
||||
@@ -153,24 +171,11 @@ impl Store {
|
||||
|
||||
/// Create a new key from seed. Do not place it into the store.
|
||||
/// Only the first 32 bytes of the sead are used. This is meant to be used for testing only.
|
||||
// TODO: Remove this
|
||||
// FIXME: remove this - https://github.com/paritytech/substrate/issues/1063
|
||||
pub fn generate_from_seed(&mut self, seed: &str) -> Result<Pair> {
|
||||
let mut s: [u8; 32] = [' ' as u8; 32];
|
||||
|
||||
let was_hex = if seed.len() == 66 && &seed[0..2] == "0x" {
|
||||
if let Ok(d) = hex::decode(&seed[2..]) {
|
||||
s.copy_from_slice(&d);
|
||||
true
|
||||
} else { false }
|
||||
} else { false };
|
||||
|
||||
if !was_hex {
|
||||
let len = ::std::cmp::min(32, seed.len());
|
||||
&mut s[..len].copy_from_slice(&seed.as_bytes()[..len]);
|
||||
}
|
||||
|
||||
let pair = Pair::from_seed(&s);
|
||||
self.additional.insert(pair.public(), s);
|
||||
let padded_seed = pad_seed(seed);
|
||||
let pair = Pair::from_seed(&padded_seed);
|
||||
self.additional.insert(pair.public(), padded_seed);
|
||||
Ok(pair)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user