Clean up definition for custom ss58 address formats (#4470)

* Clearer definition for custom ss58 address formats

* Fix subkey compile
This commit is contained in:
Wei Tang
2019-12-21 06:34:36 -08:00
committed by Gavin Wood
parent 2c2e0d772d
commit c3413fdea3
4 changed files with 42 additions and 30 deletions
+22 -14
View File
@@ -22,6 +22,7 @@ use bip39::{Language, Mnemonic, MnemonicType};
use clap::{App, ArgMatches, SubCommand};
use codec::{Decode, Encode};
use hex_literal::hex;
use itertools::Itertools;
use node_primitives::{Balance, Hash, Index, AccountId, Signature};
use node_runtime::{BalancesCall, Call, Runtime, SignedPayload, UncheckedExtrinsic, VERSION};
use sp_core::{
@@ -155,20 +156,25 @@ impl PublicT for sr25519::Public { fn into_runtime(self) -> AccountPublic { self
impl PublicT for ed25519::Public { fn into_runtime(self) -> AccountPublic { self.into() } }
impl PublicT for ecdsa::Public { fn into_runtime(self) -> AccountPublic { self.into() } }
fn get_app<'a, 'b>() -> App<'a, 'b> {
fn get_usage() -> String {
let networks = Ss58AddressFormat::all().iter().cloned().map(String::from).join("/");
let default_network = String::from(Ss58AddressFormat::default());
format!("
-e, --ed25519 'Use Ed25519/BIP39 cryptography'
-k, --secp256k1 'Use SECP256k1/ECDSA/BIP39 cryptography'
-s, --sr25519 'Use Schnorr/Ristretto x25519/BIP39 cryptography'
[network] -n, --network <network> 'Specify a network. One of {}. Default is {}'
[password] -p, --password <password> 'The password for the key'
--password-interactive 'You will be prompted for the password for the key.'
", networks, default_network)
}
fn get_app<'a, 'b>(usage: &'a str) -> App<'a, 'b> {
App::new("subkey")
.author("Parity Team <admin@parity.io>")
.about("Utility for generating and restoring with Substrate keys")
.version(env!("CARGO_PKG_VERSION"))
.args_from_usage("
-e, --ed25519 'Use Ed25519/BIP39 cryptography'
-k, --secp256k1 'Use SECP256k1/ECDSA/BIP39 cryptography'
-s, --sr25519 'Use Schnorr/Ristretto x25519/BIP39 cryptography'
[network] -n, --network <network> 'Specify a network. One of substrate \
(default), polkadot, kusama, dothereum, edgeware, or kulupu'
[password] -p, --password <password> 'The password for the key'
--password-interactive 'You will be prompted for the password for the key.'
")
.args_from_usage(usage)
.subcommands(vec![
SubCommand::with_name("generate")
.about("Generate a random account")
@@ -226,7 +232,8 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
}
fn main() {
let matches = get_app().get_matches();
let usage = get_usage();
let matches = get_app(&usage).get_matches();
if matches.is_present("ed25519") {
return execute::<Ed25519>(matches)
@@ -260,7 +267,7 @@ where
let maybe_network: Option<Ss58AddressFormat> = matches.value_of("network").map(|network| {
network
.try_into()
.expect("Invalid network name: must be polkadot/substrate/kusama/dothereum/edgeware")
.expect("Invalid network name. See --help for available networks.")
});
if let Some(network) = maybe_network {
set_default_ss58_version(network);
@@ -553,7 +560,8 @@ mod tests {
SignatureOf<CryptoType>: SignatureT,
PublicOf<CryptoType>: PublicT,
{
let app = get_app();
let usage = get_usage();
let app = get_app(&usage);
let password = None;
// Generate public key and seed.
@@ -581,7 +589,7 @@ mod tests {
// Verify the previous signature.
let arg_vec = vec!["subkey", "verify", &signature[..], &public_key[..]];
let matches = get_app().get_matches_from(arg_vec);
let matches = get_app(&usage).get_matches_from(arg_vec);
let matches = matches.subcommand().1.unwrap();
assert!(do_verify::<CryptoType>(matches, message));
}