This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
536 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
[package] | ||
name = "pallet-bounties" | ||
version = "2.0.0-dev" | ||
authors = ["Parity Technologies <[email protected]>"] | ||
edition = "2018" | ||
license = "GPL-3.0" | ||
homepage = "https://substrate.dev" | ||
repository = "https://github.com/paritytech/substrate/" | ||
description = "FRAME bounties pallet" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
serde = { version = "1.0.101", optional = true } | ||
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } | ||
frame-support = { version = "2.0.0-dev", default-features = false, path = "../support" } | ||
frame-system = { version = "2.0.0-dev", default-features = false, path = "../system" } | ||
sp-core = { version = "2.0.0-dev", default-features = false, path = "../../primitives/core" } | ||
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../primitives/runtime" } | ||
sp-std = { version = "2.0.0-dev", default-features = false, path = "../../primitives/std" } | ||
sp-io = { version = "2.0.0-dev", default-features = false, path = "../../primitives/io" } | ||
|
||
frame-benchmarking = { version = "2.0.0-dev", default-features = false, path = "../benchmarking", optional = true } | ||
|
||
[dev-dependencies] | ||
sp-core = { version = "2.0.0-dev", path = "../../primitives/core" } | ||
pallet-balances = { version = "2.0.0-dev", path = "../balances" } | ||
|
||
[features] | ||
default = ["std"] | ||
std = [ | ||
"serde", | ||
"codec/std", | ||
"sp-runtime/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"sp-io/std", | ||
"sp-std/std" | ||
] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking", | ||
"frame-support/runtime-benchmarks", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2019-2020 Parity Technologies (UK) Ltd. | ||
// This file is part of Substrate. | ||
|
||
// Substrate 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. | ||
|
||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
//! # Bounties Module | ||
//! The Bounties module implements a bugeting system for treasury spendings. | ||
//! The core idea is: | ||
//! > Delegation of the curation activity of Spending Proposals to an expert called a Curator | ||
//! | ||
//! - [`bounties::Trait`](./trait.Trait.html) | ||
//! - [`Call`](./enum.Call.html) | ||
//! | ||
//! ## Overview | ||
//! | ||
//! TODO: | ||
//! | ||
//! ## Interface | ||
//! | ||
//! ### Dispatchable Functions | ||
//! | ||
//! TODO: | ||
//! | ||
//! [`Call`]: ./enum.Call.html | ||
//! [`Trait`]: ./trait.Trait.html | ||
// Ensure we're `no_std` when compiling for Wasm. | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
use sp_std::prelude::*; | ||
use codec::{Encode, Decode}; | ||
use sp_core::TypeId; | ||
use sp_io::hashing::blake2_256; | ||
use frame_support::{decl_module, decl_event, decl_error, decl_storage, Parameter, ensure, RuntimeDebug}; | ||
use frame_support::{ | ||
traits::{Get, ReservableCurrency, Currency, EnsureOrigin}, | ||
weights::{Weight, GetDispatchInfo, DispatchClass, FunctionOf}, | ||
dispatch::PostDispatchInfo, | ||
}; | ||
use frame_system::{self as system, ensure_signed}; | ||
use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable}; | ||
|
||
mod tests; | ||
|
||
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance; | ||
|
||
/// A bounty index. | ||
pub type BountyIndex = u32; | ||
|
||
/// Configuration trait. | ||
pub trait Trait: frame_system::Trait { | ||
/// The overarching event type. | ||
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>; | ||
|
||
/// The currency mechanism. | ||
type Currency: ReservableCurrency<Self::AccountId>; | ||
|
||
type ProposerOrigin: EnsureOrigin<Self::Origin>; | ||
} | ||
|
||
const MAX_BOUNTY_DESC_LENGTH: usize = 16384; | ||
|
||
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug)] | ||
pub struct Bounty<AccountId, Balance> { | ||
curator: AccountId, | ||
reward: Balance, | ||
description: Vec<u8>, | ||
} | ||
|
||
decl_storage! { | ||
trait Store for Module<T: Trait> as Utility { | ||
/// The number of bounties that have been made so far. | ||
pub BountyCount get(fn bounty_count): BountyCount; | ||
} | ||
} | ||
|
||
decl_error! { | ||
pub enum Error for Module<T: Trait> { | ||
} | ||
} | ||
|
||
decl_event! { | ||
/// Events type. | ||
pub enum Event<T> where | ||
AccountId = <T as system::Trait>::AccountId, | ||
BlockNumber = <T as system::Trait>::BlockNumber, | ||
{ | ||
|
||
} | ||
} | ||
|
||
decl_module! { | ||
pub struct Module<T: Trait> for enum Call where origin: T::Origin { | ||
type Error = Error<T>; | ||
|
||
/// Deposit one of this module's events by using the default implementation. | ||
fn deposit_event() = default; | ||
|
||
#[weight = SimpleDispatchInfo::default()] | ||
fn create_bounty(origin) { | ||
|
||
} | ||
} | ||
} | ||
|
||
impl<T: Trait> Module<T> { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
// Copyright 2019-2020 Parity Technologies (UK) Ltd. | ||
// This file is part of Substrate. | ||
|
||
// Substrate 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. | ||
|
||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
// Tests for Utility Pallet | ||
|
||
#![cfg(test)] | ||
|
||
use super::*; | ||
|
||
use frame_support::{ | ||
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch, | ||
weights::Weight, impl_outer_event | ||
}; | ||
use sp_core::H256; | ||
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header}; | ||
use crate as utility; | ||
|
||
impl_outer_origin! { | ||
pub enum Origin for Test where system = frame_system {} | ||
} | ||
|
||
impl_outer_event! { | ||
pub enum TestEvent for Test { | ||
system<T>, | ||
pallet_balances<T>, | ||
utility<T>, | ||
} | ||
} | ||
impl_outer_dispatch! { | ||
pub enum Call for Test where origin: Origin { | ||
frame_system::System, | ||
pallet_balances::Balances, | ||
utility::Utility, | ||
} | ||
} | ||
|
||
// For testing the pallet, we construct most of a mock runtime. This means | ||
// first constructing a configuration type (`Test`) which `impl`s each of the | ||
// configuration traits of pallets we want to use. | ||
#[derive(Clone, Eq, PartialEq)] | ||
pub struct Test; | ||
parameter_types! { | ||
pub const BlockHashCount: u64 = 250; | ||
pub const MaximumBlockWeight: Weight = 1024; | ||
pub const MaximumBlockLength: u32 = 2 * 1024; | ||
pub const AvailableBlockRatio: Perbill = Perbill::one(); | ||
} | ||
impl frame_system::Trait for Test { | ||
type Origin = Origin; | ||
type Index = u64; | ||
type BlockNumber = u64; | ||
type Hash = H256; | ||
type Call = Call; | ||
type Hashing = BlakeTwo256; | ||
type AccountId = u64; | ||
type Lookup = IdentityLookup<Self::AccountId>; | ||
type Header = Header; | ||
type Event = TestEvent; | ||
type BlockHashCount = BlockHashCount; | ||
type MaximumBlockWeight = MaximumBlockWeight; | ||
type DbWeight = (); | ||
type MaximumBlockLength = MaximumBlockLength; | ||
type AvailableBlockRatio = AvailableBlockRatio; | ||
type Version = (); | ||
type ModuleToIndex = (); | ||
type AccountData = pallet_balances::AccountData<u64>; | ||
type OnNewAccount = (); | ||
type OnKilledAccount = (); | ||
} | ||
parameter_types! { | ||
pub const ExistentialDeposit: u64 = 1; | ||
} | ||
impl pallet_balances::Trait for Test { | ||
type Balance = u64; | ||
type Event = TestEvent; | ||
type DustRemoval = (); | ||
type ExistentialDeposit = ExistentialDeposit; | ||
type AccountStore = System; | ||
} | ||
parameter_types! { | ||
pub const MultisigDepositBase: u64 = 1; | ||
pub const MultisigDepositFactor: u64 = 1; | ||
pub const MaxSignatories: u16 = 3; | ||
} | ||
impl Trait for Test { | ||
type Event = TestEvent; | ||
type Currency = Balances; | ||
} | ||
type System = frame_system::Module<Test>; | ||
type Balances = pallet_balances::Module<Test>; | ||
type Utility = Module<Test>; | ||
|
||
use pallet_balances::Call as BalancesCall; | ||
use pallet_balances::Error as BalancesError; | ||
|
||
pub fn new_test_ext() -> sp_io::TestExternalities { | ||
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap(); | ||
pallet_balances::GenesisConfig::<Test> { | ||
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 10)], | ||
}.assimilate_storage(&mut t).unwrap(); | ||
let mut ext = sp_io::TestExternalities::new(t); | ||
ext.execute_with(|| System::set_block_number(1)); | ||
ext | ||
} | ||
|
||
fn last_event() -> TestEvent { | ||
system::Module::<Test>::events().pop().map(|e| e.event).expect("Event expected") | ||
} | ||
|
||
fn expect_event<E: Into<TestEvent>>(e: E) { | ||
assert_eq!(last_event(), e.into()); | ||
} | ||
|
||
fn now() -> Timepoint<u64> { | ||
Utility::timepoint() | ||
} | ||
|
||
#[test] | ||
fn test() { | ||
new_test_ext().execute_with(|| { | ||
|
||
}); | ||
} | ||
|
Oops, something went wrong.