git.delta.rocks / unique-network / refs/commits / 31e089cf67a7

difftreelog

fixup contract helpers

Yaroslav Bolyukin2021-07-27parent: #1197b67.patch.diff
in: master

1 file changed

modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
before · pallets/evm-contract-helpers/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23pub use pallet::*;4pub use eth::*;5pub mod eth;67#[frame_support::pallet]8pub mod pallet {9	use evm_coder::execution::Result;10	use frame_support::pallet_prelude::*;11	use pallet_evm::RawEvent;12	use sp_core::H160;1314	#[pallet::config]15	pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {16		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;1718		type ContractAddress: Get<H160>;19	}2021	#[pallet::error]22	pub enum Error<T> {23		/// This method is only executable by owner24		NoPermission,25	}2627	#[pallet::pallet]28	#[pallet::generate_store(pub(super) trait Store)]29	pub struct Pallet<T>(_);3031	#[pallet::storage]32	pub(super) type Owner<T: Config> =33		StorageMap<Hasher = Twox128, Key = H160, Value = H160, QueryKind = ValueQuery>;3435	#[pallet::storage]36	pub(super) type SelfSponsoring<T: Config> =37		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;3839	#[pallet::storage]40	pub(super) type SponsoringRateLimit<T: Config> =41		StorageMap<Hasher = Twox128, Key = H160, Value = T::BlockNumber, QueryKind = ValueQuery>;4243	#[pallet::storage]44	pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<45		Hasher1 = Twox128,46		Key1 = H160,47		Hasher2 = Twox128,48		Key2 = H160,49		Value = T::BlockNumber,50		QueryKind = OptionQuery,51	>;5253	#[pallet::storage]54	pub(super) type AllowlistEnabled<T: Config> =55		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;5657	#[pallet::storage]58	pub(super) type Allowlist<T: Config> = StorageDoubleMap<59		Hasher1 = Twox128,60		Key1 = H160,61		Hasher2 = Twox128,62		Key2 = H160,63		Value = bool,64		QueryKind = ValueQuery,65	>;6667	impl<T: Config> Pallet<T> {68		pub fn toggle_sponsoring(contract: H160, enabled: bool) {69			<SelfSponsoring<T>>::insert(contract, enabled);70		}7172		pub fn allowed(contract: H160, user: H160) -> bool {73			if !<AllowlistEnabled<T>>::get(contract) {74				return true;75			}76			<Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user77		}7879		pub fn toggle_allowlist(contract: H160, enabled: bool) {80			<AllowlistEnabled<T>>::insert(contract, enabled)81		}8283		pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {84			<Allowlist<T>>::insert(contract, user, allowed);85		}8687		pub fn ensure_owner(contract: H160, user: H160) -> Result<()> {88			ensure!(<Owner<T>>::get(&contract) == user, "no permission");89			Ok(())90		}91	}92}
after · pallets/evm-contract-helpers/src/lib.rs
1#![cfg_attr(not(feature = "std"), no_std)]23pub use pallet::*;4pub use eth::*;5pub mod eth;67#[frame_support::pallet]8pub mod pallet {9	use evm_coder::execution::Result;10	use frame_support::pallet_prelude::*;11	use sp_core::H160;1213	#[pallet::config]14	pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {15		type ContractAddress: Get<H160>;16	}1718	#[pallet::error]19	pub enum Error<T> {20		/// This method is only executable by owner21		NoPermission,22	}2324	#[pallet::pallet]25	#[pallet::generate_store(pub(super) trait Store)]26	pub struct Pallet<T>(_);2728	#[pallet::storage]29	pub(super) type Owner<T: Config> =30		StorageMap<Hasher = Twox128, Key = H160, Value = H160, QueryKind = ValueQuery>;3132	#[pallet::storage]33	pub(super) type SelfSponsoring<T: Config> =34		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;3536	#[pallet::storage]37	pub(super) type SponsoringRateLimit<T: Config> =38		StorageMap<Hasher = Twox128, Key = H160, Value = T::BlockNumber, QueryKind = ValueQuery>;3940	#[pallet::storage]41	pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<42		Hasher1 = Twox128,43		Key1 = H160,44		Hasher2 = Twox128,45		Key2 = H160,46		Value = T::BlockNumber,47		QueryKind = OptionQuery,48	>;4950	#[pallet::storage]51	pub(super) type AllowlistEnabled<T: Config> =52		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;5354	#[pallet::storage]55	pub(super) type Allowlist<T: Config> = StorageDoubleMap<56		Hasher1 = Twox128,57		Key1 = H160,58		Hasher2 = Twox128,59		Key2 = H160,60		Value = bool,61		QueryKind = ValueQuery,62	>;6364	impl<T: Config> Pallet<T> {65		pub fn toggle_sponsoring(contract: H160, enabled: bool) {66			<SelfSponsoring<T>>::insert(contract, enabled);67		}6869		pub fn allowed(contract: H160, user: H160) -> bool {70			if !<AllowlistEnabled<T>>::get(contract) {71				return true;72			}73			<Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user74		}7576		pub fn toggle_allowlist(contract: H160, enabled: bool) {77			<AllowlistEnabled<T>>::insert(contract, enabled)78		}7980		pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {81			<Allowlist<T>>::insert(contract, user, allowed);82		}8384		pub fn ensure_owner(contract: H160, user: H160) -> Result<()> {85			ensure!(<Owner<T>>::get(&contract) == user, "no permission");86			Ok(())87		}88	}89}