mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 08:07:58 +00:00
e327b734bc
* use clap3 instead of structopt Signed-off-by: koushiro <koushiro.cqx@gmail.com> * format Signed-off-by: koushiro <koushiro.cqx@gmail.com> * update ss58-registry and revert some nits Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Fix clippy and doc Signed-off-by: koushiro <koushiro.cqx@gmail.com> * update clap to 3.0.7 Signed-off-by: koushiro <koushiro.cqx@gmail.com> * Apply review suggestions Signed-off-by: koushiro <koushiro.cqx@gmail.com> * remove useless option long name Signed-off-by: koushiro <koushiro.cqx@gmail.com> * cargo fmt Signed-off-by: koushiro <koushiro.cqx@gmail.com>
69 lines
2.5 KiB
Rust
69 lines
2.5 KiB
Rust
// This file is part of Substrate.
|
|
|
|
// Copyright (C) 2020-2022 Parity Technologies (UK) Ltd.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
//! Offchain worker related configuration parameters.
|
|
//!
|
|
//! A subset of configuration parameters which are relevant to
|
|
//! the inner working of offchain workers. The usage is solely
|
|
//! targeted at handling input parameter parsing providing
|
|
//! a reasonable abstraction.
|
|
|
|
use clap::Args;
|
|
use sc_network::config::Role;
|
|
use sc_service::config::OffchainWorkerConfig;
|
|
|
|
use crate::{error, OffchainWorkerEnabled};
|
|
|
|
/// Offchain worker related parameters.
|
|
#[derive(Debug, Clone, Args)]
|
|
pub struct OffchainWorkerParams {
|
|
/// Should execute offchain workers on every block.
|
|
///
|
|
/// By default it's only enabled for nodes that are authoring new blocks.
|
|
#[clap(
|
|
long = "offchain-worker",
|
|
value_name = "ENABLED",
|
|
arg_enum,
|
|
ignore_case = true,
|
|
default_value = "WhenValidating"
|
|
)]
|
|
pub enabled: OffchainWorkerEnabled,
|
|
|
|
/// Enable Offchain Indexing API, which allows block import to write to Offchain DB.
|
|
///
|
|
/// Enables a runtime to write directly to a offchain workers
|
|
/// DB during block import.
|
|
#[clap(long = "enable-offchain-indexing", value_name = "ENABLE_OFFCHAIN_INDEXING")]
|
|
pub indexing_enabled: bool,
|
|
}
|
|
|
|
impl OffchainWorkerParams {
|
|
/// Load spec to `Configuration` from `OffchainWorkerParams` and spec factory.
|
|
pub fn offchain_worker(&self, role: &Role) -> error::Result<OffchainWorkerConfig> {
|
|
let enabled = match (&self.enabled, role) {
|
|
(OffchainWorkerEnabled::WhenValidating, Role::Authority { .. }) => true,
|
|
(OffchainWorkerEnabled::Always, _) => true,
|
|
(OffchainWorkerEnabled::Never, _) => false,
|
|
(OffchainWorkerEnabled::WhenValidating, _) => false,
|
|
};
|
|
|
|
let indexing_enabled = self.indexing_enabled;
|
|
Ok(OffchainWorkerConfig { enabled, indexing_enabled })
|
|
}
|
|
}
|