refactor: define trait HashOutput for some Hash associate type (#14220)

* define trait `HashOutput`

* improve

* improve

* Update primitives/runtime/src/traits.rs

Co-authored-by: Bastian Köcher <git@kchr.de>

* remove `Block::Hash: Ord`

* fmt

* add `MaybeFromStr`

* cleanup

* fix

* remove useless `HashOutput`

---------

Co-authored-by: Bastian Köcher <git@kchr.de>
This commit is contained in:
yjh
2023-06-08 10:02:13 +08:00
committed by GitHub
parent c31c6a1a73
commit ddb46a8aa0
19 changed files with 85 additions and 146 deletions
@@ -41,7 +41,7 @@ pub(crate) async fn create_snapshot<Block, HostFns>(
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr + serde::de::DeserializeOwned,
Block::Hash: serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
@@ -68,7 +68,6 @@ pub struct ExecuteBlockCmd {
impl ExecuteBlockCmd {
fn block_ws_uri<Block: BlockT>(&self) -> String
where
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
{
match (&self.block_ws_uri, &self.state) {
@@ -91,7 +90,6 @@ pub(crate) async fn execute_block<Block, HostFns>(
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
Block::Hash: serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
@@ -211,7 +211,6 @@ pub(crate) async fn fast_forward<Block, HostFns, BBIP>(
) -> Result<()>
where
Block: BlockT<Hash = H256> + DeserializeOwned,
Block::Hash: FromStr,
Block::Header: DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
@@ -84,7 +84,6 @@ pub(crate) async fn follow_chain<Block, HostFns>(
) -> sc_cli::Result<()>
where
Block: BlockT<Hash = H256> + DeserializeOwned,
Block::Hash: FromStr,
Block::Header: DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
@@ -46,7 +46,6 @@ pub struct OffchainWorkerCmd {
impl OffchainWorkerCmd {
fn header_ws_uri<Block: BlockT>(&self) -> String
where
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
{
match (&self.header_ws_uri, &self.state) {
@@ -70,7 +69,6 @@ pub(crate) async fn offchain_worker<Block, HostFns>(
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Header: serde::de::DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
NumberFor<Block>: FromStr,
<NumberFor<Block> as FromStr>::Err: Debug,
@@ -54,7 +54,6 @@ pub(crate) async fn on_runtime_upgrade<Block, HostFns>(
) -> sc_cli::Result<()>
where
Block: BlockT + serde::de::DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
Block::Header: serde::de::DeserializeOwned,
NumberFor<Block>: FromStr,
@@ -618,9 +618,7 @@ impl State {
try_runtime_check: bool,
) -> sc_cli::Result<RemoteExternalities<Block>>
where
Block::Hash: FromStr,
Block::Header: DeserializeOwned,
Block::Hash: DeserializeOwned,
<Block::Hash as FromStr>::Err: Debug,
{
let builder = match self {
@@ -732,7 +730,6 @@ impl TryRuntimeCmd {
where
Block: BlockT<Hash = H256> + DeserializeOwned,
Block::Header: DeserializeOwned,
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
<NumberFor<Block> as FromStr>::Err: Debug,
<NumberFor<Block> as TryInto<u64>>::Error: Debug,
@@ -798,7 +795,6 @@ impl CliConfiguration for TryRuntimeCmd {
/// Get the hash type of the generic `Block` from a `hash_str`.
pub(crate) fn hash_of<Block: BlockT>(hash_str: &str) -> sc_cli::Result<Block::Hash>
where
Block::Hash: FromStr,
<Block::Hash as FromStr>::Err: Debug,
{
hash_str