mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 06:57:58 +00:00
core, subkey: allow to read Polkadot, Kusama, and Dothereum address types (#3643)
* core/primitives: set dothereum address type to 4 * subkey: add dothereum to network prefix * core/primitives: set dothereum address type to 20 * core/primitives: update comment * core/primitives: set default address to Dothereum * Revert "core/primitives: set default address to Dothereum" This reverts commit 2fc95490c89390eb26f200cb314435b1e9ff83e8. * core/primitives: allow to parse different default address types
This commit is contained in:
@@ -261,6 +261,9 @@ pub trait Ss58Codec: Sized {
|
||||
Self::from_ss58check_with_version(s)
|
||||
.and_then(|(r, v)| match v {
|
||||
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::PolkadotAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::KusamaAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::DothereumAccountDirect => Ok(r),
|
||||
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
||||
_ => Err(PublicError::UnknownVersion),
|
||||
})
|
||||
@@ -273,6 +276,9 @@ pub trait Ss58Codec: Sized {
|
||||
Self::from_string_with_version(s)
|
||||
.and_then(|(r, v)| match v {
|
||||
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::PolkadotAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::KusamaAccountDirect => Ok(r),
|
||||
Ss58AddressFormat::DothereumAccountDirect => Ok(r),
|
||||
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
||||
_ => Err(PublicError::UnknownVersion),
|
||||
})
|
||||
@@ -327,6 +333,8 @@ pub enum Ss58AddressFormat {
|
||||
PolkadotAccountDirect,
|
||||
/// Kusama Relay-chain, direct checksum, standard account (*25519).
|
||||
KusamaAccountDirect,
|
||||
/// Dothereum Para-chain, direct checksum, standard account (*25519).
|
||||
DothereumAccountDirect,
|
||||
/// Use a manually provided numeric value.
|
||||
Custom(u8),
|
||||
}
|
||||
@@ -338,6 +346,7 @@ impl From<Ss58AddressFormat> for u8 {
|
||||
Ss58AddressFormat::SubstrateAccountDirect => 42,
|
||||
Ss58AddressFormat::PolkadotAccountDirect => 0,
|
||||
Ss58AddressFormat::KusamaAccountDirect => 2,
|
||||
Ss58AddressFormat::DothereumAccountDirect => 20,
|
||||
Ss58AddressFormat::Custom(n) => n,
|
||||
}
|
||||
}
|
||||
@@ -351,6 +360,7 @@ impl TryFrom<u8> for Ss58AddressFormat {
|
||||
42 => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
||||
0 => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
||||
2 => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
||||
20 => Ok(Ss58AddressFormat::DothereumAccountDirect),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
@@ -364,6 +374,7 @@ impl<'a> TryFrom<&'a str> for Ss58AddressFormat {
|
||||
"substrate" => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
||||
"polkadot" => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
||||
"kusama" => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
||||
"dothereum" => Ok(Ss58AddressFormat::DothereumAccountDirect),
|
||||
a => a.parse::<u8>().map(Ss58AddressFormat::Custom).map_err(|_| ()),
|
||||
}
|
||||
}
|
||||
@@ -376,6 +387,7 @@ impl From<Ss58AddressFormat> for String {
|
||||
Ss58AddressFormat::SubstrateAccountDirect => "substrate".into(),
|
||||
Ss58AddressFormat::PolkadotAccountDirect => "polkadot".into(),
|
||||
Ss58AddressFormat::KusamaAccountDirect => "kusama".into(),
|
||||
Ss58AddressFormat::DothereumAccountDirect => "dothereum".into(),
|
||||
Ss58AddressFormat::Custom(x) => x.to_string(),
|
||||
}
|
||||
}
|
||||
@@ -387,7 +399,8 @@ impl From<Ss58AddressFormat> for String {
|
||||
///
|
||||
/// Current known "versions" are:
|
||||
/// - 0 direct (payload) checksum for 32-byte *25519 Polkadot addresses.
|
||||
/// - 2 direct (payload) checksum for 32-byte *25519 Polkadot Milestone 'K' addresses.
|
||||
/// - 2 direct (payload) checksum for 32-byte *25519 Kusama addresses.
|
||||
/// - 20 direct (payload) checksum for 32-byte *25519 Dothereum addresses.
|
||||
/// - 42 direct (payload) checksum for 32-byte *25519 addresses on any Substrate-based network.
|
||||
#[cfg(feature = "std")]
|
||||
pub fn set_default_ss58_version(version: Ss58AddressFormat) {
|
||||
|
||||
@@ -23,7 +23,7 @@ args:
|
||||
long: network
|
||||
takes_value: true
|
||||
required: false
|
||||
help: Specify a network. One of substrate (default), polkadot and kusama.
|
||||
help: Specify a network. One of substrate (default), polkadot, kusama, or dothereum.
|
||||
subcommands:
|
||||
- generate:
|
||||
about: Generate a random account
|
||||
|
||||
@@ -140,7 +140,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")
|
||||
.expect("Invalid network name: must be polkadot/substrate/kusama/dothereum")
|
||||
});
|
||||
if let Some(network) = maybe_network {
|
||||
set_default_ss58_version(network);
|
||||
@@ -382,7 +382,7 @@ fn create_extrinsic(
|
||||
);
|
||||
let signature = raw_payload.using_encoded(|payload| signer.sign(payload));
|
||||
let (function, extra, _) = raw_payload.deconstruct();
|
||||
|
||||
|
||||
UncheckedExtrinsic::new_signed(
|
||||
function,
|
||||
signer.public().into(),
|
||||
|
||||
Reference in New Issue
Block a user