Skip to content
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

Remove public minting from pallet and precompile #737

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 0 additions & 78 deletions pallets/laos-evolution/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,40 +211,6 @@ mod benchmarks {
}
}

#[benchmark]
fn precompile_enable_public_minting() {
let caller: T::AccountId = whitelisted_caller();
let owner = caller.clone();
let collection_id = LaosEvolution::<T>::create_collection(owner).unwrap();
let mut handle = MockHandle::new(T::AccountIdToH160::convert(caller));

#[block]
{
let res = EvolutionCollectionPrecompileSet::<T>::enable_public_minting(
collection_id,
&mut handle,
);
assert!(res.is_ok());
}
}

#[benchmark]
fn precompile_disable_public_minting() {
let caller: T::AccountId = whitelisted_caller();
let owner = caller.clone();
let collection_id = LaosEvolution::<T>::create_collection(owner).unwrap();
let mut handle = MockHandle::new(T::AccountIdToH160::convert(caller));

#[block]
{
let res = EvolutionCollectionPrecompileSet::<T>::disable_public_minting(
collection_id,
&mut handle,
);
assert!(res.is_ok());
}
}

#[benchmark]
fn precompile_owner() {
let caller: T::AccountId = whitelisted_caller();
Expand All @@ -259,23 +225,6 @@ mod benchmarks {
}
}

#[benchmark]
fn precompile_is_public_minting_enabled() {
let caller: T::AccountId = whitelisted_caller();
let owner = caller.clone();
let collection_id = LaosEvolution::<T>::create_collection(owner).unwrap();
let mut handle = MockHandle::new(T::AccountIdToH160::convert(caller));

#[block]
{
let res = EvolutionCollectionPrecompileSet::<T>::is_public_minting_enabled(
collection_id,
&mut handle,
);
assert!(res.is_ok());
}
}

#[benchmark]
fn precompile_token_uri() {
let caller: T::AccountId = whitelisted_caller();
Expand Down Expand Up @@ -374,33 +323,6 @@ mod benchmarks {
);
}

#[benchmark]
fn enable_public_minting() {
let caller: T::AccountId = whitelisted_caller();
let owner = caller.clone();
let collection_id = LaosEvolution::<T>::create_collection(owner.clone()).unwrap();

#[block]
{
LaosEvolution::<T>::enable_public_minting(owner, collection_id).unwrap();
}
assert!(CollectionPublicMintingEnabled::<T>::contains_key(collection_id));
}

#[benchmark]
fn disable_public_minting() {
let caller: T::AccountId = whitelisted_caller();
let owner = caller.clone();
let collection_id = LaosEvolution::<T>::create_collection(owner.clone()).unwrap();
LaosEvolution::<T>::enable_public_minting(owner.clone(), collection_id).unwrap();

#[block]
{
LaosEvolution::<T>::disable_public_minting(owner, collection_id).unwrap();
}
assert!(!CollectionPublicMintingEnabled::<T>::contains_key(collection_id));
}

#[benchmark]
fn transfer_ownership() {
let caller: T::AccountId = whitelisted_caller();
Expand Down
44 changes: 1 addition & 43 deletions pallets/laos-evolution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ pub mod pallet {
pub type CollectionOwner<T: Config> =
StorageMap<_, Blake2_128Concat, CollectionId, AccountIdOf<T>, OptionQuery>;

/// Storage for the public minting policy of collections
#[pallet::storage]
#[pallet::getter(fn collection_public_minting_enabled)]
pub type CollectionPublicMintingEnabled<T: Config> =
StorageMap<_, Blake2_128Concat, CollectionId, (), OptionQuery>;

/// Token URI which can override the default URI scheme and set explicitly
/// This will contain external URI in a raw form
#[pallet::storage]
Expand Down Expand Up @@ -132,12 +126,6 @@ pub mod pallet {
from: AccountIdOf<T>,
to: AccountIdOf<T>,
},
/// Public minting enabled
/// [collection_id]
PublicMintingEnabled { collection_id: CollectionId },
/// Public minting disabled
/// [collection_id]
PublicMintingDisabled { collection_id: CollectionId },
}

// Errors inform users that something went wrong.
Expand Down Expand Up @@ -194,11 +182,7 @@ impl<T: Config> EvolutionCollection<AccountIdOf<T>, TokenUriOf<T>> for Pallet<T>
CollectionOwner::<T>::contains_key(collection_id),
Error::<T>::CollectionDoesNotExist
);
ensure!(
Self::is_owner(collection_id, who) ||
CollectionPublicMintingEnabled::<T>::contains_key(collection_id),
Error::<T>::NoPermission
);
ensure!(Self::is_owner(collection_id, who), Error::<T>::NoPermission);

let to_as_h160 = T::AccountIdToH160::convert(to.clone());
// compose asset_id from slot and owner
Expand Down Expand Up @@ -266,32 +250,6 @@ impl<T: Config> EvolutionCollection<AccountIdOf<T>, TokenUriOf<T>> for Pallet<T>
Ok(())
})
}

fn enable_public_minting(who: AccountIdOf<T>, collection_id: CollectionId) -> DispatchResult {
ensure!(
CollectionOwner::<T>::contains_key(collection_id),
Error::<T>::CollectionDoesNotExist
);
ensure!(Self::is_owner(collection_id, who), Error::<T>::NoPermission);
CollectionPublicMintingEnabled::<T>::insert(collection_id, ());
Self::deposit_event(Event::PublicMintingEnabled { collection_id });
Ok(())
}

fn disable_public_minting(who: AccountIdOf<T>, collection_id: CollectionId) -> DispatchResult {
ensure!(
CollectionOwner::<T>::contains_key(collection_id),
Error::<T>::CollectionDoesNotExist
);
ensure!(Self::is_owner(collection_id, who), Error::<T>::NoPermission);
CollectionPublicMintingEnabled::<T>::remove(collection_id);
Self::deposit_event(Event::PublicMintingDisabled { collection_id });
Ok(())
}

fn is_public_minting_enabled(collection_id: CollectionId) -> bool {
CollectionPublicMintingEnabled::<T>::contains_key(collection_id)
}
}

/// Converts `Slot` and `H160` to `TokenId`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,19 @@
{
"indexed": true,
"internalType": "address",
"name": "previousOwner",
"name": "_previousOwner",
"type": "address"
},
{
"indexed": true,
"internalType": "address",
"name": "newOwner",
"name": "_newOwner",
"type": "address"
}
],
"name": "OwnershipTransferred",
"type": "event"
},
{
"anonymous": false,
"inputs": [],
"name": "PublicMintingDisabled",
"type": "event"
},
{
"anonymous": false,
"inputs": [],
"name": "PublicMintingEnabled",
"type": "event"
},
{
"inputs": [],
"name": "owner",
Expand Down Expand Up @@ -163,40 +151,13 @@
"inputs": [
{
"internalType": "address",
"name": "newOwner",
"name": "_newOwner",
"type": "address"
}
],
"name": "transferOwnership",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "enablePublicMinting",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "disablePublicMinting",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "isPublicMintingEnabled",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ interface EvolutionCollection {
address indexed _newOwner
);

/// @notice Emitted when public minting is enabled for the collection
event PublicMintingEnabled();

/// @notice Emitted when public minting is disabled for the collection
event PublicMintingDisabled();

/// @notice Owner of the collection
/// @dev Call this function to get the owner of a collection
/// @return the owner of the collection
Expand Down Expand Up @@ -88,19 +82,4 @@ interface EvolutionCollection {
/// @dev Call this function to transfer ownership of the collection, the caller must be the owner of the collection
/// @param _newOwner The address to transfer ownership to.
function transferOwnership(address _newOwner) external;

/// @notice Enables public minting for the collection
/// When enabled, any address is allowed to mint on this collection
/// This does not affect evolution: only the owner of the collection can continue evolving assets
/// @dev Call this function to enable public minting for the collection, the caller must be the owner of the collection
function enablePublicMinting() external;

/// @notice Disables public minting for the collection
/// @dev Call this function to disable public minting for the collection, the caller must be the owner of the collection
function disablePublicMinting() external;

/// @notice Checks if public minting is enabled for the collection
/// @dev Call this function to check if public minting is enabled for the collection
/// @return true if public minting is enabled for the collection, false otherwise
function isPublicMintingEnabled() external view returns (bool);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use pallet_evm::GasWeightMapping;
use precompile_utils::{
keccak256,
prelude::{
log1, log2, log3, revert, Address, DiscriminantResult, EvmResult, LogExt, PrecompileHandle,
log2, log3, revert, Address, DiscriminantResult, EvmResult, LogExt, PrecompileHandle,
String,
},
solidity::{self, codec::UnboundedString},
Expand All @@ -31,11 +31,6 @@ pub const SELECTOR_LOG_MINTED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] =
pub const SELECTOR_LOG_EVOLVED_WITH_EXTERNAL_TOKEN_URI: [u8; 32] =
keccak256!("EvolvedWithExternalURI(uint256,string)");

/// Solidity selector of the PublicMintingEnabled log, which is the Keccak of the Log signature.
pub const SELECTOR_LOG_PUBLIC_MINTING_ENABLED: [u8; 32] = keccak256!("PublicMintingEnabled()");
/// Solidity selector of the PublicMintingDisabled log, which is the Keccak of the Log signature.
pub const SELECTOR_LOG_PUBLIC_MINTING_DISABLED: [u8; 32] = keccak256!("PublicMintingDisabled()");

/// Solidity selector of the `OwnershipTransferred` log, which is the Keccak of the Log signature.
pub const SELECTOR_LOG_OWNERSHIP_TRANSFERRED: [u8; 32] =
keccak256!("OwnershipTransferred(address,address)");
Expand Down Expand Up @@ -199,68 +194,6 @@ where
Ok(())
}

#[precompile::public("enablePublicMinting()")]
pub fn enable_public_minting(
collection_id: CollectionId,
handle: &mut impl PrecompileHandle,
) -> EvmResult<()> {
super::register_cost::<R>(handle, R::WeightInfo::precompile_enable_public_minting())?;

match LaosEvolution::<R>::enable_public_minting(
R::AccountIdToH160::convert_back(handle.context().caller),
collection_id,
) {
Ok(()) => {
log1(
handle.context().address,
SELECTOR_LOG_PUBLIC_MINTING_ENABLED,
solidity::encode_event_data(()),
)
.record(handle)?;

Ok(())
},
Err(err) => Err(revert(convert_dispatch_error_to_string(err))),
}
}

#[precompile::public("disablePublicMinting()")]
pub fn disable_public_minting(
collection_id: CollectionId,
handle: &mut impl PrecompileHandle,
) -> EvmResult<()> {
super::register_cost::<R>(handle, R::WeightInfo::precompile_disable_public_minting())?;

match LaosEvolution::<R>::disable_public_minting(
R::AccountIdToH160::convert_back(handle.context().caller),
collection_id,
) {
Ok(()) => {
log1(
handle.context().address,
SELECTOR_LOG_PUBLIC_MINTING_DISABLED,
solidity::encode_event_data(()),
)
.record(handle)?;

Ok(())
},
Err(err) => Err(revert(convert_dispatch_error_to_string(err))),
}
}

#[precompile::public("isPublicMintingEnabled()")]
#[precompile::view]
pub fn is_public_minting_enabled(
collection_id: CollectionId,
handle: &mut impl PrecompileHandle,
) -> EvmResult<bool> {
super::register_cost::<R>(handle, R::WeightInfo::precompile_is_public_minting_enabled())?;

let is_enabled = LaosEvolution::<R>::is_public_minting_enabled(collection_id);
Ok(is_enabled)
}

#[precompile::public("tokenURI(uint256)")]
#[precompile::view]
pub fn token_uri(
Expand Down
Loading
Loading