difftreelog
refactor revert changing collection owner type
in: master
Not necessary yet, we don't have to support evm accounts create collections
3 files changed
pallets/nft/src/lib.rsdiffbeforeafterboth--- a/pallets/nft/src/lib.rs
+++ b/pallets/nft/src/lib.rs
@@ -167,7 +167,7 @@
#[derive(Encode, Decode, Clone, PartialEq)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
pub struct Collection<T: Config> {
- pub owner: T::CrossAccountId,
+ pub owner: T::AccountId,
pub mode: CollectionMode,
pub access: AccessMode,
pub decimal_points: DecimalPoints,
@@ -638,6 +638,7 @@
decl_event!(
pub enum Event<T>
where
+ AccountId = <T as frame_system::Config>::AccountId,
CrossAccountId = <T as Config>::CrossAccountId,
{
/// New collection was created
@@ -649,7 +650,7 @@
/// * mode: [CollectionMode] converted into u8.
///
/// * account_id: Collection owner.
- CollectionCreated(CollectionId, u8, CrossAccountId),
+ CollectionCreated(CollectionId, u8, AccountId),
/// New item was created.
///
@@ -734,7 +735,7 @@
mode: CollectionMode) -> DispatchResult {
// Anyone can create a collection
- let who = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let who = ensure_signed(origin)?;
// Take a (non-refundable) deposit of collection creation
let mut imbalance = <<<T as Config>::Currency as Currency<T::AccountId>>::PositiveImbalance>::zero();
@@ -743,7 +744,7 @@
T::CollectionCreationPrice::get(),
));
<T as Config>::Currency::settle(
- who.as_sub(),
+ &who,
imbalance,
WithdrawReasons::TRANSFER,
ExistenceRequirement::KeepAlive,
@@ -820,7 +821,7 @@
#[transactional]
pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {
- let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let sender = ensure_signed(origin)?;
let collection = Self::get_collection(collection_id)?;
Self::check_owner_permissions(&collection, &sender)?;
if !collection.limits.owner_can_destroy {
@@ -925,7 +926,7 @@
#[transactional]
pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult
{
- let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let sender = ensure_signed(origin)?;
let mut target_collection = Self::get_collection(collection_id)?;
Self::check_owner_permissions(&target_collection, &sender)?;
@@ -952,7 +953,7 @@
#[transactional]
pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult
{
- let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let sender = ensure_signed(origin)?;
let mut target_collection = Self::get_collection(collection_id)?;
Self::check_owner_permissions(&target_collection, &sender)?;
@@ -975,9 +976,9 @@
/// * new_owner.
#[weight = <T as Config>::WeightInfo::change_collection_owner()]
#[transactional]
- pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::CrossAccountId) -> DispatchResult {
+ pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {
- let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let sender = ensure_signed(origin)?;
let mut target_collection = Self::get_collection(collection_id)?;
Self::check_owner_permissions(&target_collection, &sender)?;
target_collection.owner = new_owner;
@@ -1061,7 +1062,7 @@
#[weight = <T as Config>::WeightInfo::set_collection_sponsor()]
#[transactional]
pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {
- let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
+ let sender = ensure_signed(origin)?;
let mut target_collection = Self::get_collection(collection_id)?;
Self::check_owner_permissions(&target_collection, &sender)?;
@@ -1110,7 +1111,7 @@
let sender = ensure_signed(origin)?;
let mut target_collection = Self::get_collection(collection_id)?;
- Self::check_owner_permissions(&target_collection, &T::CrossAccountId::from_sub(sender))?;
+ Self::check_owner_permissions(&target_collection, &sender)?;
target_collection.sponsorship = SponsorshipState::Disabled;
Self::save_collection(target_collection);
@@ -1650,7 +1651,7 @@
) -> DispatchResult {
let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
let mut target_collection = Self::get_collection(collection_id)?;
- Self::check_owner_permissions(&target_collection, &sender)?;
+ Self::check_owner_permissions(&target_collection, &sender.as_sub())?;
let old_limits = &target_collection.limits;
let chain_limits = ChainLimit::get();
@@ -2239,7 +2240,7 @@
)
}
- fn check_owner_permissions(target_collection: &CollectionHandle<T>, subject: &T::CrossAccountId) -> DispatchResult {
+ fn check_owner_permissions(target_collection: &CollectionHandle<T>, subject: &T::AccountId) -> DispatchResult {
ensure!(
*subject == target_collection.owner,
Error::<T>::NoPermission
@@ -2249,7 +2250,7 @@
}
fn is_owner_or_admin_permissions(collection: &CollectionHandle<T>, subject: &T::CrossAccountId) -> bool {
- *subject == collection.owner || <AdminList<T>>::get(collection.id).contains(&subject)
+ *subject.as_sub() == collection.owner || <AdminList<T>>::get(collection.id).contains(&subject)
}
fn check_owner_or_admin_permissions(
runtime_types.jsondiffbeforeafterboth45 }45 }46 },46 },47 "Collection": {47 "Collection": {48 "Owner": "CrossAccountId",48 "Owner": "AccountId",49 "Mode": "CollectionMode",49 "Mode": "CollectionMode",50 "Access": "AccessMode",50 "Access": "AccessMode",51 "DecimalPoints": "DecimalPoints",51 "DecimalPoints": "DecimalPoints",tests/src/util/helpers.tsdiffbeforeafterboth--- a/tests/src/util/helpers.ts
+++ b/tests/src/util/helpers.ts
@@ -37,7 +37,7 @@
}
return input;
}
-export function toSubstrateAddress(input: CrossAccountId): string {
+export function toSubstrateAddress(input: string | CrossAccountId | IKeyringPair): string {
input = normalizeAccountId(input);
if ('substrate' in input) {
return input.substrate;
@@ -273,7 +273,7 @@
// tslint:disable-next-line:no-unused-expression
expect(collection).to.be.not.null;
expect(BcollectionCount).to.be.equal(AcollectionCount + 1, 'Error: NFT collection NOT created.');
- expect(collection.Owner).to.be.deep.equal(normalizeAccountId(alicesPublicKey));
+ expect(collection.Owner).to.be.equal(toSubstrateAddress(alicesPublicKey));
expect(utf16ToStr(collection.Name)).to.be.equal(name);
expect(utf16ToStr(collection.Description)).to.be.equal(description);
expect(hexToStr(collection.TokenPrefix)).to.be.equal(tokenPrefix);