difftreelog
add force methods for collection in `Unique` , add events Stake, Unstake, SetAdmin
in: master
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -6473,7 +6473,7 @@
[[package]]
name = "pallet-unique"
-version = "0.1.3"
+version = "0.1.4"
dependencies = [
"ethereum",
"evm-coder",
pallets/app-promotion/src/benchmarking.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/benchmarking.rs
+++ b/pallets/app-promotion/src/benchmarking.rs
@@ -54,7 +54,7 @@
payout_stakers{
let pallet_admin = account::<T::AccountId>("admin", 0, SEED);
- let share = Perbill::from_rational(1u32, 10);
+ let share = Perbill::from_rational(1u32, 100);
PromototionPallet::<T>::set_admin_address(RawOrigin::Root.into(), T::CrossAccountId::from_sub(pallet_admin.clone()))?;
let _ = <T as Config>::Currency::make_free_balance_be(&pallet_admin, Perbill::from_rational(1u32, 2) * BalanceOf::<T>::max_value());
let staker: T::AccountId = account("caller", 0, SEED);
pallets/app-promotion/src/lib.rsdiffbeforeafterboth75type 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;7778// 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;837884#[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>;117112118 /// 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>; // useless121116122 #[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 interest151 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 }154152155 #[pallet::error]153 #[pallet::error]205 ValueQuery,203 ValueQuery,206 >;204 >;207205208 /// 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>;211209212 // /// Next target block when interest is recalculated210 // /// Next target block when interest is recalculated213 // #[pallet::storage]211 // #[pallet::storage]258260 <Admin<T>>::set(Some(admin.as_sub().to_owned()));259 <Admin<T>>::set(Some(admin.as_sub().to_owned()));260261 Self::deposit_event(Event::SetAdmin(admin.as_sub().to_owned()));261262262 Ok(())263 Ok(())263 }264 }264265 // #[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 // ) -> DispatchResult270 // where271 // <T as frame_system::Config>::BlockNumber: From<u32>,272 // {273 // ensure_root(origin)?;274275 // // Start app-promotion mechanics if it has not been yet initialized276 // if <StartBlock<T>>::get() == 0u32.into() {277 // let start_block = promotion_start_relay_block278 // .unwrap_or(T::RelayBlockNumberProvider::current_block_number());279280 // // Set promotion global start block281 // <StartBlock<T>>::set(start_block);282283 // <NextInterestBlock<T>>::set(start_block + T::RecalculationInterval::get());284 // }285286 // Ok(())287 // }288289 // #[pallet::weight(T::WeightInfo::stop_app_promotion())]290 // pub fn stop_app_promotion(origin: OriginFor<T>) -> DispatchResult291 // where292 // <T as frame_system::Config>::BlockNumber: From<u32>,293 // {294 // ensure_root(origin)?;295296 // if <StartBlock<T>>::get() != 0u32.into() {297 // <StartBlock<T>>::set(T::BlockNumber::default());298 // <NextInterestBlock<T>>::set(T::BlockNumber::default());299 // }300301 // Ok(())302 // }303265304 #[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 {351313352 StakesPerAccount::<T>::mutate(&staker_id, |stakes| *stakes += 1);314 StakesPerAccount::<T>::mutate(&staker_id, |stakes| *stakes += 1);315316 Self::deposit_event(Event::Stake(staker_id, amount));317353 Ok(())318 Ok(())354 }319 }392357393 StakesPerAccount::<T>::remove(&staker_id);358 StakesPerAccount::<T>::remove(&staker_id);359360 Self::deposit_event(Event::Unstake(staker_id, total_staked));394361395 Ok(None.into())362 Ok(None.into())396 }363 }pallets/app-promotion/src/types.rsdiffbeforeafterboth--- a/pallets/app-promotion/src/types.rs
+++ b/pallets/app-promotion/src/types.rs
@@ -5,7 +5,7 @@
use pallet_balances::{BalanceLock, Config as BalancesConfig, Pallet as PalletBalances};
use pallet_common::CollectionHandle;
-use pallet_unique::{Event as UniqueEvent, Error as UniqueError};
+
use sp_runtime::DispatchError;
use up_data_structs::{CollectionId, SponsorshipState};
use sp_std::borrow::ToOwned;
@@ -53,36 +53,11 @@
sponsor_id: Self::AccountId,
collection_id: Self::CollectionId,
) -> DispatchResult {
- let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.set_sponsor(sponsor_id.clone())?;
-
- Self::deposit_event(UniqueEvent::<T>::CollectionSponsorSet(
- collection_id,
- sponsor_id.clone(),
- ));
-
- ensure!(
- target_collection.confirm_sponsorship(&sponsor_id)?,
- UniqueError::<T>::ConfirmUnsetSponsorFail
- );
-
- Self::deposit_event(UniqueEvent::<T>::SponsorshipConfirmed(
- collection_id,
- sponsor_id,
- ));
-
- target_collection.save()
+ Self::force_set_sponsor(sponsor_id, collection_id)
}
fn remove_collection_sponsor(collection_id: Self::CollectionId) -> DispatchResult {
- let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
- target_collection.check_is_internal()?;
- target_collection.sponsorship = SponsorshipState::Disabled;
-
- Self::deposit_event(UniqueEvent::<T>::CollectionSponsorRemoved(collection_id));
-
- target_collection.save()
+ Self::force_remove_collection_sponsor(collection_id)
}
fn get_sponsor(
pallets/unique/CHANGELOG.mddiffbeforeafterboth--- a/pallets/unique/CHANGELOG.md
+++ b/pallets/unique/CHANGELOG.md
@@ -3,22 +3,27 @@
All notable changes to this project will be documented in this file.
<!-- bureaucrate goes here -->
+
+## [v0.1.4] 2022-09-5
+
+### Added
+
## [v0.1.3] 2022-08-16
### Other changes
-- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a
+- build: Upgrade polkadot to v0.9.27 2c498572636f2b34d53b1c51b7283a761a7dc90a
-- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8
+- build: Upgrade polkadot to v0.9.26 85515e54c4ca1b82a2630034e55dcc804c643bf8
-- refactor: Remove `#[transactional]` from extrinsics 7fd36cea2f6e00c02c67ccc1de9649ae404efd31
+- refactor: Remove `#[transactional]` from extrinsics 7fd36cea2f6e00c02c67ccc1de9649ae404efd31
Every extrinsic now runs in transaction implicitly, and
`#[transactional]` on pallet dispatchable is now meaningless
Upstream-Change: https://github.com/paritytech/substrate/issues/10806
-- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d975
+- refactor: Switch to new prefix removal methods 26734e9567589d75cdd99e404eabf11d5a97d975
New methods allows to call `remove_prefix` with limit multiple times
in the same block
@@ -27,10 +32,12 @@
Upstream-Change: https://github.com/paritytech/substrate/pull/11490
-- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
+- build: Upgrade polkadot to v0.9.25 cdfb9bdc7b205ff1b5134f034ef9973d769e5e6b
## [v0.1.1] - 2022-07-25
+
### Added
-- Method for creating `ERC721Metadata` compatible NFT collection.
-- Method for creating `ERC721Metadata` compatible ReFungible collection.
-- Method for creating ReFungible collection.
+
+- Method for creating `ERC721Metadata` compatible NFT collection.
+- Method for creating `ERC721Metadata` compatible ReFungible collection.
+- Method for creating ReFungible collection.
pallets/unique/Cargo.tomldiffbeforeafterboth--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -9,7 +9,7 @@
license = 'GPLv3'
name = 'pallet-unique'
repository = 'https://github.com/UniqueNetwork/unique-chain'
-version = "0.1.3"
+version = "0.1.4"
[package.metadata.docs.rs]
targets = ['x86_64-unknown-linux-gnu']
pallets/unique/src/lib.rsdiffbeforeafterboth--- a/pallets/unique/src/lib.rs
+++ b/pallets/unique/src/lib.rs
@@ -1103,3 +1103,35 @@
}
}
}
+
+impl<T: Config> Pallet<T> {
+ pub fn force_set_sponsor(sponsor: T::AccountId, collection_id: CollectionId) -> DispatchResult {
+ let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
+ target_collection.check_is_internal()?;
+ target_collection.set_sponsor(sponsor.clone())?;
+
+ Self::deposit_event(Event::<T>::CollectionSponsorSet(
+ collection_id,
+ sponsor.clone(),
+ ));
+
+ ensure!(
+ target_collection.confirm_sponsorship(&sponsor)?,
+ Error::<T>::ConfirmUnsetSponsorFail
+ );
+
+ Self::deposit_event(Event::<T>::SponsorshipConfirmed(collection_id, sponsor));
+
+ target_collection.save()
+ }
+
+ pub fn force_remove_collection_sponsor(collection_id: CollectionId) -> DispatchResult {
+ let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;
+ target_collection.check_is_internal()?;
+ target_collection.sponsorship = SponsorshipState::Disabled;
+
+ Self::deposit_event(Event::<T>::CollectionSponsorRemoved(collection_id));
+
+ target_collection.save()
+ }
+}
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -22,7 +22,7 @@
use frame_support::{parameter_types, PalletId};
use sp_arithmetic::Perbill;
use up_common::{
- constants::{DAYS, UNIQUE, RELAY_DAYS},
+ constants::{ UNIQUE, RELAY_DAYS},
types::Balance,
};
@@ -32,7 +32,7 @@
pub const RecalculationInterval: BlockNumber = 20;
pub const PendingInterval: BlockNumber = 10;
pub const Nominal: Balance = UNIQUE;
- pub const Day: BlockNumber = DAYS;
+ // pub const Day: BlockNumber = DAYS;
pub IntervalIncome: Perbill = Perbill::from_rational(RecalculationInterval::get(), RELAY_DAYS) * Perbill::from_rational(5u32, 10_000);
}
@@ -42,7 +42,7 @@
pub const RecalculationInterval: BlockNumber = RELAY_DAYS;
pub const PendingInterval: BlockNumber = 7 * RELAY_DAYS;
pub const Nominal: Balance = UNIQUE;
- pub const Day: BlockNumber = RELAY_DAYS;
+ // pub const Day: BlockNumber = RELAY_DAYS;
pub IntervalIncome: Perbill = Perbill::from_rational(5u32, 10_000);
}
@@ -56,7 +56,7 @@
type RelayBlockNumberProvider = RelayChainBlockNumberProvider<Runtime>;
type RecalculationInterval = RecalculationInterval;
type PendingInterval = PendingInterval;
- type Day = Day;
+ // type Day = Day;
type Nominal = Nominal;
type IntervalIncome = IntervalIncome;
type Event = Event;