diff --git a/blockchain/modules/example/Cargo.toml b/blockchain/modules/example/Cargo.toml deleted file mode 100644 index 454c5eac..00000000 --- a/blockchain/modules/example/Cargo.toml +++ /dev/null @@ -1,26 +0,0 @@ -[package] -name = "nft-mart" -version = "1.0.0" -authors = ["Setheum Labs"] -edition = "2018" - -[dependencies] -serde = { version = "1.0.124", optional = true } -codec = { package = "parity-scale-codec", version = "2.2.0", default-features = false } -sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false } -frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false } -frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10", default-features = false } - -[dev-dependencies] -sp-core = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10" } -sp-io = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.10" } - -[features] -default = ["std"] -std = [ - "serde", - "codec/std", - "sp-runtime/std", - "frame-support/std", - "frame-system/std", -] diff --git a/blockchain/modules/example/src/lib.rs b/blockchain/modules/example/src/lib.rs deleted file mode 100644 index 3ccc927d..00000000 --- a/blockchain/modules/example/src/lib.rs +++ /dev/null @@ -1,146 +0,0 @@ -// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم - -// This file is part of Setheum. - -// Copyright (C) 2019-Present Setheum Labs. -// 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 . - -//! # Example Module -//! -//! A simple example of a FRAME pallet demonstrating -//! concepts, APIs and structures common to most FRAME runtimes. - -#![cfg_attr(not(feature = "std"), no_std)] -#![allow(clippy::unused_unit)] - -use frame_support::pallet_prelude::*; -use frame_system::pallet_prelude::*; - -mod mock; -mod tests; - -pub use module::*; - -#[frame_support::pallet] -pub mod module { - use super::*; - - #[pallet::config] - pub trait Config: frame_system::Config { - type Balance: Parameter + codec::HasCompact + From + Into + Default + MaybeSerializeDeserialize; - #[pallet::constant] - type SomeConst: Get; - type Event: From> + IsType<::Event>; - } - - #[pallet::error] - pub enum Error { - /// Some wrong behavior - Wrong, - } - - #[pallet::event] - #[pallet::generate_deposit(fn deposit_event)] - #[pallet::metadata(T::Balance = "Balance")] - pub enum Event { - /// Dummy event, just here so there's a generic type that's used. - Dummy(T::Balance), - } - - #[pallet::type_value] - pub fn OnFooEmpty() -> T::Balance { - 3.into() - } - - /// Some documentation - #[pallet::storage] - #[pallet::getter(fn dummy)] - type Dummy = StorageValue<_, T::Balance, OptionQuery>; - - #[pallet::storage] - #[pallet::getter(fn bar)] - pub(crate) type Bar = StorageMap<_, Blake2_128Concat, T::AccountId, T::Balance, ValueQuery>; - - #[pallet::storage] - type Foo = StorageValue<_, T::Balance, ValueQuery, OnFooEmpty>; - - #[pallet::storage] - type Double = StorageDoubleMap<_, Blake2_128Concat, u32, Twox64Concat, u64, T::Balance, ValueQuery>; - - #[pallet::genesis_config] - pub struct GenesisConfig { - pub dummy: Option, - pub bar: Vec<(T::AccountId, T::Balance)>, - pub foo: T::Balance, - } - - impl Default for GenesisConfig { - fn default() -> Self { - GenesisConfig { - dummy: Default::default(), - bar: Default::default(), - foo: OnFooEmpty::::get(), - } - } - } - - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { - fn build(&self) { - if let Some(dummy) = self.dummy.as_ref() { - Dummy::::put(dummy); - } - for (k, v) in &self.bar { - Bar::::insert(k, v); - } - Foo::::put(&self.foo); - } - } - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::hooks] - impl Hooks for Pallet { - fn on_initialize(_n: T::BlockNumber) -> Weight { - Dummy::::put(T::Balance::from(10)); - 10 - } - - fn on_finalize(_n: T::BlockNumber) { - Dummy::::put(T::Balance::from(11)); - } - } - - #[pallet::call] - impl Pallet { - #[pallet::weight(>::into(new_value.clone()))] - pub fn set_dummy(origin: OriginFor, #[pallet::compact] new_value: T::Balance) -> DispatchResult { - ensure_root(origin)?; - - Dummy::::put(&new_value); - Self::deposit_event(Event::Dummy(new_value)); - - Ok(()) - } - } -} - -impl Pallet { - pub fn do_set_bar(who: &T::AccountId, amount: T::Balance) { - Bar::::insert(who, amount); - } -} diff --git a/blockchain/modules/example/src/mock.rs b/blockchain/modules/example/src/mock.rs deleted file mode 100644 index a7bedd60..00000000 --- a/blockchain/modules/example/src/mock.rs +++ /dev/null @@ -1,94 +0,0 @@ -// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم - -// This file is part of Setheum. - -// Copyright (C) 2019-Present Setheum Labs. -// 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 . - -//! Mocks for example module. - -#![cfg(test)] - -use crate as example; -use frame_support::pallet_prelude::GenesisBuild; -use frame_support::{construct_runtime, parameter_types}; - -parameter_types!( - pub const SomeConst: u64 = 10; - pub const BlockHashCount: u32 = 250; -); - -impl frame_system::Config for Runtime { - type BaseCallFilter = (); - type Origin = Origin; - type Index = u64; - type BlockNumber = u64; - type Call = Call; - type Hash = sp_runtime::testing::H256; - type Hashing = sp_runtime::traits::BlakeTwo256; - type AccountId = u64; - type Lookup = sp_runtime::traits::IdentityLookup; - type Header = sp_runtime::testing::Header; - type Event = Event; - type BlockHashCount = BlockHashCount; - type BlockWeights = (); - type BlockLength = (); - type DbWeight = (); - type Version = (); - type PalletInfo = PalletInfo; - type AccountData = (); - type OnNewAccount = (); - type OnKilledAccount = (); - type SystemWeightInfo = (); - type SS58Prefix = (); - type OnSetCode = (); -} - -impl example::Config for Runtime { - type Event = Event; - type SomeConst = SomeConst; - type Balance = u64; -} - -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; -type Block = frame_system::mocking::MockBlock; - -construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic - { - System: frame_system::{Pallet, Call, Event}, - // NOTE: name Example here is needed in order to have same module prefix - Example: example::{Pallet, Call, Event, Config, Storage}, - } -); - -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() - .unwrap(); - example::GenesisConfig:: { - bar: vec![(1, 100), (2, 200)], - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} diff --git a/blockchain/modules/example/src/tests.rs b/blockchain/modules/example/src/tests.rs deleted file mode 100644 index ddca1c29..00000000 --- a/blockchain/modules/example/src/tests.rs +++ /dev/null @@ -1,45 +0,0 @@ -// بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم - -// This file is part of Setheum. - -// Copyright (C) 2019-Present Setheum Labs. -// 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 . - -//! Unit tests for example module. - -#![cfg(test)] - -use crate::mock::*; -use frame_support::assert_ok; - -#[test] -fn set_dummy_work() { - new_test_ext().execute_with(|| { - assert_eq!(Example::dummy(), None); - assert_ok!(Example::set_dummy(Origin::root(), 20)); - assert_eq!(Example::dummy(), Some(20)); - System::assert_last_event(Event::Example(crate::Event::Dummy(20))); - }); -} - -#[test] -fn do_set_bar_work() { - new_test_ext().execute_with(|| { - assert_eq!(Example::bar(2), 200); - Example::do_set_bar(&2, 10); - assert_eq!(Example::bar(2), 10); - }); -}