diff --git a/democracy/src/mock.rs b/democracy/src/mock.rs index ffa4df7d..1bb81c1e 100644 --- a/democracy/src/mock.rs +++ b/democracy/src/mock.rs @@ -17,8 +17,8 @@ use crate as dut; use encointer_primitives::{balances::BalanceType, scheduler::CeremonyPhaseType}; use sp_runtime::{ - traits::{ConstU128, ConstU64}, - BuildStorage, + traits::{ConstU128, ConstU64}, + BuildStorage, }; use test_utils::*; @@ -45,14 +45,14 @@ frame_support::construct_runtime!( // } impl dut::Config for TestRuntime { - type RuntimeEvent = RuntimeEvent; - type MaxReputationCount = ConstU32<10>; - // 10 6s blocks - type ConfirmationPeriod = ConstU64<60000>; - // 40 6s blocks - type ProposalLifetime = ConstU64<240000>; - type MinTurnout = ConstU128<20>; // 2% - type WeightInfo = (); // 2% + type RuntimeEvent = RuntimeEvent; + type MaxReputationCount = ConstU32<10>; + // 10 6s blocks + type ConfirmationPeriod = ConstU64<60000>; + // 40 6s blocks + type ProposalLifetime = ConstU64<240000>; + type MinTurnout = ConstU128<20>; // 2% + type WeightInfo = (); // 2% } // boilerplate @@ -68,45 +68,45 @@ impl_encointer_treasuries!(TestRuntime); // genesis values pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); + let mut t = frame_system::GenesisConfig::::default().build_storage().unwrap(); - dut::GenesisConfig:: { proposal_count: 0, ..Default::default() } - .assimilate_storage(&mut t) - .unwrap(); + dut::GenesisConfig:: { proposal_count: 0, ..Default::default() } + .assimilate_storage(&mut t) + .unwrap(); - pallet_encointer_scheduler::GenesisConfig:: { - current_ceremony_index: 7, - phase_durations: vec![ - (CeremonyPhaseType::Registering, ONE_DAY), - (CeremonyPhaseType::Assigning, ONE_DAY), - (CeremonyPhaseType::Attesting, ONE_DAY), - ], - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_encointer_scheduler::GenesisConfig:: { + current_ceremony_index: 7, + phase_durations: vec![ + (CeremonyPhaseType::Registering, ONE_DAY), + (CeremonyPhaseType::Assigning, ONE_DAY), + (CeremonyPhaseType::Attesting, ONE_DAY), + ], + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); - pallet_encointer_ceremonies::GenesisConfig:: { - ceremony_reward: BalanceType::from_num(1), - location_tolerance: LOCATION_TOLERANCE, // [m] - time_tolerance: TIME_TOLERANCE, // [ms] - inactivity_timeout: 12, - endorsement_tickets_per_bootstrapper: 50, - endorsement_tickets_per_reputable: 2, - reputation_lifetime: 5, - meetup_time_offset: 0, - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_encointer_ceremonies::GenesisConfig:: { + ceremony_reward: BalanceType::from_num(1), + location_tolerance: LOCATION_TOLERANCE, // [m] + time_tolerance: TIME_TOLERANCE, // [ms] + inactivity_timeout: 12, + endorsement_tickets_per_bootstrapper: 50, + endorsement_tickets_per_reputable: 2, + reputation_lifetime: 5, + meetup_time_offset: 0, + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); - pallet_encointer_communities::GenesisConfig:: { - min_solar_trip_time_s: 1, - max_speed_mps: 83, - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); + pallet_encointer_communities::GenesisConfig:: { + min_solar_trip_time_s: 1, + max_speed_mps: 83, + ..Default::default() + } + .assimilate_storage(&mut t) + .unwrap(); - t.into() + t.into() } diff --git a/treasuries/src/lib.rs b/treasuries/src/lib.rs index 432c99c7..37689b3d 100644 --- a/treasuries/src/lib.rs +++ b/treasuries/src/lib.rs @@ -19,8 +19,8 @@ use core::marker::PhantomData; use encointer_primitives::communities::CommunityIdentifier; use frame_support::{ - traits::{Currency, ExistenceRequirement::KeepAlive, Get}, - PalletId, + traits::{Currency, ExistenceRequirement::KeepAlive, Get}, + PalletId, }; use log::info; use parity_scale_codec::Decode; @@ -38,60 +38,60 @@ mod mock; mod tests; pub type BalanceOf = -<::Currency as Currency<::AccountId>>::Balance; + <::Currency as Currency<::AccountId>>::Balance; #[frame_support::pallet] pub mod pallet { - use super::*; - use frame_support::pallet_prelude::*; + use super::*; + use frame_support::pallet_prelude::*; - #[pallet::pallet] - pub struct Pallet(PhantomData); + #[pallet::pallet] + pub struct Pallet(PhantomData); - #[pallet::config] - pub trait Config: frame_system::Config { - type RuntimeEvent: From> + IsType<::RuntimeEvent>; - type Currency: Currency; + #[pallet::config] + pub trait Config: frame_system::Config { + type RuntimeEvent: From> + IsType<::RuntimeEvent>; + type Currency: Currency; - /// The treasuries' pallet id, used for deriving sovereign account IDs per community. - #[pallet::constant] - type PalletId: Get; - } + /// The treasuries' pallet id, used for deriving sovereign account IDs per community. + #[pallet::constant] + type PalletId: Get; + } - impl Pallet - where - sp_core::H256: From<::Hash>, - T::AccountId: AsRef<[u8; 32]>, - { - pub fn get_community_treasury_account_unchecked( - maybecid: Option, - ) -> T::AccountId { - let treasury_identifier = - [::PalletId::get().0.as_slice(), maybecid.encode().as_slice()] - .concat(); - let treasury_id_hash: H256 = T::Hashing::hash_of(&treasury_identifier).into(); - T::AccountId::decode(&mut treasury_id_hash.as_bytes()) - .expect("32 bytes can always construct an AccountId32") - } + impl Pallet + where + sp_core::H256: From<::Hash>, + T::AccountId: AsRef<[u8; 32]>, + { + pub fn get_community_treasury_account_unchecked( + maybecid: Option, + ) -> T::AccountId { + let treasury_identifier = + [::PalletId::get().0.as_slice(), maybecid.encode().as_slice()] + .concat(); + let treasury_id_hash: H256 = T::Hashing::hash_of(&treasury_identifier).into(); + T::AccountId::decode(&mut treasury_id_hash.as_bytes()) + .expect("32 bytes can always construct an AccountId32") + } - /// returns the account id where remaining funds of closed faucets go - pub fn do_spend_native( - maybecid: Option, - beneficiary: T::AccountId, - amount: BalanceOf, - ) -> DispatchResultWithPostInfo { - let treasury = Self::get_community_treasury_account_unchecked(maybecid); - T::Currency::transfer(&treasury, &beneficiary, amount, KeepAlive)?; - info!(target: LOG, "treasury spent native: {:?}, {:?} to {:?}", maybecid, amount, beneficiary); - Self::deposit_event(Event::SpentNative { treasury, beneficiary, amount }); - Ok(().into()) - } - } + /// returns the account id where remaining funds of closed faucets go + pub fn do_spend_native( + maybecid: Option, + beneficiary: T::AccountId, + amount: BalanceOf, + ) -> DispatchResultWithPostInfo { + let treasury = Self::get_community_treasury_account_unchecked(maybecid); + T::Currency::transfer(&treasury, &beneficiary, amount, KeepAlive)?; + info!(target: LOG, "treasury spent native: {:?}, {:?} to {:?}", maybecid, amount, beneficiary); + Self::deposit_event(Event::SpentNative { treasury, beneficiary, amount }); + Ok(().into()) + } + } - #[pallet::event] - #[pallet::generate_deposit(pub (super) fn deposit_event)] - pub enum Event { - /// treasury spent native tokens from community `cid` to `beneficiary` amounting `amount` - SpentNative { treasury: T::AccountId, beneficiary: T::AccountId, amount: BalanceOf }, - } + #[pallet::event] + #[pallet::generate_deposit(pub (super) fn deposit_event)] + pub enum Event { + /// treasury spent native tokens from community `cid` to `beneficiary` amounting `amount` + SpentNative { treasury: T::AccountId, beneficiary: T::AccountId, amount: BalanceOf }, + } }