mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-30 21:01:02 +00:00
Move Chain trait to runtime primitives (#403)
* extract ChainBase to bp-runtime * post-merge fixes * cargo fmt --all * compilation fixes * reexport BlockNumberOf, HashOf, HeaderOf
This commit is contained in:
committed by
Bastian Köcher
parent
ddeb59d336
commit
9e9ac8df3c
@@ -16,7 +16,7 @@
|
||||
|
||||
//! Types used to connect to the Millau-Substrate chain.
|
||||
|
||||
use relay_substrate_client::Chain;
|
||||
use relay_substrate_client::{Chain, ChainBase};
|
||||
|
||||
use headers_relay::sync_types::SourceHeader;
|
||||
use sp_runtime::traits::Header as HeaderT;
|
||||
@@ -28,10 +28,14 @@ pub type HeaderId = relay_utils::HeaderId<millau_runtime::Hash, millau_runtime::
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Millau;
|
||||
|
||||
impl Chain for Millau {
|
||||
impl ChainBase for Millau {
|
||||
type BlockNumber = millau_runtime::BlockNumber;
|
||||
type Hash = millau_runtime::Hash;
|
||||
type Hasher = millau_runtime::Hashing;
|
||||
type Header = millau_runtime::Header;
|
||||
}
|
||||
|
||||
impl Chain for Millau {
|
||||
type AccountId = millau_runtime::AccountId;
|
||||
type Index = millau_runtime::Index;
|
||||
type SignedBlock = millau_runtime::SignedBlock;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use codec::Encode;
|
||||
use headers_relay::sync_types::SourceHeader;
|
||||
use relay_substrate_client::{Chain, Client, TransactionSignScheme};
|
||||
use relay_substrate_client::{Chain, ChainBase, Client, TransactionSignScheme};
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::{
|
||||
generic::SignedPayload,
|
||||
@@ -32,10 +32,14 @@ pub type HeaderId = relay_utils::HeaderId<rialto_runtime::Hash, rialto_runtime::
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Rialto;
|
||||
|
||||
impl Chain for Rialto {
|
||||
impl ChainBase for Rialto {
|
||||
type BlockNumber = rialto_runtime::BlockNumber;
|
||||
type Hash = rialto_runtime::Hash;
|
||||
type Hasher = rialto_runtime::Hashing;
|
||||
type Header = rialto_runtime::Header;
|
||||
}
|
||||
|
||||
impl Chain for Rialto {
|
||||
type AccountId = rialto_runtime::AccountId;
|
||||
type Index = rialto_runtime::Index;
|
||||
type SignedBlock = rialto_runtime::SignedBlock;
|
||||
|
||||
@@ -14,6 +14,7 @@ num-traits = "0.2"
|
||||
|
||||
# Bridge dependencies
|
||||
|
||||
bp-runtime = { path = "../../primitives/runtime" }
|
||||
headers-relay = { path = "../headers-relay" }
|
||||
relay-utils = { path = "../utils" }
|
||||
|
||||
|
||||
@@ -16,51 +16,19 @@
|
||||
|
||||
use crate::client::Client;
|
||||
|
||||
use bp_runtime::Chain as ChainBase;
|
||||
use frame_support::Parameter;
|
||||
use jsonrpsee::common::{DeserializeOwned, Serialize};
|
||||
use sp_core::Pair;
|
||||
use sp_runtime::{
|
||||
generic::SignedBlock,
|
||||
traits::{
|
||||
AtLeast32Bit, AtLeast32BitUnsigned, Bounded, CheckEqual, Dispatchable, Header as HeaderT, MaybeDisplay,
|
||||
MaybeMallocSizeOf, MaybeSerialize, MaybeSerializeDeserialize, Member, SimpleBitOps,
|
||||
},
|
||||
traits::{AtLeast32Bit, Dispatchable, MaybeDisplay, MaybeSerialize, MaybeSerializeDeserialize, Member},
|
||||
Justification,
|
||||
};
|
||||
use sp_std::fmt::Debug;
|
||||
|
||||
/// Substrate-based chain from minimal relay-client point of view.
|
||||
pub trait Chain {
|
||||
/// The block number type used by the runtime.
|
||||
type BlockNumber: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ AtLeast32BitUnsigned
|
||||
+ Default
|
||||
+ Bounded
|
||||
+ Copy
|
||||
+ sp_std::hash::Hash
|
||||
+ sp_std::str::FromStr
|
||||
+ MaybeMallocSizeOf;
|
||||
/// The output of the `Hashing` function.
|
||||
type Hash: Parameter
|
||||
+ Member
|
||||
+ MaybeSerializeDeserialize
|
||||
+ Debug
|
||||
+ MaybeDisplay
|
||||
+ SimpleBitOps
|
||||
+ Ord
|
||||
+ Default
|
||||
+ Copy
|
||||
+ CheckEqual
|
||||
+ sp_std::hash::Hash
|
||||
+ AsRef<[u8]>
|
||||
+ AsMut<[u8]>
|
||||
+ MaybeMallocSizeOf;
|
||||
/// The block header.
|
||||
type Header: Parameter + HeaderT<Number = Self::BlockNumber, Hash = Self::Hash>;
|
||||
pub trait Chain: ChainBase {
|
||||
/// The user account identifier type for the runtime.
|
||||
type AccountId: Parameter + Member + MaybeSerializeDeserialize + Debug + MaybeDisplay + Ord + Default;
|
||||
/// Account index (aka nonce) type. This stores the number of previous transactions associated
|
||||
@@ -96,15 +64,6 @@ pub trait TransactionSignScheme {
|
||||
) -> Self::SignedTransaction;
|
||||
}
|
||||
|
||||
/// Header type used by the chain.
|
||||
pub type HeaderOf<C> = <C as Chain>::Header;
|
||||
|
||||
/// Hash type used by the chain.
|
||||
pub type HashOf<C> = <C as Chain>::Hash;
|
||||
|
||||
/// Block number used by the chain.
|
||||
pub type BlockNumberOf<C> = <C as Chain>::BlockNumber;
|
||||
|
||||
impl<Block> BlockWithJustification for SignedBlock<Block> {
|
||||
fn justification(&self) -> Option<&Justification> {
|
||||
self.justification.as_ref()
|
||||
|
||||
@@ -25,9 +25,10 @@ mod rpc;
|
||||
|
||||
pub mod headers_source;
|
||||
|
||||
pub use crate::chain::{BlockNumberOf, BlockWithJustification, Chain, HashOf, HeaderOf, TransactionSignScheme};
|
||||
pub use crate::chain::{BlockWithJustification, Chain, TransactionSignScheme};
|
||||
pub use crate::client::{Client, OpaqueGrandpaAuthoritiesSet};
|
||||
pub use crate::error::{Error, Result};
|
||||
pub use bp_runtime::{BlockNumberOf, Chain as ChainBase, HashOf, HeaderOf};
|
||||
|
||||
/// Substrate connection params.
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
Reference in New Issue
Block a user