mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 20:57:59 +00:00
Initial: Offchain Workers (#1942)
* Refactor state-machine stuff. * Fix tests. * WiP * WiP2 * Service support for offchain workers. * Service support for offchain workers. * Testing offchain worker. * Initial version working. * Pass side effects in call. * Pass OffchainExt in context. * Submit extrinsics to the pool. * Support inherents. * Insert to inherents pool. * Inserting to the pool asynchronously. * Add test to offchain worker. * Implement convenience syntax for modules. * Dispatching offchain worker through executive. * Fix offchain test. * Remove offchain worker from timestamp. * Update Cargo.lock. * Address review comments. * Use latest patch version for futures. * Add CLI parameter for offchain worker. * Fix compilation. * Fix test. * Fix extrinsics format for tests. * Fix RPC test. * Bump spec version. * Fix executive. * Fix support macro. * Address grumbles. * Bump runtime
This commit is contained in:
@@ -270,6 +270,24 @@ pub trait OnInitialise<BlockNumber> {
|
||||
|
||||
impl<N> OnInitialise<N> for () {}
|
||||
|
||||
/// Off-chain computation trait.
|
||||
///
|
||||
/// Implementing this trait on a module allows you to perform a long-running tasks
|
||||
/// that make validators generate extrinsics (either transactions or inherents)
|
||||
/// with results of those long-running computations.
|
||||
///
|
||||
/// NOTE: This function runs off-chain, so it can access the block state,
|
||||
/// but cannot preform any alterations.
|
||||
pub trait OffchainWorker<BlockNumber> {
|
||||
/// This function is being called on every block.
|
||||
///
|
||||
/// Implement this and use special `extern`s to generate transactions or inherents.
|
||||
/// Any state alterations are lost and are not persisted.
|
||||
fn generate_extrinsics(_n: BlockNumber) {}
|
||||
}
|
||||
|
||||
impl<N> OffchainWorker<N> for () {}
|
||||
|
||||
macro_rules! tuple_impl {
|
||||
($one:ident,) => {
|
||||
impl<Number: Copy, $one: OnFinalise<Number>> OnFinalise<Number> for ($one,) {
|
||||
@@ -282,6 +300,11 @@ macro_rules! tuple_impl {
|
||||
$one::on_initialise(n);
|
||||
}
|
||||
}
|
||||
impl<Number: Copy, $one: OffchainWorker<Number>> OffchainWorker<Number> for ($one,) {
|
||||
fn generate_extrinsics(n: Number) {
|
||||
$one::generate_extrinsics(n);
|
||||
}
|
||||
}
|
||||
};
|
||||
($first:ident, $($rest:ident,)+) => {
|
||||
impl<
|
||||
@@ -304,6 +327,16 @@ macro_rules! tuple_impl {
|
||||
$($rest::on_initialise(n);)+
|
||||
}
|
||||
}
|
||||
impl<
|
||||
Number: Copy,
|
||||
$first: OffchainWorker<Number>,
|
||||
$($rest: OffchainWorker<Number>),+
|
||||
> OffchainWorker<Number> for ($first, $($rest),+) {
|
||||
fn generate_extrinsics(n: Number) {
|
||||
$first::generate_extrinsics(n);
|
||||
$($rest::generate_extrinsics(n);)+
|
||||
}
|
||||
}
|
||||
tuple_impl!($($rest,)+);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user