git.delta.rocks / unique-network / refs/commits / ebc4cdb8a3c4

difftreelog

add force methods for collection in `Unique` , add events Stake, Unstake, SetAdmin

PraetorP2022-09-05parent: #9704432.patch.diff
in: master

8 files changed

modifiedCargo.lockdiffbeforeafterboth
64736473
6474[[package]]6474[[package]]
6475name = "pallet-unique"6475name = "pallet-unique"
6476version = "0.1.3"6476version = "0.1.4"
6477dependencies = [6477dependencies = [
6478 "ethereum",6478 "ethereum",
6479 "evm-coder",6479 "evm-coder",
modifiedpallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth
5454
55 payout_stakers{55 payout_stakers{
56 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);56 let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
57 let share = Perbill::from_rational(1u32, 10);57 let share = Perbill::from_rational(1u32, 100);
58 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;58 PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
59 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());59 let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
60 let staker: T::AccountId = account("caller", 0, SEED);60 let staker: T::AccountId = account("caller", 0, SEED);
modifiedpallets/app-promotion/src/lib.rsdiffbeforeafterboth
75type BalanceOf<T> =76type BalanceOf<T> =
76 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;77 <<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance;
77
78// const SECONDS_TO_BLOCK: u32 = 6;
79// const DAY: u32 = 60 * 60 * 24 / SECONDS_TO_BLOCK;
80// const WEEK: u32 = 7 * DAY;
81// const TWO_WEEK: u32 = 2 * WEEK;
82// const YEAR: u32 = DAY * 365;
8378
84#[frame_support::pallet]79#[frame_support::pallet]
85pub mod pallet {80pub mod pallet {
115 #[pallet::constant]110 #[pallet::constant]
116 type PendingInterval: Get<Self::BlockNumber>;111 type PendingInterval: Get<Self::BlockNumber>;
117112
118 /// In chain blocks.113 // /// In chain blocks.
119 #[pallet::constant]114 // #[pallet::constant]
120 type Day: Get<Self::BlockNumber>; // useless115 // type Day: Get<Self::BlockNumber>; // useless
121116
122 #[pallet::constant]117 #[pallet::constant]
123 type Nominal: Get<BalanceOf<Self>>;118 type Nominal: Get<BalanceOf<Self>>;
150 /// Amount of accrued interest145 /// Amount of accrued interest
151 BalanceOf<T>,146 BalanceOf<T>,
152 ),147 ),
148 Stake(T::AccountId, BalanceOf<T>),
149 Unstake(T::AccountId, BalanceOf<T>),
150 SetAdmin(T::AccountId),
153 }151 }
154152
155 #[pallet::error]153 #[pallet::error]
205 ValueQuery,203 ValueQuery,
206 >;204 >;
207205
208 /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.206 // /// A block when app-promotion has started .I think this is redundant, because we only need `NextInterestBlock`.
209 #[pallet::storage]207 // #[pallet::storage]
210 pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;208 // pub type StartBlock<T: Config> = StorageValue<Value = T::BlockNumber, QueryKind = ValueQuery>;
211209
212 // /// Next target block when interest is recalculated210 // /// Next target block when interest is recalculated
213 // #[pallet::storage]211 // #[pallet::storage]
258
260 <Admin<T>>::set(Some(admin.as_sub().to_owned()));259 <Admin<T>>::set(Some(admin.as_sub().to_owned()));
260
261 Self::deposit_event(Event::SetAdmin(admin.as_sub().to_owned()));
261262
262 Ok(())263 Ok(())
263 }264 }
264
265 // #[pallet::weight(T::WeightInfo::start_app_promotion())]
266 // pub fn start_app_promotion(
267 // origin: OriginFor<T>,
268 // promotion_start_relay_block: Option<T::BlockNumber>,
269 // ) -> DispatchResult
270 // where
271 // <T as frame_system::Config>::BlockNumber: From<u32>,
272 // {
273 // ensure_root(origin)?;
274
275 // // Start app-promotion mechanics if it has not been yet initialized
276 // if <StartBlock<T>>::get() == 0u32.into() {
277 // let start_block = promotion_start_relay_block
278 // .unwrap_or(T::RelayBlockNumberProvider::current_block_number());
279
280 // // Set promotion global start block
281 // <StartBlock<T>>::set(start_block);
282
283 // <NextInterestBlock<T>>::set(start_block + T::RecalculationInterval::get());
284 // }
285
286 // Ok(())
287 // }
288
289 // #[pallet::weight(T::WeightInfo::stop_app_promotion())]
290 // pub fn stop_app_promotion(origin: OriginFor<T>) -> DispatchResult
291 // where
292 // <T as frame_system::Config>::BlockNumber: From<u32>,
293 // {
294 // ensure_root(origin)?;
295
296 // if <StartBlock<T>>::get() != 0u32.into() {
297 // <StartBlock<T>>::set(T::BlockNumber::default());
298 // <NextInterestBlock<T>>::set(T::BlockNumber::default());
299 // }
300
301 // Ok(())
302 // }
303265
304 #[pallet::weight(T::WeightInfo::stake())]266 #[pallet::weight(T::WeightInfo::stake())]
305 pub fn stake(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {267 pub fn stake(staker: OriginFor<T>, amount: BalanceOf<T>) -> DispatchResult {
351313
352 StakesPerAccount::<T>::mutate(&staker_id, |stakes| *stakes += 1);314 StakesPerAccount::<T>::mutate(&staker_id, |stakes| *stakes += 1);
315
316 Self::deposit_event(Event::Stake(staker_id, amount));
317
353 Ok(())318 Ok(())
354 }319 }
392357
393 StakesPerAccount::<T>::remove(&staker_id);358 StakesPerAccount::<T>::remove(&staker_id);
359
360 Self::deposit_event(Event::Unstake(staker_id, total_staked));
394361
395 Ok(None.into())362 Ok(None.into())
396 }363 }
modifiedpallets/app-promotion/src/types.rsdiffbeforeafterboth
55
6use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};6use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};
7use pallet_common::CollectionHandle;7use pallet_common::CollectionHandle;
8use pallet_unique::{Event as UniqueEvent, Error as UniqueError};8
9use sp_runtime::DispatchError;9use sp_runtime::DispatchError;
10use up_data_structs::{CollectionId, SponsorshipState};10use up_data_structs::{CollectionId, SponsorshipState};
11use sp_std::borrow::ToOwned;11use sp_std::borrow::ToOwned;
53 sponsor_id: Self::AccountId,53 sponsor_id: Self::AccountId,
54 collection_id: Self::CollectionId,54 collection_id: Self::CollectionId,
55 ) -> DispatchResult {55 ) -> DispatchResult {
56 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
57 target_collection.check_is_internal()?;
58 target_collection.set_sponsor(sponsor_id.clone())?;
59
60 Self::deposit_event(UniqueEvent::<T>::CollectionSponsorSet(
61 collection_id,
62 sponsor_id.clone(),
63 ));
64
65 ensure!(
66 target_collection.confirm_sponsorship(&sponsor_id)?,
67 UniqueError::<T>::ConfirmUnsetSponsorFail
68 );
69
70 Self::deposit_event(UniqueEvent::<T>::SponsorshipConfirmed(56 Self::force_set_sponsor(sponsor_id, collection_id)
71 collection_id,
72 sponsor_id,
73 ));
74
75 target_collection.save()
76 }57 }
7758
78 fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {59 fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {
79 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
80 target_collection.check_is_internal()?;
81 target_collection.sponsorship = SponsorshipState::Disabled;
82
83 Self::deposit_event(UniqueEvent::<T>::CollectionSponsorRemoved(collection_id));60 Self::force_remove_collection_sponsor(collection_id)
84
85 target_collection.save()
86 }61 }
8762
88 fn get_sponsor(63 fn get_sponsor(
modifiedpallets/unique/CHANGELOG.mddiffbeforeafterboth
3All notable changes to this project will be documented in this file.3All notable changes to this project will be documented in this file.
44
5<!-- bureaucrate goes here -->5<!-- bureaucrate goes here -->
6
7## [v0.1.4] 2022-09-5
8
9### Added
10
6## [v0.1.3] 2022-08-1611## [v0.1.3] 2022-08-16
712
8### Other changes13### Other changes
914
10- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a15- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a
1116
12- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf817- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8
1318
14- refactor: Remove `#[transactional]` from extrinsics 7fd36cea2f6e00c02c67ccc1de9649ae404efd3119- refactor: Remove `#[transactional]` from extrinsics 7fd36cea2f6e00c02c67ccc1de9649ae404efd31
1520
16Every extrinsic now runs in transaction implicitly, and21Every extrinsic now runs in transaction implicitly, and
17`#[transactional]` on pallet dispatchable is now meaningless22`#[transactional]` on pallet dispatchable is now meaningless
1823
19Upstream-Change: https://github.com/paritytech/substrate/issues/1080624Upstream-Change: https://github.com/paritytech/substrate/issues/10806
2025
21- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d97526- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d975
2227
23New methods allows to call `remove_prefix` with limit multiple times28New methods allows to call `remove_prefix` with limit multiple times
24in the same block29in the same block
2732
28Upstream-Change: https://github.com/paritytech/substrate/pull/1149033Upstream-Change: https://github.com/paritytech/substrate/pull/11490
2934
30- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b35- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
3136
32## [v0.1.1] - 2022-07-2537## [v0.1.1] - 2022-07-25
38
33### Added39### Added
40
34- Method for creating `ERC721Metadata` compatible NFT collection.41- Method for creating `ERC721Metadata` compatible NFT collection.
35- Method for creating `ERC721Metadata` compatible ReFungible collection.42- Method for creating `ERC721Metadata` compatible ReFungible collection.
36- Method for creating ReFungible collection.43- Method for creating ReFungible collection.
3744
modifiedpallets/unique/Cargo.tomldiffbeforeafterboth
9license = 'GPLv3'9license = 'GPLv3'
10name = 'pallet-unique'10name = 'pallet-unique'
11repository = 'https://github.com/UniqueNetwork/unique-chain'11repository = 'https://github.com/UniqueNetwork/unique-chain'
12version = "0.1.3"12version = "0.1.4"
1313
14[package.metadata.docs.rs]14[package.metadata.docs.rs]
15targets = ['x86_64-unknown-linux-gnu']15targets = ['x86_64-unknown-linux-gnu']
modifiedpallets/unique/src/lib.rsdiffbeforeafterboth
1104 }1104 }
1105}1105}
1106
1107impl<T: Config> Pallet<T> {
1108 pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {
1109 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
1110 target_collection.check_is_internal()?;
1111 target_collection.set_sponsor(sponsor.clone())?;
1112
1113 Self::deposit_event(Event::<T>::CollectionSponsorSet(
1114 collection_id,
1115 sponsor.clone(),
1116 ));
1117
1118 ensure!(
1119 target_collection.confirm_sponsorship(&sponsor)?,
1120 Error::<T>::ConfirmUnsetSponsorFail
1121 );
1122
1123 Self::deposit_event(Event::<T>::SponsorshipConfirmed(collection_id, sponsor));
1124
1125 target_collection.save()
1126 }
1127
1128 pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {
1129 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
1130 target_collection.check_is_internal()?;
1131 target_collection.sponsorship = SponsorshipState::Disabled;
1132
1133 Self::deposit_event(Event::<T>::CollectionSponsorRemoved(collection_id));
1134
1135 target_collection.save()
1136 }
1137}
11061138
modifiedruntime/common/config/pallets/app_promotion.rsdiffbeforeafterboth
22use frame_support::{parameter_types, PalletId};22use frame_support::{parameter_types, PalletId};
23use sp_arithmetic::Perbill;23use sp_arithmetic::Perbill;
24use up_common::{24use up_common::{
25 constants::{DAYS, UNIQUE, RELAY_DAYS},25 constants::{ UNIQUE, RELAY_DAYS},
26 types::Balance,26 types::Balance,
27};27};
2828
32 pub const RecalculationInterval: BlockNumber = 20;32 pub const RecalculationInterval: BlockNumber = 20;
33 pub const PendingInterval: BlockNumber = 10;33 pub const PendingInterval: BlockNumber = 10;
34 pub const Nominal: Balance = UNIQUE;34 pub const Nominal: Balance = UNIQUE;
35 pub const Day: BlockNumber = DAYS;35 // pub const Day: BlockNumber = DAYS;
36 pub IntervalIncome: Perbill = Perbill::from_rational(RecalculationInterval::get(), RELAY_DAYS) * Perbill::from_rational(5u32, 10_000);36 pub IntervalIncome: Perbill = Perbill::from_rational(RecalculationInterval::get(), RELAY_DAYS) * Perbill::from_rational(5u32, 10_000);
37}37}
3838
42 pub const RecalculationInterval: BlockNumber = RELAY_DAYS;42 pub const RecalculationInterval: BlockNumber = RELAY_DAYS;
43 pub const PendingInterval: BlockNumber = 7 * RELAY_DAYS;43 pub const PendingInterval: BlockNumber = 7 * RELAY_DAYS;
44 pub const Nominal: Balance = UNIQUE;44 pub const Nominal: Balance = UNIQUE;
45 pub const Day: BlockNumber = RELAY_DAYS;45 // pub const Day: BlockNumber = RELAY_DAYS;
46 pub IntervalIncome: Perbill = Perbill::from_rational(5u32, 10_000);46 pub IntervalIncome: Perbill = Perbill::from_rational(5u32, 10_000);
47}47}
4848
56 type RelayBlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;56 type RelayBlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
57 type RecalculationInterval = RecalculationInterval;57 type RecalculationInterval = RecalculationInterval;
58 type PendingInterval = PendingInterval;58 type PendingInterval = PendingInterval;
59 type Day = Day;59 // type Day = Day;
60 type Nominal = Nominal;60 type Nominal = Nominal;
61 type IntervalIncome = IntervalIncome;61 type IntervalIncome = IntervalIncome;
62 type Event = Event;62 type Event = Event;