Skip to content
Snippets Groups Projects
Commit 496128d5 authored by Éloïs's avatar Éloïs
Browse files

feat(cli): add subcommand utils storage-key-prefix

parent e01bc04b
No related branches found
No related tags found
1 merge request!28Smiths sub-wot
......@@ -1268,6 +1268,7 @@ dependencies = [
"sp-consensus-babe",
"sp-core",
"sp-finality-grandpa",
"sp-io",
"sp-keyring",
"sp-keystore",
"sp-membership",
......
......@@ -84,6 +84,7 @@ sp-consensus = { git = "https://github.com/librelois/substrate.git", branch = "d
sp-consensus-babe = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-core = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-finality-grandpa = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-io = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-offchain = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-keyring = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
sp-keystore = { git = "https://github.com/librelois/substrate.git", branch = "duniter-monthly-2022-01" }
......
......@@ -15,6 +15,7 @@
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
pub mod key;
pub mod utils;
use sc_cli::RunCmd;
use std::str::FromStr;
......@@ -60,6 +61,9 @@ pub enum Subcommand {
/// Revert the chain to a previous state.
Revert(sc_cli::RevertCmd),
/// Some tools for developers and advanced testers
Utils(utils::UtilsSubCommand),
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
......
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use sc_cli::{Error, SubstrateCli};
use sp_io::hashing::twox_128;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub enum UtilsSubCommand {
/// Compute the raw storage key prefix
StorageKeyPrefix(StorageKeyPrefixCmd),
}
impl UtilsSubCommand {
/// Run the command
pub fn run<C: SubstrateCli>(&self, cli: &C) -> Result<(), Error> {
match self {
Self::StorageKeyPrefix(cmd) => cmd.run(cli),
}
}
}
#[derive(Debug, StructOpt)]
pub struct StorageKeyPrefixCmd {
/// Pallet name
#[structopt(short = "p", long)]
pallet_name: Option<String>,
/// Storage item name
#[structopt(short = "i", long)]
item_name: Option<String>,
}
impl StorageKeyPrefixCmd {
/// Run the command
pub fn run<C: SubstrateCli>(&self, _cli: &C) -> Result<(), Error> {
let mut key_prefix = Vec::new();
let mut print_key_prefix = false;
if let Some(ref pallet_name) = self.pallet_name {
print_key_prefix = true;
let pallet_prefix = twox_128(pallet_name.as_bytes());
println!("Pallet prefix: 0x{}", hex::encode(&pallet_prefix));
key_prefix.extend_from_slice(&pallet_prefix[..]);
}
if let Some(ref item_name) = self.item_name {
let item_prefix = twox_128(item_name.as_bytes());
println!("Item prefix: 0x{}", hex::encode(item_prefix));
key_prefix.extend_from_slice(&item_prefix[..]);
}
if print_key_prefix {
println!("Key prefix: 0x{}", hex::encode(key_prefix));
}
Ok(())
}
}
......@@ -147,6 +147,7 @@ pub fn run() -> sc_cli::Result<()> {
match &cli.subcommand {
Some(Subcommand::Key(cmd)) => cmd.run(&cli),
Some(Subcommand::Utils(cmd)) => cmd.run(&cli),
Some(Subcommand::BuildSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment