mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-15 20:51:05 +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)
|
Self::from_ss58check_with_version(s)
|
||||||
.and_then(|(r, v)| match v {
|
.and_then(|(r, v)| match v {
|
||||||
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::PolkadotAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::KusamaAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::DothereumAccountDirect => Ok(r),
|
||||||
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
||||||
_ => Err(PublicError::UnknownVersion),
|
_ => Err(PublicError::UnknownVersion),
|
||||||
})
|
})
|
||||||
@@ -273,6 +276,9 @@ pub trait Ss58Codec: Sized {
|
|||||||
Self::from_string_with_version(s)
|
Self::from_string_with_version(s)
|
||||||
.and_then(|(r, v)| match v {
|
.and_then(|(r, v)| match v {
|
||||||
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
Ss58AddressFormat::SubstrateAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::PolkadotAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::KusamaAccountDirect => Ok(r),
|
||||||
|
Ss58AddressFormat::DothereumAccountDirect => Ok(r),
|
||||||
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
v if v == *DEFAULT_VERSION.lock() => Ok(r),
|
||||||
_ => Err(PublicError::UnknownVersion),
|
_ => Err(PublicError::UnknownVersion),
|
||||||
})
|
})
|
||||||
@@ -327,6 +333,8 @@ pub enum Ss58AddressFormat {
|
|||||||
PolkadotAccountDirect,
|
PolkadotAccountDirect,
|
||||||
/// Kusama Relay-chain, direct checksum, standard account (*25519).
|
/// Kusama Relay-chain, direct checksum, standard account (*25519).
|
||||||
KusamaAccountDirect,
|
KusamaAccountDirect,
|
||||||
|
/// Dothereum Para-chain, direct checksum, standard account (*25519).
|
||||||
|
DothereumAccountDirect,
|
||||||
/// Use a manually provided numeric value.
|
/// Use a manually provided numeric value.
|
||||||
Custom(u8),
|
Custom(u8),
|
||||||
}
|
}
|
||||||
@@ -338,6 +346,7 @@ impl From<Ss58AddressFormat> for u8 {
|
|||||||
Ss58AddressFormat::SubstrateAccountDirect => 42,
|
Ss58AddressFormat::SubstrateAccountDirect => 42,
|
||||||
Ss58AddressFormat::PolkadotAccountDirect => 0,
|
Ss58AddressFormat::PolkadotAccountDirect => 0,
|
||||||
Ss58AddressFormat::KusamaAccountDirect => 2,
|
Ss58AddressFormat::KusamaAccountDirect => 2,
|
||||||
|
Ss58AddressFormat::DothereumAccountDirect => 20,
|
||||||
Ss58AddressFormat::Custom(n) => n,
|
Ss58AddressFormat::Custom(n) => n,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -351,6 +360,7 @@ impl TryFrom<u8> for Ss58AddressFormat {
|
|||||||
42 => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
42 => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
||||||
0 => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
0 => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
||||||
2 => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
2 => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
||||||
|
20 => Ok(Ss58AddressFormat::DothereumAccountDirect),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -364,6 +374,7 @@ impl<'a> TryFrom<&'a str> for Ss58AddressFormat {
|
|||||||
"substrate" => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
"substrate" => Ok(Ss58AddressFormat::SubstrateAccountDirect),
|
||||||
"polkadot" => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
"polkadot" => Ok(Ss58AddressFormat::PolkadotAccountDirect),
|
||||||
"kusama" => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
"kusama" => Ok(Ss58AddressFormat::KusamaAccountDirect),
|
||||||
|
"dothereum" => Ok(Ss58AddressFormat::DothereumAccountDirect),
|
||||||
a => a.parse::<u8>().map(Ss58AddressFormat::Custom).map_err(|_| ()),
|
a => a.parse::<u8>().map(Ss58AddressFormat::Custom).map_err(|_| ()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,6 +387,7 @@ impl From<Ss58AddressFormat> for String {
|
|||||||
Ss58AddressFormat::SubstrateAccountDirect => "substrate".into(),
|
Ss58AddressFormat::SubstrateAccountDirect => "substrate".into(),
|
||||||
Ss58AddressFormat::PolkadotAccountDirect => "polkadot".into(),
|
Ss58AddressFormat::PolkadotAccountDirect => "polkadot".into(),
|
||||||
Ss58AddressFormat::KusamaAccountDirect => "kusama".into(),
|
Ss58AddressFormat::KusamaAccountDirect => "kusama".into(),
|
||||||
|
Ss58AddressFormat::DothereumAccountDirect => "dothereum".into(),
|
||||||
Ss58AddressFormat::Custom(x) => x.to_string(),
|
Ss58AddressFormat::Custom(x) => x.to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -387,7 +399,8 @@ impl From<Ss58AddressFormat> for String {
|
|||||||
///
|
///
|
||||||
/// Current known "versions" are:
|
/// Current known "versions" are:
|
||||||
/// - 0 direct (payload) checksum for 32-byte *25519 Polkadot addresses.
|
/// - 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.
|
/// - 42 direct (payload) checksum for 32-byte *25519 addresses on any Substrate-based network.
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn set_default_ss58_version(version: Ss58AddressFormat) {
|
pub fn set_default_ss58_version(version: Ss58AddressFormat) {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ args:
|
|||||||
long: network
|
long: network
|
||||||
takes_value: true
|
takes_value: true
|
||||||
required: false
|
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:
|
subcommands:
|
||||||
- generate:
|
- generate:
|
||||||
about: Generate a random account
|
about: Generate a random account
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ where
|
|||||||
let maybe_network: Option<Ss58AddressFormat> = matches.value_of("network").map(|network| {
|
let maybe_network: Option<Ss58AddressFormat> = matches.value_of("network").map(|network| {
|
||||||
network
|
network
|
||||||
.try_into()
|
.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 {
|
if let Some(network) = maybe_network {
|
||||||
set_default_ss58_version(network);
|
set_default_ss58_version(network);
|
||||||
|
|||||||
Reference in New Issue
Block a user