mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 16:21:06 +00:00
Rewrite impl_runtime_apis! and decl_runtime_apis! as proc-macro (#1174)
* Rewrites `impl_runtime_apis!` macro as `proc-macro` * Adds some documentation * Require the `impl_runtime_apis` to use a path for accessing the trait * Make the runtime implement `GetNodeBlockType` * Moves first chunk of runtime api code into the `impl_runtime_apis` macro This also renames `ClientWithApi` into `RuntimeApi`. * Make `impl_runtime_apis` use `runtime` api version automatically * `decl_runtime_apis` automatically adds `Block: BlockT` as generic parameter * Remove function generic arguments in block builder api * Remove some unnused stuff from the `decl_runtime_apis` macro * Make `InherentData` working again * Make `impl_runtime_apis!` implement the `RuntimeApi` side as well * Make it compile again after rebasing with master * Split `sr-api-macros` into multiple files * Reimplement `decl_runtime_apis!` as proc_macro * Use `decl_runtime_apis!` for `Core` as well and improve error reporting * Adds documentation for `decl_runtime_apis!` and `impl_runtime_apis!` * Move some code * Adds compile fail tests * Adds a test and fixes some bugs * Make `impl_runtime_apis!` support `_` as parameter name * Fixes build errors with wasm * Wasm rebuild after master rebase * Apply suggestions from code review Co-Authored-By: bkchr <bkchr@users.noreply.github.com> * Addresses some grumbles * Adds test to ensure that method signatures need to match * New wasm files
This commit is contained in:
@@ -61,7 +61,7 @@ impl Era {
|
||||
Era::Mortal(period, quantized_phase)
|
||||
}
|
||||
|
||||
/// Create an "immortal" transaction.
|
||||
/// Create an "immortal" transaction.
|
||||
pub fn immortal() -> Self {
|
||||
Era::Immortal
|
||||
}
|
||||
@@ -75,7 +75,7 @@ impl Era {
|
||||
}
|
||||
|
||||
/// Get the block number of the start of the era whose properties this object
|
||||
/// describes that `current` belongs to.
|
||||
/// describes that `current` belongs to.
|
||||
pub fn birth(self, current: u64) -> u64 {
|
||||
match self {
|
||||
Era::Immortal => 0,
|
||||
@@ -189,10 +189,10 @@ mod tests {
|
||||
assert_ne!(e.birth(10), 6);
|
||||
assert_ne!(e.birth(5), 6);
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn current_less_than_phase() {
|
||||
// should not panic
|
||||
Era::mortal(4, 3).birth(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -462,6 +462,35 @@ macro_rules! impl_outer_log {
|
||||
};
|
||||
}
|
||||
|
||||
//TODO: https://github.com/paritytech/substrate/issues/1022
|
||||
/// Inherent data to include in a block.
|
||||
#[derive(Encode, Decode)]
|
||||
pub struct InherentData {
|
||||
/// Current timestamp.
|
||||
pub timestamp: u64,
|
||||
/// Indices of offline validators.
|
||||
pub consensus: Vec<u32>,
|
||||
}
|
||||
|
||||
impl InherentData {
|
||||
/// Create a new `InherentData` instance.
|
||||
pub fn new(timestamp: u64, consensus: Vec<u32>) -> Self {
|
||||
Self {
|
||||
timestamp,
|
||||
consensus,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: https://github.com/paritytech/substrate/issues/1022
|
||||
/// Error type used while checking inherents.
|
||||
#[derive(Encode)]
|
||||
#[cfg_attr(feature = "std", derive(Decode))]
|
||||
pub enum CheckInherentError {
|
||||
TimestampInFuture(u64),
|
||||
Other(RuntimeString),
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use substrate_primitives::hash::H256;
|
||||
|
||||
@@ -582,8 +582,6 @@ pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize {
|
||||
pub trait ProvideInherent {
|
||||
/// The inherent that is provided.
|
||||
type Inherent: Encode + MaybeDecode;
|
||||
/// The error used by this trait.
|
||||
type Error: Encode + MaybeDecode;
|
||||
/// The call for setting the inherent.
|
||||
type Call: Encode + MaybeDecode;
|
||||
|
||||
@@ -597,7 +595,7 @@ pub trait ProvideInherent {
|
||||
/// Check that the given inherent is valid.
|
||||
fn check_inherent<Block: self::Block, F: Fn(&Block::Extrinsic) -> Option<&Self::Call>>(
|
||||
block: &Block, data: Self::Inherent, extract_function: &F
|
||||
) -> Result<(), Self::Error>;
|
||||
) -> Result<(), super::CheckInherentError>;
|
||||
}
|
||||
|
||||
/// Auxiliary wrapper that holds an api instance and binds it to the given lifetime.
|
||||
@@ -629,3 +627,15 @@ pub trait ProvideRuntimeApi {
|
||||
/// storage, even on a `commit`.
|
||||
fn runtime_api<'a>(&'a self) -> ApiRef<'a, Self::Api>;
|
||||
}
|
||||
|
||||
/// A marker trait for something that knows the type of the runtime block.
|
||||
pub trait GetRuntimeBlockType {
|
||||
/// The `RuntimeBlock` type.
|
||||
type RuntimeBlock: self::Block;
|
||||
}
|
||||
|
||||
/// A marker trait for something that knows the type of the node block.
|
||||
pub trait GetNodeBlockType {
|
||||
/// The `NodeBlock` type.
|
||||
type NodeBlock: self::Block;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user