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.jsondiffbeforeafterboth1{2 "CrossAccountId": {3 "_enum": {4 "substrate": "AccountId",5 "ethereum": "H160"6 }7 },8 "AccessMode": {9 "_enum": [10 "Normal",11 "WhiteList"12 ]13 },14 "DecimalPoints": "u8",15 "CollectionMode": {16 "_enum": {17 "Invalid": null,18 "NFT": null,19 "Fungible": "DecimalPoints",20 "ReFungible": null21 }22 },23 "Ownership": {24 "Owner": "CrossAccountId",25 "Fraction": "u128"26 },27 "FungibleItemType": {28 "Value": "u128"29 },30 "NftItemType": {31 "Owner": "CrossAccountId",32 "ConstData": "Vec<u8>",33 "VariableData": "Vec<u8>"34 },35 "ReFungibleItemType": {36 "Owner": "Vec<Ownership<CrossAccountId>>",37 "ConstData": "Vec<u8>",38 "VariableData": "Vec<u8>"39 },40 "SponsorshipState": {41 "_enum": {42 "disabled": null,43 "unconfirmed": "AccountId",44 "confirmed": "AccountId"45 }46 },47 "Collection": {48 "Owner": "CrossAccountId",49 "Mode": "CollectionMode",50 "Access": "AccessMode",51 "DecimalPoints": "DecimalPoints",52 "Name": "Vec<u16>",53 "Description": "Vec<u16>",54 "TokenPrefix": "Vec<u8>",55 "MintMode": "bool",56 "OffchainSchema": "Vec<u8>",57 "SchemaVersion": "SchemaVersion",58 "Sponsorship": "SponsorshipState",59 "Limits": "CollectionLimits",60 "VariableOnChainSchema": "Vec<u8>",61 "ConstOnChainSchema": "Vec<u8>"62 },63 "RawData": "Vec<u8>",64 "Address": "AccountId",65 "LookupSource": "AccountId",66 "Weight": "u64",67 "CreateNftData": {68 "const_data": "Vec<u8>",69 "variable_data": "Vec<u8>" 70 },71 "CreateFungibleData": {72 "value": "u128"73 },74 "CreateReFungibleData": {75 "const_data": "Vec<u8>",76 "variable_data": "Vec<u8>",77 "pieces": "u128"78 },79 "CreateItemData": {80 "_enum": {81 "NFT": "CreateNftData",82 "Fungible": "CreateFungibleData",83 "ReFungible": "CreateReFungibleData"84 }85 },86 "SchemaVersion": {87 "_enum": [88 "ImageURL",89 "Unique"90 ]91 },92 "CollectionId": "u32",93 "TokenId": "u32",94 "ChainLimits": {95 "CollectionNumbersLimit": "u32",96 "AccountTokenOwnershipLimit": "u32",97 "CollectionAdminsLimit": "u64",98 "CustomDataLimit": "u32",99 "NftSponsorTimeout": "u32",100 "FungibleSponsorTimeout": "u32",101 "RefungibleSponsorTimeout": "u32",102 "OffchainSchemaLimit": "u32",103 "VariableOnChainSchemaLimit": "u32",104 "ConstOnChainSchemaLimit": "u32"105 },106 "CollectionLimits": {107 "AccountTokenOwnershipLimit": "u32",108 "SponsoredDataSize": "u32",109 "SponsoredDataRateLimit": "Option<BlockNumber>",110 "TokenLimit": "u32",111 "SponsorTimeout": "u32",112 "OwnerCanTransfer": "bool",113 "OwnerCanDestroy": "bool"114 }115}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);