From db14a78b0d76428586d9eb90dc661572bf01d10a Mon Sep 17 00:00:00 2001 From: Trubnikov Sergey Date: Tue, 17 Jan 2023 11:36:13 +0000 Subject: [PATCH] feat: add enum for AccessMode --- --- a/pallets/common/src/erc.rs +++ b/pallets/common/src/erc.rs @@ -503,18 +503,12 @@ } /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList - fn set_collection_access(&mut self, caller: caller, mode: u8) -> Result<()> { + fn set_collection_access(&mut self, caller: caller, mode: eth::AccessMode) -> Result<()> { self.consume_store_reads_and_writes(1, 1)?; let caller = T::CrossAccountId::from_eth(caller); let permissions = CollectionPermissions { - access: Some(match mode { - 0 => AccessMode::Normal, - 1 => AccessMode::AllowList, - _ => return Err("not supported access mode".into()), - }), + access: Some(mode.into()), ..Default::default() }; >::update_permissions(&caller, self, permissions).map_err(dispatch_to_evm::) --- a/pallets/common/src/eth.rs +++ b/pallets/common/src/eth.rs @@ -413,3 +413,32 @@ Self { field, value } } } + +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +#[derive(AbiCoder, Copy, Clone, Default, Debug)] +#[repr(u8)] +pub enum AccessMode { + /// Access grant for owner and admins. Used as default. + #[default] + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList, +} + +impl From for AccessMode { + fn from(value: up_data_structs::AccessMode) -> Self { + match value { + up_data_structs::AccessMode::Normal => AccessMode::Normal, + up_data_structs::AccessMode::AllowList => AccessMode::AllowList, + } + } +} + +impl Into for AccessMode { + fn into(self) -> up_data_structs::AccessMode { + match self { + AccessMode::Normal => up_data_structs::AccessMode::Normal, + AccessMode::AllowList => up_data_structs::AccessMode::AllowList, + } + } +} --- a/pallets/fungible/src/stubs/UniqueFungible.sol +++ b/pallets/fungible/src/stubs/UniqueFungible.sol @@ -274,11 +274,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) public { + function setCollectionAccess(AccessMode mode) public { require(false, stub_error); mode; dummy = 0; @@ -443,6 +441,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; --- a/pallets/nonfungible/src/stubs/UniqueNFT.sol +++ b/pallets/nonfungible/src/stubs/UniqueNFT.sol @@ -416,11 +416,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) public { + function setCollectionAccess(AccessMode mode) public { require(false, stub_error); mode; dummy = 0; @@ -585,6 +583,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; --- a/pallets/refungible/src/stubs/UniqueRefungible.sol +++ b/pallets/refungible/src/stubs/UniqueRefungible.sol @@ -416,11 +416,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) public { + function setCollectionAccess(AccessMode mode) public { require(false, stub_error); mode; dummy = 0; @@ -585,6 +583,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; --- a/tests/src/eth/abi/fungible.json +++ b/tests/src/eth/abi/fungible.json @@ -488,7 +488,9 @@ "type": "function" }, { - "inputs": [{ "internalType": "uint8", "name": "mode", "type": "uint8" }], + "inputs": [ + { "internalType": "enum AccessMode", "name": "mode", "type": "uint8" } + ], "name": "setCollectionAccess", "outputs": [], "stateMutability": "nonpayable", --- a/tests/src/eth/abi/nonFungible.json +++ b/tests/src/eth/abi/nonFungible.json @@ -650,7 +650,9 @@ "type": "function" }, { - "inputs": [{ "internalType": "uint8", "name": "mode", "type": "uint8" }], + "inputs": [ + { "internalType": "enum AccessMode", "name": "mode", "type": "uint8" } + ], "name": "setCollectionAccess", "outputs": [], "stateMutability": "nonpayable", --- a/tests/src/eth/abi/reFungible.json +++ b/tests/src/eth/abi/reFungible.json @@ -632,7 +632,9 @@ "type": "function" }, { - "inputs": [{ "internalType": "uint8", "name": "mode", "type": "uint8" }], + "inputs": [ + { "internalType": "enum AccessMode", "name": "mode", "type": "uint8" } + ], "name": "setCollectionAccess", "outputs": [], "stateMutability": "nonpayable", --- a/tests/src/eth/api/UniqueFungible.sol +++ b/tests/src/eth/api/UniqueFungible.sol @@ -175,11 +175,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) external; + function setCollectionAccess(AccessMode mode) external; /// Checks that user allowed to operate with collection. /// @@ -285,6 +283,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; --- a/tests/src/eth/api/UniqueNFT.sol +++ b/tests/src/eth/api/UniqueNFT.sol @@ -275,11 +275,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) external; + function setCollectionAccess(AccessMode mode) external; /// Checks that user allowed to operate with collection. /// @@ -385,6 +383,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; --- a/tests/src/eth/api/UniqueRefungible.sol +++ b/tests/src/eth/api/UniqueRefungible.sol @@ -275,11 +275,9 @@ /// Set the collection access method. /// @param mode Access mode - /// 0 for Normal - /// 1 for AllowList /// @dev EVM selector for this function is: 0x41835d4c, /// or in textual repr: setCollectionAccess(uint8) - function setCollectionAccess(uint8 mode) external; + function setCollectionAccess(AccessMode mode) external; /// Checks that user allowed to operate with collection. /// @@ -385,6 +383,14 @@ uint256 sub; } +/// Ethereum representation of `AccessMode` (see [`up_data_structs::AccessMode`]). +enum AccessMode { + /// Access grant for owner and admins. Used as default. + Normal, + /// Like a [`Normal`](AccessMode::Normal) but also users in allow list. + AllowList +} + /// Ethereum representation of `NestingPermissions` (see [`up_data_structs::NestingPermissions`]) field. struct CollectionNestingPermission { CollectionPermissionField field; -- gitstuff