npos-config 0.0.3

npos config
Documentation
// Copyright 2021-2022 Parity Technologies (UK) Ltd.
// This file is part of Polkadot.

// Polkadot 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.

// Polkadot 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 Polkadot.  If not, see <http://www.gnu.org/licenses/>.

use strum::{Display as EnumDisplay, EnumString, EnumVariantNames};

pub mod prelude;
use prelude::*;

#[path = "westend.rs"]
pub mod westend;
pub use westend::MinerConfig as Westend;

#[path = "polkadot.rs"]
pub mod polkadot;
pub use polkadot::MinerConfig as Polkadot;

#[path = "kusama.rs"]
pub mod kusama;
pub use kusama::MinerConfig as Kusama;

#[path = "vara.rs"]
pub mod vara;
pub use vara::MinerConfig as Vara;

#[path = "joystream.rs"]
pub mod joystream;
pub use joystream::MinerConfig as Joystream;

#[path = "enjin.rs"]
pub mod enjin;
pub use enjin::MinerConfig as Enjin;

#[derive(
  Debug,
  Default,
  Clone,
  Copy,
  PartialEq,
  Eq,
  EnumString,
  EnumDisplay,
  EnumVariantNames,
)]
pub enum Chain {
  #[default]
  #[strum(serialize = "vara")]
  Vara,
  #[strum(serialize = "polkadot")]
  Polkadot,
  #[strum(serialize = "kusama")]
  Kusama,
  #[strum(serialize = "westend")]
  Westend,
  #[strum(serialize = "joystream")]
  Joystream,
  #[strum(serialize = "enjin")]
  Enjin,
}

#[derive(
  Debug,
  Default,
  Copy,
  Clone,
  PartialEq,
  Eq,
  EnumString,
  EnumDisplay,
  EnumVariantNames,
)]
pub enum Method {
  #[default]
  #[strum(serialize = "seq")]
  SeqPhragmen,
  #[strum(serialize = "mms")]
  PhragMMS,
}

// A helper to use different MinerConfig depending on chain.
#[macro_export]
macro_rules! with_chain {
  ($chain:expr, $($code:tt)*) => {
    match $chain {
      Chain::Vara => {
        #[allow(unused)]
        use Vara as Config;
        $($code)*
      },
      Chain::Polkadot => {
        #[allow(unused)]
        use Polkadot as Config;
        $($code)*
      },
      Chain::Kusama => {
        #[allow(unused)]
        use Kusama as Config;
        $($code)*
      },
      Chain::Westend => {
        #[allow(unused)]
        use Westend as Config;
        $($code)*
      },
      Chain::Joystream => {
        #[allow(unused)]
        use Joystream as Config;
        $($code)*
      },
      Chain::Enjin => {
        #[allow(unused)]
        use Enjin as Config;
        $($code)*
      },
    }
  };
}