mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-12 17:01:09 +00:00
Runtime API clean up (#892)
* Rename `NewTxQueue` to `TaggedTransactionQueue` * Remove `BlockBuilder` API and support adding documentation to the API functions * Adds new `BlockBuilder` API * Fixes compilation with new `BlockBuilder` API * Some more cleanup * Cargo.lock update * Try to fix on stable
This commit is contained in:
@@ -25,7 +25,7 @@ pub extern crate parity_codec as codec;
|
||||
extern crate sr_version as runtime_version;
|
||||
|
||||
#[doc(hidden)]
|
||||
pub use primitives::{ApplyResult, traits::Block as BlockT, generic::BlockId};
|
||||
pub use primitives::{traits::Block as BlockT, generic::BlockId, ApplyResult};
|
||||
use runtime_version::RuntimeVersion;
|
||||
use rstd::vec::Vec;
|
||||
#[doc(hidden)]
|
||||
@@ -39,8 +39,12 @@ pub use codec::{Encode, Decode};
|
||||
///
|
||||
/// ```nocompile
|
||||
/// decl_apis!{
|
||||
/// pub trait Test<Event> {
|
||||
/// pub trait Test<Event> ExtraClientSide<ClientArg> {
|
||||
/// fn test<AccountId>(event: Event) -> AccountId;
|
||||
///
|
||||
/// /// A function that will have the extra parameter `param` on the client side,
|
||||
/// /// the runtime does not have any parameter.
|
||||
/// fn testWithExtraParams() ExtraClientSide(param: &Self::ClientArg);
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@@ -56,7 +60,9 @@ pub use codec::{Encode, Decode};
|
||||
///
|
||||
/// pub trait Test<Block: BlockT, Event> {
|
||||
/// type Error;
|
||||
/// type ClientArg;
|
||||
/// fn test<AccountId: Encode + Decode>(&self, at: &BlockId<Block>, event: Event) -> Result<Event, Self::Error>;
|
||||
/// fn testWithExtraParams(&self, at: &BlockId<Block>, param: &Client) -> Result<Event, Self::Error>;
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
@@ -68,11 +74,16 @@ macro_rules! decl_apis {
|
||||
(
|
||||
$(
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param:ident $( : $generic_bound:ident )* ),* >)* {
|
||||
pub trait $name:ident $(< $( $generic_param:ident $( : $generic_bound:ident )* ),* >)*
|
||||
$( ExtraClientSide < $( $client_generic_param:ident $( : $client_generic_bound:ident )* ),+ > )*
|
||||
{
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
$( $param_name:ident : $param_type:ty ),*
|
||||
)
|
||||
$( ExtraClientSide ( $( $client_param_name:ident : $client_param_type:ty ),+ ) )*
|
||||
$( -> $return_ty:ty)*;
|
||||
)*
|
||||
}
|
||||
)*
|
||||
@@ -82,8 +93,13 @@ macro_rules! decl_apis {
|
||||
@ADD_BLOCK_GENERIC
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param $( : $generic_bound )* ),* >)* {
|
||||
$( $( type $client_generic_param $( : $client_generic_bound )*; )* )*
|
||||
$(
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* ($( $param_name : $param_type )* ) $( -> $return_ty )*;
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $( $client_param_name: $client_param_type, )* )*
|
||||
$( $param_name : &$param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
;
|
||||
@@ -97,6 +113,7 @@ macro_rules! decl_apis {
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param $( : $generic_bound )* ),* >)* {
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* ($( $param_name : $param_type )* ) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -106,9 +123,11 @@ macro_rules! decl_apis {
|
||||
(@ADD_BLOCK_GENERIC
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
};
|
||||
@@ -121,9 +140,11 @@ macro_rules! decl_apis {
|
||||
@ADD_BLOCK_GENERIC
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -135,9 +156,11 @@ macro_rules! decl_apis {
|
||||
(@ADD_BLOCK_GENERIC
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -150,9 +173,11 @@ macro_rules! decl_apis {
|
||||
@ADD_BLOCK_GENERIC
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -164,9 +189,11 @@ macro_rules! decl_apis {
|
||||
(@ADD_BLOCK_GENERIC
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -174,12 +201,14 @@ macro_rules! decl_apis {
|
||||
$( $generic_param_parsed:ident $( : $generic_bound_parsed:path )* ),*;
|
||||
) => {
|
||||
decl_apis!(
|
||||
@GENERATE_FNS
|
||||
@GENERATE_RETURN_TYPES
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -191,9 +220,11 @@ macro_rules! decl_apis {
|
||||
(@ADD_BLOCK_GENERIC
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -201,12 +232,14 @@ macro_rules! decl_apis {
|
||||
$( $generic_param_parsed:ident $( : $generic_bound_parsed:ident )* ),*;
|
||||
) => {
|
||||
decl_apis!(
|
||||
@GENERATE_FNS
|
||||
@GENERATE_RETURN_TYPES
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -216,12 +249,14 @@ macro_rules! decl_apis {
|
||||
$( $( $return_ty )*; )*
|
||||
);
|
||||
};
|
||||
(@GENERATE_FNS
|
||||
(@GENERATE_RETURN_TYPES
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
};
|
||||
@@ -231,12 +266,14 @@ macro_rules! decl_apis {
|
||||
$( $( $return_ty_rest:ty )*; )*
|
||||
) => {
|
||||
decl_apis!(
|
||||
@GENERATE_FNS
|
||||
@GENERATE_RETURN_TYPES
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -245,12 +282,14 @@ macro_rules! decl_apis {
|
||||
$( $( $return_ty_rest )*; )*
|
||||
);
|
||||
};
|
||||
(@GENERATE_FNS
|
||||
(@GENERATE_RETURN_TYPES
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
};
|
||||
@@ -260,12 +299,14 @@ macro_rules! decl_apis {
|
||||
$( $( $return_ty_rest:ty )*; )*
|
||||
) => {
|
||||
decl_apis!(
|
||||
@GENERATE_FNS
|
||||
@GENERATE_RETURN_TYPES
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
@@ -274,12 +315,14 @@ macro_rules! decl_apis {
|
||||
$( $( $return_ty_rest )*; )*
|
||||
);
|
||||
};
|
||||
(@GENERATE_FNS
|
||||
(@GENERATE_RETURN_TYPES
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
};
|
||||
@@ -290,35 +333,40 @@ macro_rules! decl_apis {
|
||||
@GENERATE_CLIENT_TRAITS
|
||||
$( #[$attr] )*
|
||||
pub trait $name $(< $( $generic_param_orig $( : $generic_bound_orig )* ),* >)* {
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic ),* > )* (
|
||||
$( $param_name : $param_type )*
|
||||
$( $param_name : $param_type, )*
|
||||
) $( -> $return_ty )*;
|
||||
)*
|
||||
};
|
||||
$( $generic_param_parsed $( : $generic_bound_parsed )* ),*;
|
||||
{ $( $result_return_ty; )* };
|
||||
$( $( $generic_param_orig $( : $generic_bound_orig )*, )* )* $( $( $( $fn_generic, )* )* )*;
|
||||
);
|
||||
};
|
||||
(@GENERATE_CLIENT_TRAITS
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param_orig:ident $( : $generic_bound_orig:ident )* ),* >)* {
|
||||
$( type $client_generic_param:ident $( : $client_generic_bound:ident )*; )*
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
$( $param_name:ident : $param_type:ty, )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
};
|
||||
$( $generic_param_parsed:ident $( : $generic_bound_parsed:path )* ),*;
|
||||
{ $( $result_return_ty:ty; )* };
|
||||
$( $generic_param_joined:ident $( : $generic_bound_joined:ident )*, )*;
|
||||
) => {
|
||||
$( #[$attr] )*
|
||||
pub trait $name < $( $generic_param_parsed $( : $generic_bound_parsed )* ),* > {
|
||||
/// The Error type returned by this API.
|
||||
type Error;
|
||||
$( type $client_generic_param $( : $client_generic_bound )*; )*
|
||||
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name $( < $( $fn_generic: $crate::Encode + $crate::Decode ),* > )* (
|
||||
&self, at: &$crate::BlockId<Block> $(, $param_name: $param_type )*
|
||||
) -> $result_return_ty;
|
||||
@@ -330,6 +378,7 @@ macro_rules! decl_apis {
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident $(< $( $generic_param:ident $( : $generic_bound:ident )* ),* >)* {
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident $( < $( $fn_generic:ident ),* > )* (
|
||||
$( $param_name:ident : $param_type:ty )*
|
||||
) $( -> $return_ty:ty)*;
|
||||
@@ -343,6 +392,7 @@ macro_rules! decl_apis {
|
||||
$( #[$attr] )*
|
||||
pub trait $name < $( $( $generic_param $( : $generic_bound )*, )* )* $( $( $( $fn_generic, )* )* )* > {
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name ($( $param_name: $param_type ),*) $( -> $return_ty )*;
|
||||
)*
|
||||
}
|
||||
@@ -354,11 +404,13 @@ macro_rules! decl_apis {
|
||||
$( #[$attr:meta] )*
|
||||
pub trait $name:ident < $( $generic_param:ident $( : $generic_bound:ident )*, )* > {
|
||||
$(
|
||||
$( #[$fn_attr:meta] )*
|
||||
fn $fn_name:ident($( $param_name:ident : $param_type:ty )*) $( -> $return_ty:ty)*;
|
||||
)*
|
||||
}
|
||||
)*
|
||||
) => {
|
||||
/// The API traits to implement on the runtime side.
|
||||
pub mod runtime {
|
||||
use super::*;
|
||||
|
||||
@@ -366,6 +418,7 @@ macro_rules! decl_apis {
|
||||
$( #[$attr] )*
|
||||
pub trait $name < $( $generic_param $( : $generic_bound )* ),* > {
|
||||
$(
|
||||
$( #[$fn_attr] )*
|
||||
fn $fn_name ($( $param_name: $param_type ),*) $( -> $return_ty )*;
|
||||
)*
|
||||
}
|
||||
@@ -387,23 +440,14 @@ decl_apis! {
|
||||
fn metadata() -> Vec<u8>;
|
||||
}
|
||||
|
||||
/// The `BlockBuilder` api trait that provides required functions for building a block for a runtime.
|
||||
pub trait BlockBuilder<Block: BlockT> {
|
||||
fn initialise_block(header: <Block as BlockT>::Header);
|
||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult;
|
||||
fn finalise_block() -> <Block as BlockT>::Header;
|
||||
fn inherent_extrinsics<InherentExtrinsic, UncheckedExtrinsic>(inherent: InherentExtrinsic) -> Vec<UncheckedExtrinsic>;
|
||||
fn random_seed() -> <Block as BlockT>::Hash;
|
||||
}
|
||||
|
||||
/// The `OldTxQueue` api trait for interfering with the old transaction queue.
|
||||
pub trait OldTxQueue {
|
||||
fn account_nonce<AccountId, Index>(account: AccountId) -> Index;
|
||||
fn lookup_address<Address, LookupId>(address: Address) -> Option<LookupId>;
|
||||
}
|
||||
|
||||
/// The `NewTxQueue` api trait for interfering with the new transaction queue.
|
||||
pub trait NewTxQueue<Block: BlockT> {
|
||||
/// The `TaggedTransactionQueue` api trait for interfering with the new transaction queue.
|
||||
pub trait TaggedTransactionQueue<Block: BlockT> {
|
||||
fn validate_transaction<TransactionValidity>(tx: <Block as BlockT>::Extrinsic) -> TransactionValidity;
|
||||
}
|
||||
|
||||
@@ -413,6 +457,20 @@ decl_apis! {
|
||||
fn validators<AccountId>() -> Vec<AccountId>;
|
||||
fn timestamp<Moment>() -> Moment;
|
||||
}
|
||||
|
||||
/// The `BlockBuilder` api trait that provides required functions for building a block for a runtime.
|
||||
pub trait BlockBuilder<Block: BlockT> ExtraClientSide <OverlayedChanges> {
|
||||
/// Initialise a block with the given header.
|
||||
fn initialise_block(header: <Block as BlockT>::Header) ExtraClientSide(changes: &mut Self::OverlayedChanges);
|
||||
/// Apply the given extrinsics.
|
||||
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) ExtraClientSide(changes: &mut Self::OverlayedChanges) -> ApplyResult;
|
||||
/// Finish the current block.
|
||||
fn finalise_block() ExtraClientSide(changes: &mut Self::OverlayedChanges) -> <Block as BlockT>::Header;
|
||||
/// Generate inherent extrinsics.
|
||||
fn inherent_extrinsics<InherentExtrinsic, UncheckedExtrinsic>(inherent: InherentExtrinsic) -> Vec<UncheckedExtrinsic>;
|
||||
/// Generate a random seed.
|
||||
fn random_seed() -> <Block as BlockT>::Hash;
|
||||
}
|
||||
}
|
||||
|
||||
/// Implement the given API's for the given runtime.
|
||||
|
||||
Reference in New Issue
Block a user