Kagome
Polkadot Runtime Engine in C++17
offchain_worker_api.cpp
Go to the documentation of this file.
1 
7 
10 
11 namespace kagome::runtime {
12 
14  const application::AppConfiguration &app_config,
15  std::shared_ptr<offchain::OffchainWorkerFactory> ocw_factory,
16  std::shared_ptr<Executor> executor)
17  : app_config_(app_config),
18  ocw_factory_(std::move(ocw_factory)),
19  executor_(std::move(executor)) {
20  BOOST_ASSERT(ocw_factory_);
21  BOOST_ASSERT(executor_);
22  }
23 
25  const primitives::BlockHash &block,
26  const primitives::BlockHeader &header) {
27  // Never start offchain workers
30  return outcome::success();
31  }
32 
33  // Not start offchain workers if node is not validating,
34  // but offchain workers runs when node is validating
37  if (app_config_.roles().flags.authority != 1) {
38  return outcome::success();
39  }
40  }
41 
42  auto worker = ocw_factory_->make(executor_, header);
43 
44  auto res = worker->run();
45 
46  return res;
47  }
48 
49 } // namespace kagome::runtime
virtual OffchainWorkerMode offchainWorkerMode() const =0
struct kagome::network::Roles::@11 flags
STL namespace.
virtual network::Roles roles() const =0
OffchainWorkerApiImpl(const application::AppConfiguration &app_config, std::shared_ptr< offchain::OffchainWorkerFactory > ocw_factory, std::shared_ptr< Executor > executor)
std::shared_ptr< offchain::OffchainWorkerFactory > ocw_factory_
const application::AppConfiguration & app_config_
outcome::result< void > offchain_worker(const primitives::BlockHash &block, const primitives::BlockHeader &header) override
calls offchain_worker method of OffchainWorker runtime api