Skip to content
Snippets Groups Projects
lib.rs 8.28 KiB
Newer Older
// Copyright 2021 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.

Shawn Tabrizi's avatar
Shawn Tabrizi committed
#![cfg_attr(not(feature = "std"), no_std)]
// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
Pascal Engélibert's avatar
Pascal Engélibert committed
#![recursion_limit = "256"]
Shawn Tabrizi's avatar
Shawn Tabrizi committed

// Make the WASM binary available.
#[cfg(feature = "std")]
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));


pub use self::parameters::*;
pub use common_runtime::{
    constants::*,
Éloïs's avatar
Éloïs committed
    entities::{IdtyData, IdtyRight},
    AccountId, Address, Balance, BlockNumber, Hash, Header, IdtyIndex, IdtyNameValidatorImpl,
    Index, Signature,
Éloïs's avatar
Éloïs committed
pub use pallet_balances::Call as BalancesCall;
pub use pallet_identity::{IdtyStatus, IdtyValue};
Éloïs's avatar
Éloïs committed
use pallet_transaction_payment::CurrencyAdapter;
pub use pallet_universal_dividend;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};

use common_runtime::{
    authorizations::{AddStrongCertOrigin, DelStrongCertOrigin, EnsureIdtyCallAllowedImpl},
    handlers::{
        OnIdtyChangeHandler, OnNewStrongCertHandler, OnRemovedStrongCertHandler,
        OnRightKeyChangeHandler,
    },
    providers::IdtyDataProvider,
Éloïs's avatar
Éloïs committed
use frame_system::EnsureRoot;
Pascal Engélibert's avatar
Pascal Engélibert committed
use pallet_grandpa::fg_primitives;
use pallet_grandpa::{AuthorityId as GrandpaId, AuthorityList as GrandpaAuthorityList};
use sp_api::impl_runtime_apis;
use sp_core::{crypto::KeyTypeId, OpaqueMetadata};
use sp_runtime::traits::{AccountIdLookup, BlakeTwo256, Block as BlockT, NumberFor};
Pascal Engélibert's avatar
Pascal Engélibert committed
use sp_runtime::{
    create_runtime_str, generic, impl_opaque_keys,
    transaction_validity::{TransactionSource, TransactionValidity},
    ApplyExtrinsicResult,
Pascal Engélibert's avatar
Pascal Engélibert committed
};
use sp_std::prelude::*;
Shawn Tabrizi's avatar
Shawn Tabrizi committed
#[cfg(feature = "std")]
Joshy Orndorff's avatar
Joshy Orndorff committed
use sp_version::NativeVersion;
Pascal Engélibert's avatar
Pascal Engélibert committed
use sp_version::RuntimeVersion;
Shawn Tabrizi's avatar
Shawn Tabrizi committed

// A few exports that help ease life for downstream crates.
Joshy Orndorff's avatar
Joshy Orndorff committed
pub use frame_support::{
Pascal Engélibert's avatar
Pascal Engélibert committed
    construct_runtime, parameter_types,
    traits::{KeyOwnerProofSystem, Randomness},
    weights::{
        constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
Éloïs's avatar
Éloïs committed
        Weight, WeightToFeeCoefficient, WeightToFeeCoefficients, WeightToFeePolynomial,
Pascal Engélibert's avatar
Pascal Engélibert committed
    },
    StorageValue,
Joshy Orndorff's avatar
Joshy Orndorff committed
};
Shawn Tabrizi's avatar
Shawn Tabrizi committed
/// Opaque types. These are used by the CLI to instantiate machinery that don't need to know
/// the specifics of the runtime. They can then be made to be agnostic over specific formats
/// of data like extrinsics, allowing for them to continue syncing the network through upgrades
/// to even the core data structures.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
pub mod opaque {
Pascal Engélibert's avatar
Pascal Engélibert committed
    use super::*;

    impl_opaque_keys! {
        pub struct SessionKeys {
            pub grandpa: Grandpa,
        }
    }
// To learn more about runtime versioning and what each of the following value means:
//   https://substrate.dev/docs/en/knowledgebase/runtime/upgrades#runtime-versioning
Éloïs's avatar
Éloïs committed
#[sp_version::runtime_version]
Shawn Tabrizi's avatar
Shawn Tabrizi committed
pub const VERSION: RuntimeVersion = RuntimeVersion {
    spec_name: create_runtime_str!("gdev"),
    impl_name: create_runtime_str!("gdev"),
Pascal Engélibert's avatar
Pascal Engélibert committed
    authoring_version: 1,
    // The version of the runtime specification. A full node will not attempt to use its native
    //   runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
    //   `spec_version`, and `authoring_version` are the same between Wasm and native.
    // This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
    //   the compatible custom types.
    spec_version: 100,
    impl_version: 1,
    apis: RUNTIME_API_VERSIONS,
    transaction_version: 1,
    state_version: 1,
/// The version information used to identify this runtime when compiled natively.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
#[cfg(feature = "std")]
pub fn native_version() -> NativeVersion {
Pascal Engélibert's avatar
Pascal Engélibert committed
    NativeVersion {
        runtime_version: VERSION,
        can_author_with: Default::default(),
    }
Shawn Tabrizi's avatar
Shawn Tabrizi committed
}

parameter_types! {
Pascal Engélibert's avatar
Pascal Engélibert committed
    pub const Version: RuntimeVersion = VERSION;
    pub const BlockHashCount: BlockNumber = 2400;
    /// We allow for 2 seconds of compute with a 6 second average block time.
    pub BlockWeights: frame_system::limits::BlockWeights = frame_system::limits::BlockWeights
        ::with_sensible_defaults(2 * WEIGHT_PER_SECOND, NORMAL_DISPATCH_RATIO);
    pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength
        ::max_with_normal_ratio(5 * 1024 * 1024, NORMAL_DISPATCH_RATIO);
    pub const SS58Prefix: u16 = 42;
Dan Forbes's avatar
Dan Forbes committed
// Configure FRAME pallets to include in runtime.
common_runtime::pallets_config! {
    impl pallet_randomness_collective_flip::Config for Runtime {}
    impl pallet_sudo::Config for Runtime {
        type Event = Event;
        type Call = Call;
    }
Dan Forbes's avatar
Dan Forbes committed
// Create the runtime by composing the FRAME pallets that were previously configured.
Shawn Tabrizi's avatar
Shawn Tabrizi committed
construct_runtime!(
Pascal Engélibert's avatar
Pascal Engélibert committed
    pub enum Runtime where
        Block = Block,
        NodeBlock = common_runtime::Block,
Pascal Engélibert's avatar
Pascal Engélibert committed
        UncheckedExtrinsic = UncheckedExtrinsic
    {
        // Basic stuff
        System: frame_system::{Pallet, Call, Config, Storage, Event<T>} = 0,
        Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>} = 1,

        Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 5,
        TransactionPayment: pallet_transaction_payment::{Pallet, Storage} = 32,

        // Consensus support.
        Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event} = 10,
        RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 11,

        // Governance stuff.
        Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>} = 20,

        // Cunning utilities.
        Utility: pallet_utility::{Pallet, Call, Event} = 30,

        // Universal dividend.
        UdAccountsStorage: pallet_ud_accounts_storage::{Pallet, Config<T>, Storage} = 40,
        UniversalDividend: pallet_universal_dividend::{Pallet, Call, Config<T>, Storage, Event<T>} = 41,

        // Web Of Trust
        Identity: pallet_identity::{Pallet, Call, Config<T>, Storage, Event<T>} = 50,
        StrongCert: pallet_certification::<Instance1>::{Pallet, Call, Config<T>, Storage, Event<T>} = 51,

        // Multisig dispatch.
        Multisig: pallet_multisig::{Pallet, Call, Storage, Event<T>} = 60,
Pascal Engélibert's avatar
Pascal Engélibert committed
    }
Shawn Tabrizi's avatar
Shawn Tabrizi committed
);

/// Block type as expected by this runtime.
pub type Block = sp_runtime::generic::Block<Header, UncheckedExtrinsic>;
/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
Shawn Tabrizi's avatar
Shawn Tabrizi committed
/// The SignedExtension to the basic transaction logic.
pub type SignedExtra = (
Pascal Engélibert's avatar
Pascal Engélibert committed
    frame_system::CheckSpecVersion<Runtime>,
    frame_system::CheckTxVersion<Runtime>,
    frame_system::CheckGenesis<Runtime>,
    frame_system::CheckEra<Runtime>,
    frame_system::CheckNonce<Runtime>,
    frame_system::CheckWeight<Runtime>,
    pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
Shawn Tabrizi's avatar
Shawn Tabrizi committed
);
/// Executive: handles dispatch to the various modules.
Dan Forbes's avatar
Dan Forbes committed
pub type Executive = frame_executive::Executive<
Pascal Engélibert's avatar
Pascal Engélibert committed
    Runtime,
    Block,
    frame_system::ChainContext<Runtime>,
    Runtime,
    AllPalletsWithSystem,
// All of our runtimes share most of their Runtime API implementations.
// We use a macro to implement this common part and add runtime-specific additional implementations.
// This macro expands to :
// ```
// impl_runtime_apis! {
//     // All impl blocks shared between all runtimes.
//
//     // Specific impls provided to the `runtime_apis!` macro.
common_runtime::runtime_apis! {
    impl sp_consensus_aura::AuraApi<Block, sp_consensus_aura::sr25519::AuthorityId> for Runtime {
Pascal Engélibert's avatar
Pascal Engélibert committed
        fn slot_duration() -> sp_consensus_aura::SlotDuration {
            sp_consensus_aura::SlotDuration::from_millis(0)
Pascal Engélibert's avatar
Pascal Engélibert committed
        }

        fn authorities() -> Vec<sp_consensus_aura::sr25519::AuthorityId> {
Pascal Engélibert's avatar
Pascal Engélibert committed
        }
    }
Shawn Tabrizi's avatar
Shawn Tabrizi committed
}