-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/bump v1.3.0 #25
Changes from all commits
21370f5
de38b35
c796692
6ac39b0
d53eb3e
9dfef1d
d384a53
17d6130
5e443de
711e290
8dc111c
64f1f0d
0187673
b05e7bf
ddc4779
d61dc78
1970cf8
13d45c2
d19802d
cb14366
abcf44e
14c8bbc
8cac63a
2bf4484
665298f
6466cef
6f90b30
d35fcfa
73cd134
1cca491
1c1b187
f99076b
5712308
8ddb136
3e7ff6c
9bfc152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use super::*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GPT summary of d4b906 - 6a0c05:
|
||
use crate::types::*; | ||
use frame_support::{pallet_prelude::*, traits::UnixTime}; | ||
use frame_support::pallet_prelude::*; | ||
use frame_system::{pallet_prelude::*, RawOrigin}; | ||
use pallet_fruniques::types::{Attributes, CollectionDescription, FruniqueRole, ParentInfo}; | ||
use pallet_gated_marketplace::types::{Marketplace, MarketplaceRole}; | ||
|
@@ -104,9 +104,10 @@ impl<T: Config> Pallet<T> { | |
cid_creator: ShortString::try_from(b"HCD:afloat".to_vec()).unwrap(), | ||
group: ShortString::try_from(b"afloat".to_vec()).unwrap(), | ||
created_by: Some(creator.clone()), | ||
created_date: Some(T::TimeProvider::now().as_secs()), | ||
created_date: pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
last_modified_by: Some(creator.clone()), | ||
last_modified_date: Some(T::TimeProvider::now().as_secs()), | ||
last_modified_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
}; | ||
<UserInfo<T>>::insert(creator.clone(), creator_user); | ||
Self::give_role_to_user(creator.clone(), AfloatRole::Owner)?; | ||
|
@@ -117,9 +118,11 @@ impl<T: Config> Pallet<T> { | |
cid_creator: ShortString::try_from(b"afloat".to_vec()).unwrap(), | ||
group: ShortString::try_from(b"afloat".to_vec()).unwrap(), | ||
created_by: Some(admin.clone()), | ||
created_date: Some(T::TimeProvider::now().as_secs()), | ||
created_date: pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds( | ||
), | ||
last_modified_by: Some(admin.clone()), | ||
last_modified_date: Some(T::TimeProvider::now().as_secs()), | ||
last_modified_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
}; | ||
<UserInfo<T>>::insert(admin.clone(), admin_user); | ||
Self::give_role_to_user(admin, AfloatRole::Admin)?; | ||
|
@@ -161,9 +164,11 @@ impl<T: Config> Pallet<T> { | |
cid_creator, | ||
group, | ||
created_by: Some(actor.clone()), | ||
created_date: Some(T::TimeProvider::now().as_secs()), | ||
created_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
last_modified_by: Some(actor.clone()), | ||
last_modified_date: Some(T::TimeProvider::now().as_secs()), | ||
last_modified_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
}; | ||
<UserInfo<T>>::insert(user_address.clone(), user); | ||
Self::give_role_to_user(user_address.clone(), AfloatRole::BuyerOrSeller)?; | ||
|
@@ -175,9 +180,11 @@ impl<T: Config> Pallet<T> { | |
cid_creator, | ||
group, | ||
created_by: Some(actor.clone()), | ||
created_date: Some(T::TimeProvider::now().as_secs()), | ||
created_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
last_modified_by: Some(actor.clone()), | ||
last_modified_date: Some(T::TimeProvider::now().as_secs()), | ||
last_modified_date: | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(), | ||
}; | ||
<UserInfo<T>>::insert(user_address.clone(), user); | ||
Self::give_role_to_user(user_address.clone(), AfloatRole::CPA)?; | ||
|
@@ -225,7 +232,8 @@ impl<T: Config> Pallet<T> { | |
<UserInfo<T>>::try_mutate::<_, _, DispatchError, _>(user_address.clone(), |user| { | ||
let user = user.as_mut().ok_or(Error::<T>::FailedToEditUserAccount)?; | ||
|
||
user.last_modified_date = Some(T::TimeProvider::now().as_secs()); | ||
user.last_modified_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
user.last_modified_by = Some(actor.clone()); | ||
user.cid = cid; | ||
user.cid_creator = cid_creator; | ||
|
@@ -246,7 +254,8 @@ impl<T: Config> Pallet<T> { | |
<UserInfo<T>>::try_mutate::<_, _, DispatchError, _>(user_address.clone(), |user| { | ||
let user = user.as_mut().ok_or(Error::<T>::FailedToEditUserAccount)?; | ||
|
||
user.last_modified_date = Some(T::TimeProvider::now().as_secs()); | ||
user.last_modified_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
user.last_modified_by = Some(actor.clone()); | ||
user.cid = cid; | ||
user.cid_creator = cid_creator; | ||
|
@@ -339,7 +348,7 @@ impl<T: Config> Pallet<T> { | |
tax_credit_amount, | ||
tax_credit_amount_remaining: tax_credit_amount.into(), | ||
price_per_credit: price, | ||
creation_date: T::TimeProvider::now().as_secs(), | ||
creation_date: T::Timestamp::now().into(), | ||
expiration_date, | ||
tax_credit_id: item_id, | ||
creator_id: authority.clone(), | ||
|
@@ -373,7 +382,7 @@ impl<T: Config> Pallet<T> { | |
tax_credit_amount, | ||
tax_credit_amount_remaining: tax_credit_amount.into(), | ||
price_per_credit: price, | ||
creation_date: T::TimeProvider::now().as_secs(), | ||
creation_date: T::Timestamp::now().into(), | ||
expiration_date, | ||
tax_credit_id: item_id, | ||
creator_id: authority.clone(), | ||
|
@@ -447,7 +456,7 @@ impl<T: Config> Pallet<T> { | |
//ensure offer is a sell offer | ||
ensure!(offer.offer_type == OfferType::Sell, Error::<T>::WrongOfferType); | ||
//ensure offer is not expired | ||
ensure!(offer.expiration_date > T::TimeProvider::now().as_secs(), Error::<T>::OfferExpired); | ||
ensure!(offer.expiration_date > T::Timestamp::now().into(), Error::<T>::OfferExpired); | ||
//ensure offer is not cancelled | ||
ensure!(offer.cancellation_date.is_none(), Error::<T>::OfferCancelled); | ||
//ensure offer is not taken | ||
|
@@ -963,7 +972,8 @@ impl<T: Config> Pallet<T> { | |
OfferStatus::CREATED => { | ||
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult { | ||
let offer = offer.as_mut().ok_or(Error::<T>::OfferNotFound)?; | ||
offer.cancellation_date = Some(T::TimeProvider::now().as_secs()); | ||
offer.cancellation_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
offer.status = OfferStatus::CANCELLED; | ||
Ok(()) | ||
})?; | ||
|
@@ -972,7 +982,8 @@ impl<T: Config> Pallet<T> { | |
OfferStatus::TF_PENDING_SIGNATURE => { | ||
<AfloatOffers<T>>::try_mutate(order_id, |offer| -> DispatchResult { | ||
let offer = offer.as_mut().ok_or(Error::<T>::OfferNotFound)?; | ||
offer.cancellation_date = Some(T::TimeProvider::now().as_secs()); | ||
offer.cancellation_date = | ||
pallet_gated_marketplace::Pallet::<T>::get_timestamp_in_milliseconds(); | ||
offer.status = OfferStatus::CANCELLED; | ||
Ok(()) | ||
})?; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,12 @@ pub mod types; | |
pub mod pallet { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
use frame_support::{ | ||
pallet_prelude::*, | ||
traits::{Currency, UnixTime}, | ||
traits::{Currency, Time}, | ||
}; | ||
use frame_system::{pallet_prelude::*, RawOrigin}; | ||
use pallet_fruniques::types::{Attributes, CollectionDescription, FruniqueRole, ParentInfo}; | ||
use pallet_gated_marketplace::types::*; | ||
use sp_runtime::traits::Scale; | ||
const STORAGE_VERSION: StorageVersion = StorageVersion::new(0); | ||
|
||
use crate::types::*; | ||
|
@@ -37,7 +38,7 @@ pub mod pallet { | |
+ pallet_uniques::Config | ||
{ | ||
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>; | ||
type TimeProvider: UnixTime; | ||
|
||
type Rbac: RoleBasedAccessControl<Self::AccountId>; | ||
// type RemoveOrigin: EnsureOrigin<Self::RuntimeOrigin>; | ||
type Currency: Currency<Self::AccountId>; | ||
|
@@ -54,6 +55,8 @@ pub mod pallet { | |
#[pallet::event] | ||
#[pallet::generate_deposit(pub(super) fn deposit_event)] | ||
pub enum Event<T: Config> { | ||
/// Timestamp was not generated correctly | ||
TimestampError, | ||
// New user created | ||
NewUser(T::AccountId), | ||
// User edited | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,6 @@ impl system::Config for Test { | |
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
impl pallet_afloat::Config for Test { | ||
type RuntimeEvent = RuntimeEvent; | ||
type TimeProvider = pallet_timestamp::Pallet<Self>; | ||
//type RemoveOrigin = frame_system::EnsureSigned<Self::AccountId>; | ||
type Currency = pallet_balances::Pallet<Self>; | ||
type Rbac = RBAC; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ mod tests; | |
// mod benchmarking; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
mod functions; | ||
pub mod migration; | ||
pub mod types; | ||
|
||
#[frame_support::pallet] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use crate::{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
types::{CollectionId, ItemId}, | ||
*, | ||
}; | ||
use frame_support::{pallet_prelude::*, traits::OnRuntimeUpgrade}; | ||
|
||
#[cfg(feature = "try-runtime")] | ||
use sp_runtime::TryRuntimeError; | ||
|
||
/// The log target. | ||
const TARGET: &'static str = "runtime::fruniques::migration"; | ||
|
||
pub mod v0 { | ||
use super::*; | ||
/// The actual type isn't important, as we only delete the key in the state. | ||
#[frame_support::storage_alias] | ||
pub(super) type FruniqueCnt<T: Config> = StorageValue<Pallet<T>, (), ValueQuery>; | ||
|
||
/// The actual type isn't important, as we only delete the key in the state. | ||
#[frame_support::storage_alias] | ||
pub(super) type FruniqueParent<T: Config> = StorageDoubleMap< | ||
Pallet<T>, | ||
Blake2_128Concat, | ||
CollectionId, | ||
Blake2_128Concat, | ||
ItemId, // FruniqueId | ||
(), // ParentId and flag if it inherit attributes | ||
ValueQuery, | ||
>; | ||
|
||
/// The actual type isn't important, as we only delete the key in the state. | ||
#[frame_support::storage_alias] | ||
pub(super) type FruniqueChild<T: Config> = StorageDoubleMap< | ||
Pallet<T>, | ||
Blake2_128Concat, | ||
CollectionId, | ||
Blake2_128Concat, | ||
ItemId, | ||
(), | ||
ValueQuery, | ||
>; | ||
|
||
pub struct MigrateToV1<T>(sp_runtime::sp_std::marker::PhantomData<T>); | ||
|
||
impl<T: Config> OnRuntimeUpgrade for MigrateToV1<T> { | ||
fn on_runtime_upgrade() -> Weight { | ||
let onchain_version = Pallet::<T>::on_chain_storage_version(); | ||
let mut writes = 0; | ||
if onchain_version < 1 { | ||
FruniqueCnt::<T>::kill(); | ||
let result = FruniqueParent::<T>::clear(1, None); //Assuming that the storage is empty | ||
if result.maybe_cursor.is_some() { | ||
log::info!(target: TARGET, "Failed to kill FruniqueParent storage item"); | ||
} | ||
let result = FruniqueChild::<T>::clear(1, None); //Assuming that the storage is empty | ||
if result.maybe_cursor.is_some() { | ||
log::info!(target: TARGET, "Failed to kill FruniqueChild storage item"); | ||
} | ||
StorageVersion::new(1).put::<Pallet<T>>(); | ||
writes = 4; | ||
log::info!(target: TARGET, "Migrated storage to version 1"); | ||
} else { | ||
log::info!(target: TARGET, "Upgrade not run as pallet version is: {:?}", onchain_version); | ||
} | ||
T::DbWeight::get().reads_writes(writes, 1) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1162,7 +1162,7 @@ impl<T: Config> Pallet<T> { | |
Ok(()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
fn get_timestamp_in_milliseconds() -> Option<u64> { | ||
pub fn get_timestamp_in_milliseconds() -> Option<u64> { | ||
let timestamp: u64 = T::Timestamp::now().into(); | ||
|
||
Some(timestamp) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,7 +246,7 @@ pub(crate) fn new_test_ext() -> sp_io::TestExternalities { | |
config.assimilate_storage(&mut storage).unwrap(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
let mut ext: sp_io::TestExternalities = storage.into(); | ||
// Clear thread local vars for https://github.com/paritytech/substrate/issues/10479. | ||
// Clear thread local vars for https://github.com/paritytech/polkadot-sdk/issues/10479. | ||
ext.execute_with(|| take_hooks()); | ||
ext.execute_with(|| System::set_block_number(1)); | ||
ext | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT summary of e344d4 - a36bc6:
pallet-timestamp
dependency was updated fromv1.3.0-rc1
to4.0.0-dev
pallet-fruniques
dependency was updated from0.1.0-dev
pallet-rbac
dependency was updated from4.0.0-dev
pallet-gated-marketplace
dependency was updated from4.0.0-dev