-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathlib.rs
61 lines (50 loc) · 1.76 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Provides the functionality to notify about the agreement concluded by majority of system participants.
#![cfg_attr(not(feature = "std"), no_std)]
use scale_info::prelude::string::String;
#[cfg(test)]
mod mock;
#[cfg(test)]
mod tests;
// Re-export pallet items so that they can be accessed from the crate namespace.
pub use pallet::*;
#[frame_support::pallet]
pub mod pallet {
use super::*;
use frame_support::pallet_prelude::*;
use frame_system::pallet_prelude::*;
#[pallet::config]
pub trait Config: frame_system::Config {
/// The overarching event type.
type Event: From<Event> + IsType<<Self as frame_system::Config>::Event>;
}
#[pallet::error]
pub enum Error<T> {
/// Attempting to emit an empty agreement.
EmptyAgreement,
/// Attempting to emit an agreement with an empty URL.
EmptyUrl,
}
#[pallet::pallet]
pub struct Pallet<T>(_);
#[pallet::call]
impl<T: Config> Pallet<T> {
/// Declares an agreement recognized by the majority of system participants.
#[pallet::weight(T::DbWeight::get().writes(1))]
pub fn agree(origin: OriginFor<T>, on: String, url: Option<String>) -> DispatchResult {
ensure_root(origin)?;
ensure!(!on.is_empty(), Error::<T>::EmptyAgreement);
ensure!(
!url.as_ref().map_or(false, String::is_empty),
Error::<T>::EmptyUrl
);
Self::deposit_event(Event::Agreed { on, url });
Ok(())
}
}
#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event {
/// Defines an agreement concluded by majority of system participants.
Agreed { on: String, url: Option<String> },
}
}