mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 14:41:11 +00:00
SS58 versioning (Network IDs) (#3147)
* Introduce network IDs for SS58 * Fix * Allow numeric overrides. * Improve docs * String rather than str * Comment out code that will become valid after other PR * Fix
This commit is contained in:
@@ -18,6 +18,12 @@ args:
|
||||
takes_value: true
|
||||
required: false
|
||||
help: The password for the key
|
||||
- network:
|
||||
short: n
|
||||
long: network
|
||||
takes_value: true
|
||||
required: false
|
||||
help: Specify a network. One of substrate (default), polkadot and kusama.
|
||||
subcommands:
|
||||
- generate:
|
||||
about: Generate a random account
|
||||
|
||||
@@ -18,15 +18,18 @@
|
||||
#[cfg(feature = "bench")]
|
||||
extern crate test;
|
||||
|
||||
use std::{str::FromStr, io::{stdin, Read}};
|
||||
use std::{str::FromStr, io::{stdin, Read}, convert::TryInto};
|
||||
use hex_literal::hex;
|
||||
use clap::load_yaml;
|
||||
use bip39::{Mnemonic, Language, MnemonicType};
|
||||
use substrate_primitives::{ed25519, sr25519, hexdisplay::HexDisplay, Pair, Public, crypto::Ss58Codec, blake2_256};
|
||||
use substrate_primitives::{
|
||||
ed25519, sr25519, hexdisplay::HexDisplay, Pair, Public,
|
||||
crypto::{Ss58Codec, set_default_ss58_version, Ss58AddressFormat}, blake2_256
|
||||
};
|
||||
use parity_codec::{Encode, Decode, Compact};
|
||||
use sr_primitives::generic::Era;
|
||||
use node_primitives::{Balance, Index, Hash};
|
||||
use node_runtime::{Call, UncheckedExtrinsic, BalancesCall};
|
||||
use node_runtime::{Call, UncheckedExtrinsic, /*CheckNonce, TakeFees, */BalancesCall};
|
||||
|
||||
mod vanity;
|
||||
|
||||
@@ -52,11 +55,12 @@ trait Crypto {
|
||||
HexDisplay::from(&Self::public_from_pair(&pair)),
|
||||
Self::ss58_from_pair(&pair)
|
||||
);
|
||||
} else if let Ok(public) = <Self::Pair as Pair>::Public::from_string(uri) {
|
||||
println!("Public Key URI `{}` is account:\n Public key (hex): 0x{}\n Address (SS58): {}",
|
||||
} else if let Ok((public, v)) = <Self::Pair as Pair>::Public::from_string_with_version(uri) {
|
||||
println!("Public Key URI `{}` is account:\n Network ID/version: {}\n Public key (hex): 0x{}\n Address (SS58): {}",
|
||||
uri,
|
||||
String::from(Ss58AddressFormat::from(v)),
|
||||
HexDisplay::from(&public.as_ref()),
|
||||
public.to_ss58check()
|
||||
public.to_ss58check_with_version(v)
|
||||
);
|
||||
} else {
|
||||
println!("Invalid phrase/URI given");
|
||||
@@ -87,6 +91,12 @@ fn execute<C: Crypto>(matches: clap::ArgMatches) where
|
||||
<<C as Crypto>::Pair as Pair>::Public: Sized + AsRef<[u8]> + Ss58Codec + AsRef<<<C as Crypto>::Pair as Pair>::Public>,
|
||||
{
|
||||
let password = matches.value_of("password");
|
||||
let maybe_network = matches.value_of("network");
|
||||
if let Some(network) = maybe_network {
|
||||
let v = network.try_into()
|
||||
.expect("Invalid network name: must be polkadot/substrate/kusama");
|
||||
set_default_ss58_version(v);
|
||||
}
|
||||
match matches.subcommand() {
|
||||
("generate", Some(matches)) => {
|
||||
// create a new randomly generated mnemonic phrase
|
||||
@@ -120,7 +130,7 @@ fn execute<C: Crypto>(matches: clap::ArgMatches) where
|
||||
let sig = pair.sign(&message);
|
||||
println!("{}", hex::encode(&sig));
|
||||
}
|
||||
("transfer", Some(matches)) => {
|
||||
/*("transfer", Some(matches)) => {
|
||||
let signer = matches.value_of("from")
|
||||
.expect("parameter is required; thus it can't be None; qed");
|
||||
let signer = Sr25519::pair_from_suri(signer, password);
|
||||
@@ -147,7 +157,7 @@ fn execute<C: Crypto>(matches: clap::ArgMatches) where
|
||||
"elm" => hex!["10c08714a10c7da78f40a60f6f732cf0dba97acfb5e2035445b032386157d5c3"].into(),
|
||||
"alex" => hex!["dcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b"].into(),
|
||||
h => hex::decode(h).ok().and_then(|x| Decode::decode(&mut &x[..]))
|
||||
.expect("Invalid genesis hash or unrecognised chain identifier"),
|
||||
.expect("Invalid genesis hash or unrecognised chain identifier"),
|
||||
};
|
||||
|
||||
println!("Using a genesis hash of {}", HexDisplay::from(&genesis_hash.as_ref()));
|
||||
@@ -161,11 +171,11 @@ fn execute<C: Crypto>(matches: clap::ArgMatches) where
|
||||
signer.sign(payload)
|
||||
});
|
||||
let extrinsic = UncheckedExtrinsic::new_signed(
|
||||
index,
|
||||
raw_payload.1,
|
||||
signer.public().into(),
|
||||
signature.into(),
|
||||
era,
|
||||
(CheckNonce(index), TakeFees(0)),
|
||||
);
|
||||
println!("0x{}", hex::encode(&extrinsic.encode()));
|
||||
}
|
||||
@@ -202,15 +212,15 @@ fn execute<C: Crypto>(matches: clap::ArgMatches) where
|
||||
);
|
||||
|
||||
let extrinsic = UncheckedExtrinsic::new_signed(
|
||||
index,
|
||||
raw_payload.1,
|
||||
signer.public().into(),
|
||||
signature.into(),
|
||||
era,
|
||||
(CheckNonce(index), TakeFees(0)),
|
||||
);
|
||||
|
||||
println!("0x{}", hex::encode(&extrinsic.encode()));
|
||||
}
|
||||
}*/
|
||||
("verify", Some(matches)) => {
|
||||
let sig_data = matches.value_of("sig")
|
||||
.expect("signature parameter is required; thus it can't be None; qed");
|
||||
|
||||
Reference in New Issue
Block a user