Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit f297a4f

Browse files
committed
bounties pallet
1 parent 1f31ad9 commit f297a4f

File tree

4 files changed

+536
-3
lines changed

4 files changed

+536
-3
lines changed

frame/bounties/Cargo.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[package]
2+
name = "pallet-bounties"
3+
version = "2.0.0-dev"
4+
authors = ["Parity Technologies <[email protected]>"]
5+
edition = "2018"
6+
license = "GPL-3.0"
7+
homepage = "https://substrate.dev"
8+
repository = "https://github.com/paritytech/substrate/"
9+
description = "FRAME bounties pallet"
10+
11+
[package.metadata.docs.rs]
12+
targets = ["x86_64-unknown-linux-gnu"]
13+
14+
[dependencies]
15+
serde = { version = "1.0.101", optional = true }
16+
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
17+
frame-support = { version = "2.0.0-dev", default-features = false, path = "../support" }
18+
frame-system = { version = "2.0.0-dev", default-features = false, path = "../system" }
19+
sp-core = { version = "2.0.0-dev", default-features = false, path = "../../primitives/core" }
20+
sp-runtime = { version = "2.0.0-dev", default-features = false, path = "../../primitives/runtime" }
21+
sp-std = { version = "2.0.0-dev", default-features = false, path = "../../primitives/std" }
22+
sp-io = { version = "2.0.0-dev", default-features = false, path = "../../primitives/io" }
23+
24+
frame-benchmarking = { version = "2.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
25+
26+
[dev-dependencies]
27+
sp-core = { version = "2.0.0-dev", path = "../../primitives/core" }
28+
pallet-balances = { version = "2.0.0-dev", path = "../balances" }
29+
30+
[features]
31+
default = ["std"]
32+
std = [
33+
"serde",
34+
"codec/std",
35+
"sp-runtime/std",
36+
"frame-support/std",
37+
"frame-system/std",
38+
"sp-io/std",
39+
"sp-std/std"
40+
]
41+
runtime-benchmarks = [
42+
"frame-benchmarking",
43+
"frame-support/runtime-benchmarks",
44+
]

frame/bounties/src/lib.rs

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate.
3+
4+
// Substrate is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Substrate is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
16+
17+
//! # Bounties Module
18+
//! The Bounties module implements a bugeting system for treasury spendings.
19+
//! The core idea is:
20+
//! > Delegation of the curation activity of Spending Proposals to an expert called a Curator
21+
//!
22+
//! - [`bounties::Trait`](./trait.Trait.html)
23+
//! - [`Call`](./enum.Call.html)
24+
//!
25+
//! ## Overview
26+
//!
27+
//! TODO:
28+
//!
29+
//! ## Interface
30+
//!
31+
//! ### Dispatchable Functions
32+
//!
33+
//! TODO:
34+
//!
35+
//! [`Call`]: ./enum.Call.html
36+
//! [`Trait`]: ./trait.Trait.html
37+
38+
// Ensure we're `no_std` when compiling for Wasm.
39+
#![cfg_attr(not(feature = "std"), no_std)]
40+
41+
use sp_std::prelude::*;
42+
use codec::{Encode, Decode};
43+
use sp_core::TypeId;
44+
use sp_io::hashing::blake2_256;
45+
use frame_support::{decl_module, decl_event, decl_error, decl_storage, Parameter, ensure, RuntimeDebug};
46+
use frame_support::{
47+
traits::{Get, ReservableCurrency, Currency, EnsureOrigin},
48+
weights::{Weight, GetDispatchInfo, DispatchClass, FunctionOf},
49+
dispatch::PostDispatchInfo,
50+
};
51+
use frame_system::{self as system, ensure_signed};
52+
use sp_runtime::{DispatchError, DispatchResult, traits::Dispatchable};
53+
54+
mod tests;
55+
56+
type BalanceOf<T> = <<T as Trait>::Currency as Currency<<T as frame_system::Trait>::AccountId>>::Balance;
57+
58+
/// A bounty index.
59+
pub type BountyIndex = u32;
60+
61+
/// Configuration trait.
62+
pub trait Trait: frame_system::Trait {
63+
/// The overarching event type.
64+
type Event: From<Event<Self>> + Into<<Self as frame_system::Trait>::Event>;
65+
66+
/// The currency mechanism.
67+
type Currency: ReservableCurrency<Self::AccountId>;
68+
69+
type ProposerOrigin: EnsureOrigin<Self::Origin>;
70+
}
71+
72+
const MAX_BOUNTY_DESC_LENGTH: usize = 16384;
73+
74+
#[derive(Copy, Clone, Eq, PartialEq, Encode, Decode, Default, RuntimeDebug)]
75+
pub struct Bounty<AccountId, Balance> {
76+
curator: AccountId,
77+
reward: Balance,
78+
description: Vec<u8>,
79+
}
80+
81+
decl_storage! {
82+
trait Store for Module<T: Trait> as Utility {
83+
/// The number of bounties that have been made so far.
84+
pub BountyCount get(fn bounty_count): BountyCount;
85+
}
86+
}
87+
88+
decl_error! {
89+
pub enum Error for Module<T: Trait> {
90+
}
91+
}
92+
93+
decl_event! {
94+
/// Events type.
95+
pub enum Event<T> where
96+
AccountId = <T as system::Trait>::AccountId,
97+
BlockNumber = <T as system::Trait>::BlockNumber,
98+
{
99+
100+
}
101+
}
102+
103+
decl_module! {
104+
pub struct Module<T: Trait> for enum Call where origin: T::Origin {
105+
type Error = Error<T>;
106+
107+
/// Deposit one of this module's events by using the default implementation.
108+
fn deposit_event() = default;
109+
110+
#[weight = SimpleDispatchInfo::default()]
111+
fn create_bounty(origin) {
112+
113+
}
114+
}
115+
}
116+
117+
impl<T: Trait> Module<T> {
118+
119+
}

frame/bounties/src/tests.rs

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// Copyright 2019-2020 Parity Technologies (UK) Ltd.
2+
// This file is part of Substrate.
3+
4+
// Substrate is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
9+
// Substrate is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
14+
// You should have received a copy of the GNU General Public License
15+
// along with Substrate. If not, see <http://www.gnu.org/licenses/>.
16+
17+
// Tests for Utility Pallet
18+
19+
#![cfg(test)]
20+
21+
use super::*;
22+
23+
use frame_support::{
24+
assert_ok, assert_noop, impl_outer_origin, parameter_types, impl_outer_dispatch,
25+
weights::Weight, impl_outer_event
26+
};
27+
use sp_core::H256;
28+
use sp_runtime::{Perbill, traits::{BlakeTwo256, IdentityLookup}, testing::Header};
29+
use crate as utility;
30+
31+
impl_outer_origin! {
32+
pub enum Origin for Test where system = frame_system {}
33+
}
34+
35+
impl_outer_event! {
36+
pub enum TestEvent for Test {
37+
system<T>,
38+
pallet_balances<T>,
39+
utility<T>,
40+
}
41+
}
42+
impl_outer_dispatch! {
43+
pub enum Call for Test where origin: Origin {
44+
frame_system::System,
45+
pallet_balances::Balances,
46+
utility::Utility,
47+
}
48+
}
49+
50+
// For testing the pallet, we construct most of a mock runtime. This means
51+
// first constructing a configuration type (`Test`) which `impl`s each of the
52+
// configuration traits of pallets we want to use.
53+
#[derive(Clone, Eq, PartialEq)]
54+
pub struct Test;
55+
parameter_types! {
56+
pub const BlockHashCount: u64 = 250;
57+
pub const MaximumBlockWeight: Weight = 1024;
58+
pub const MaximumBlockLength: u32 = 2 * 1024;
59+
pub const AvailableBlockRatio: Perbill = Perbill::one();
60+
}
61+
impl frame_system::Trait for Test {
62+
type Origin = Origin;
63+
type Index = u64;
64+
type BlockNumber = u64;
65+
type Hash = H256;
66+
type Call = Call;
67+
type Hashing = BlakeTwo256;
68+
type AccountId = u64;
69+
type Lookup = IdentityLookup<Self::AccountId>;
70+
type Header = Header;
71+
type Event = TestEvent;
72+
type BlockHashCount = BlockHashCount;
73+
type MaximumBlockWeight = MaximumBlockWeight;
74+
type DbWeight = ();
75+
type MaximumBlockLength = MaximumBlockLength;
76+
type AvailableBlockRatio = AvailableBlockRatio;
77+
type Version = ();
78+
type ModuleToIndex = ();
79+
type AccountData = pallet_balances::AccountData<u64>;
80+
type OnNewAccount = ();
81+
type OnKilledAccount = ();
82+
}
83+
parameter_types! {
84+
pub const ExistentialDeposit: u64 = 1;
85+
}
86+
impl pallet_balances::Trait for Test {
87+
type Balance = u64;
88+
type Event = TestEvent;
89+
type DustRemoval = ();
90+
type ExistentialDeposit = ExistentialDeposit;
91+
type AccountStore = System;
92+
}
93+
parameter_types! {
94+
pub const MultisigDepositBase: u64 = 1;
95+
pub const MultisigDepositFactor: u64 = 1;
96+
pub const MaxSignatories: u16 = 3;
97+
}
98+
impl Trait for Test {
99+
type Event = TestEvent;
100+
type Currency = Balances;
101+
}
102+
type System = frame_system::Module<Test>;
103+
type Balances = pallet_balances::Module<Test>;
104+
type Utility = Module<Test>;
105+
106+
use pallet_balances::Call as BalancesCall;
107+
use pallet_balances::Error as BalancesError;
108+
109+
pub fn new_test_ext() -> sp_io::TestExternalities {
110+
let mut t = frame_system::GenesisConfig::default().build_storage::<Test>().unwrap();
111+
pallet_balances::GenesisConfig::<Test> {
112+
balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 10)],
113+
}.assimilate_storage(&mut t).unwrap();
114+
let mut ext = sp_io::TestExternalities::new(t);
115+
ext.execute_with(|| System::set_block_number(1));
116+
ext
117+
}
118+
119+
fn last_event() -> TestEvent {
120+
system::Module::<Test>::events().pop().map(|e| e.event).expect("Event expected")
121+
}
122+
123+
fn expect_event<E: Into<TestEvent>>(e: E) {
124+
assert_eq!(last_event(), e.into());
125+
}
126+
127+
fn now() -> Timepoint<u64> {
128+
Utility::timepoint()
129+
}
130+
131+
#[test]
132+
fn test() {
133+
new_test_ext().execute_with(|| {
134+
135+
});
136+
}
137+

0 commit comments

Comments
 (0)