difftreelog
CORE-300 Move CrossAccountId to frontier
in: master
27 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2554,7 +2554,7 @@
"fc-db",
"fc-rpc-core",
"fp-consensus",
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"fp-rpc",
"fp-storage",
"futures 0.3.21",
@@ -2565,7 +2565,7 @@
"log",
"lru 0.6.6",
"pallet-ethereum",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"parking_lot 0.11.2",
"rand 0.7.3",
@@ -2757,7 +2757,7 @@
dependencies = [
"ethereum",
"ethereum-types",
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"scale-info",
"sp-api",
@@ -2853,6 +2853,21 @@
]
[[package]]
+name = "frame-common"
+version = "0.1.0"
+source = "git+https://github.com/uniquenetwork/frontier.git?branch=feature/300#0a1dc4086cbe971ddf57edf82a61cfce52c8c20b"
+dependencies = [
+ "frame-system",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=feature/300)",
+ "parity-scale-codec",
+ "scale-info",
+ "serde",
+ "sp-core",
+ "sp-std",
+ "up-evm-mapping",
+]
+
+[[package]]
name = "frame-election-provider-support"
version = "4.0.0-dev"
source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.18#fc3fd073d3a0acf9933c3994b660ebd7b5833f65"
@@ -5835,7 +5850,7 @@
dependencies = [
"frame-support",
"frame-system",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"scale-info",
"serde",
@@ -5984,9 +5999,10 @@
version = "0.1.0"
dependencies = [
"evm-coder",
+ "frame-common",
"frame-support",
"frame-system",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"pallet-evm-coder-substrate",
"parity-scale-codec",
"scale-info",
@@ -6064,7 +6080,7 @@
"ethereum-types",
"evm",
"fp-consensus",
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"fp-rpc",
"fp-self-contained",
"fp-storage",
@@ -6072,7 +6088,7 @@
"frame-system",
"log",
"pallet-balances",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"pallet-timestamp",
"parity-scale-codec",
"rlp",
@@ -6093,7 +6109,7 @@
"evm",
"evm-gasometer",
"evm-runtime",
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"frame-benchmarking",
"frame-support",
"frame-system",
@@ -6124,7 +6140,7 @@
"frame-support",
"frame-system",
"pallet-ethereum",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"scale-info",
"sp-core",
@@ -6139,7 +6155,7 @@
"frame-support",
"frame-system",
"log",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"pallet-evm-coder-substrate",
"parity-scale-codec",
"scale-info",
@@ -6154,11 +6170,11 @@
name = "pallet-evm-migration"
version = "0.1.0"
dependencies = [
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"frame-benchmarking",
"frame-support",
"frame-system",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"scale-info",
"sp-core",
@@ -6171,11 +6187,11 @@
name = "pallet-evm-transaction-payment"
version = "0.1.0"
dependencies = [
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"frame-support",
"frame-system",
"pallet-ethereum",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"parity-scale-codec",
"scale-info",
"sp-core",
@@ -6193,6 +6209,7 @@
"ethereum",
"evm-coder",
"frame-benchmarking",
+ "frame-common",
"frame-support",
"frame-system",
"pallet-common",
@@ -6419,6 +6436,7 @@
"ethereum",
"evm-coder",
"frame-benchmarking",
+ "frame-common",
"frame-support",
"frame-system",
"pallet-common",
@@ -6535,6 +6553,7 @@
version = "0.1.0"
dependencies = [
"frame-benchmarking",
+ "frame-common",
"frame-support",
"frame-system",
"pallet-common",
@@ -6795,15 +6814,16 @@
dependencies = [
"ethereum",
"evm-coder",
- "fp-evm",
+ "fp-evm 3.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"frame-benchmarking",
+ "frame-common",
"frame-support",
"frame-system",
"hex-literal",
"pallet-balances",
"pallet-common",
"pallet-ethereum",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"pallet-evm-coder-substrate",
"pallet-fungible",
"pallet-nonfungible",
@@ -12186,7 +12206,7 @@
"chrono",
"lazy_static",
"matchers",
- "parking_lot 0.11.2",
+ "parking_lot 0.10.2",
"regex",
"serde",
"serde_json",
@@ -12333,6 +12353,7 @@
name = "uc-rpc"
version = "0.1.0"
dependencies = [
+ "frame-common",
"jsonrpc-core",
"jsonrpc-core-client",
"jsonrpc-derive",
@@ -12549,6 +12570,7 @@
"fp-rpc",
"fp-self-contained",
"frame-benchmarking",
+ "frame-common",
"frame-executive",
"frame-support",
"frame-system",
@@ -12561,7 +12583,7 @@
"pallet-base-fee",
"pallet-common",
"pallet-ethereum",
- "pallet-evm",
+ "pallet-evm 6.0.0-dev (git+https://github.com/uniquenetwork/frontier.git?branch=unique-polkadot-v0.9.17)",
"pallet-evm-coder-substrate",
"pallet-evm-contract-helpers",
"pallet-evm-migration",
@@ -12688,6 +12710,7 @@
[[package]]
name = "up-evm-mapping"
version = "0.1.0"
+source = "git+https://github.com/uniquenetwork/frontier.git?branch=feature/300#0a1dc4086cbe971ddf57edf82a61cfce52c8c20b"
dependencies = [
"frame-support",
"sp-core",
@@ -12697,6 +12720,7 @@
name = "up-rpc"
version = "0.1.0"
dependencies = [
+ "frame-common",
"pallet-common",
"parity-scale-codec",
"sp-api",
client/rpc/Cargo.tomldiffbeforeafterboth--- a/client/rpc/Cargo.toml
+++ b/client/rpc/Cargo.toml
@@ -18,3 +18,4 @@
sp-core = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
sp-rpc = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
sp-runtime = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
client/rpc/src/lib.rsdiffbeforeafterboth--- a/client/rpc/src/lib.rs
+++ b/client/rpc/src/lib.rs
@@ -201,7 +201,7 @@
AccountId: Decode,
C: 'static + ProvideRuntimeApi<Block> + HeaderBackend<Block>,
C::Api: UniqueRuntimeApi<Block, CrossAccountId, AccountId>,
- CrossAccountId: pallet_common::account::CrossAccountId<AccountId>,
+ CrossAccountId: frame_common::account::CrossAccountId<AccountId>,
{
pass_method!(account_tokens(collection: CollectionId, account: CrossAccountId) -> Vec<TokenId>);
pass_method!(token_exists(collection: CollectionId, token: TokenId) -> bool);
pallets/common/Cargo.tomldiffbeforeafterboth--- a/pallets/common/Cargo.toml
+++ b/pallets/common/Cargo.toml
@@ -16,11 +16,12 @@
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
-up-evm-mapping = { default-features = false, path = '../../primitives/evm-mapping' }
up-data-structs = { default-features = false, path = '../../primitives/data-structs' }
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
evm-coder = { default-features = false, path = '../../crates/evm-coder' }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
+up-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
serde = { version = "1.0.130", default-features = false }
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
pallets/common/src/account.rsdiffbeforeafterboth--- a/pallets/common/src/account.rs
+++ /dev/null
@@ -1,195 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-use crate::Config;
-use codec::{Encode, EncodeLike, Decode, MaxEncodedLen};
-use sp_core::H160;
-use scale_info::{Type, TypeInfo};
-use core::cmp::Ordering;
-use serde::{Serialize, Deserialize};
-use pallet_evm::AddressMapping;
-use sp_std::vec::Vec;
-use sp_std::clone::Clone;
-
-pub use up_evm_mapping::EvmBackwardsAddressMapping;
-
-pub trait CrossAccountId<AccountId>:
- Encode + EncodeLike + Decode + TypeInfo + MaxEncodedLen + Clone + PartialEq + Ord + core::fmt::Debug
-// +
-// Serialize + Deserialize<'static>
-{
- fn as_sub(&self) -> &AccountId;
- fn as_eth(&self) -> &H160;
-
- fn from_sub(account: AccountId) -> Self;
- fn from_eth(account: H160) -> Self;
-
- fn conv_eq(&self, other: &Self) -> bool;
-}
-
-#[derive(Encode, Decode, Serialize, Deserialize, TypeInfo, MaxEncodedLen)]
-#[serde(rename_all = "camelCase")]
-enum BasicCrossAccountIdRepr<AccountId> {
- Substrate(AccountId),
- Ethereum(H160),
-}
-
-#[derive(PartialEq, Eq)]
-pub struct BasicCrossAccountId<T: Config> {
- /// If true - then ethereum is canonical encoding
- from_ethereum: bool,
- substrate: T::AccountId,
- ethereum: H160,
-}
-
-impl<T: Config> MaxEncodedLen for BasicCrossAccountId<T> {
- fn max_encoded_len() -> usize {
- <BasicCrossAccountIdRepr<T::AccountId>>::max_encoded_len()
- }
-}
-
-impl<T: Config> TypeInfo for BasicCrossAccountId<T> {
- type Identity = Self;
-
- fn type_info() -> Type {
- <BasicCrossAccountIdRepr<T::AccountId>>::type_info()
- }
-}
-
-impl<T: Config> core::fmt::Debug for BasicCrossAccountId<T> {
- fn fmt(&self, fmt: &mut core::fmt::Formatter) -> core::fmt::Result {
- if self.from_ethereum {
- fmt.debug_tuple("CrossAccountId::Ethereum")
- .field(&self.ethereum)
- .finish()
- } else {
- fmt.debug_tuple("CrossAccountId::Substrate")
- .field(&self.substrate)
- .finish()
- }
- }
-}
-
-impl<T: Config> PartialOrd for BasicCrossAccountId<T> {
- fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
- Some(self.substrate.cmp(&other.substrate))
- }
-}
-
-impl<T: Config> Ord for BasicCrossAccountId<T> {
- fn cmp(&self, other: &Self) -> Ordering {
- self.partial_cmp(other)
- .expect("substrate account is total ordered")
- }
-}
-
-impl<T: Config> Clone for BasicCrossAccountId<T> {
- fn clone(&self) -> Self {
- Self {
- from_ethereum: self.from_ethereum,
- substrate: self.substrate.clone(),
- ethereum: self.ethereum,
- }
- }
-}
-impl<T: Config> Encode for BasicCrossAccountId<T> {
- fn encode(&self) -> Vec<u8> {
- BasicCrossAccountIdRepr::from(self.clone()).encode()
- }
-}
-impl<T: Config> EncodeLike for BasicCrossAccountId<T> {}
-impl<T: Config> Decode for BasicCrossAccountId<T> {
- fn decode<I>(input: &mut I) -> Result<Self, codec::Error>
- where
- I: codec::Input,
- {
- Ok(BasicCrossAccountIdRepr::decode(input)?.into())
- }
-}
-impl<T> Serialize for BasicCrossAccountId<T>
-where
- T: Config,
- T::AccountId: Serialize,
-{
- fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
- where
- S: serde::Serializer,
- {
- let repr = BasicCrossAccountIdRepr::from(self.clone());
- (&repr).serialize(serializer)
- }
-}
-impl<'de, T> Deserialize<'de> for BasicCrossAccountId<T>
-where
- T: Config,
- T::AccountId: Deserialize<'de>,
-{
- fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
- where
- D: serde::Deserializer<'de>,
- {
- Ok(BasicCrossAccountIdRepr::deserialize(deserializer)?.into())
- }
-}
-impl<T: Config> CrossAccountId<T::AccountId> for BasicCrossAccountId<T> {
- fn as_sub(&self) -> &T::AccountId {
- &self.substrate
- }
- fn as_eth(&self) -> &H160 {
- &self.ethereum
- }
- fn from_sub(substrate: T::AccountId) -> Self {
- Self {
- ethereum: T::EvmBackwardsAddressMapping::from_account_id(substrate.clone()),
- substrate,
- from_ethereum: false,
- }
- }
- fn from_eth(ethereum: H160) -> Self {
- Self {
- ethereum,
- substrate: T::EvmAddressMapping::into_account_id(ethereum),
- from_ethereum: true,
- }
- }
- fn conv_eq(&self, other: &Self) -> bool {
- if self.from_ethereum == other.from_ethereum {
- self.substrate == other.substrate && self.ethereum == other.ethereum
- } else if self.from_ethereum {
- // ethereum is canonical encoding, but we need to compare derived address
- self.substrate == other.substrate
- } else {
- self.ethereum == other.ethereum
- }
- }
-}
-impl<T: Config> From<BasicCrossAccountIdRepr<T::AccountId>> for BasicCrossAccountId<T> {
- fn from(repr: BasicCrossAccountIdRepr<T::AccountId>) -> Self {
- match repr {
- BasicCrossAccountIdRepr::Substrate(s) => Self::from_sub(s),
- BasicCrossAccountIdRepr::Ethereum(e) => Self::from_eth(e),
- }
- }
-}
-impl<T: Config> From<BasicCrossAccountId<T>> for BasicCrossAccountIdRepr<T::AccountId> {
- fn from(v: BasicCrossAccountId<T>) -> Self {
- if v.from_ethereum {
- BasicCrossAccountIdRepr::Ethereum(*v.as_eth())
- } else {
- BasicCrossAccountIdRepr::Substrate(v.as_sub().clone())
- }
- }
-}
pallets/common/src/lib.rsdiffbeforeafterboth--- a/pallets/common/src/lib.rs
+++ b/pallets/common/src/lib.rs
@@ -19,7 +19,7 @@
use core::ops::{Deref, DerefMut};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use sp_std::vec::Vec;
-use account::CrossAccountId;
+use frame_common::account::CrossAccountId;
use frame_support::{
dispatch::{DispatchErrorWithPostInfo, DispatchResultWithPostInfo},
ensure, fail,
@@ -38,7 +38,6 @@
pub use pallet::*;
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
-pub mod account;
#[cfg(feature = "runtime-benchmarks")]
pub mod benchmarking;
pub mod erc;
@@ -163,7 +162,7 @@
pub mod pallet {
use super::*;
use frame_support::{Blake2_128Concat, pallet_prelude::*, storage::Key};
- use account::CrossAccountId;
+ use frame_common::account::CrossAccountId;
use frame_support::traits::Currency;
use up_data_structs::TokenId;
use scale_info::TypeInfo;
pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -17,7 +17,7 @@
pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.18' }
-up-evm-mapping = { default-features = false, path = "../../primitives/evm-mapping" }
+up-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
log = "0.4.14"
[dependencies.codec]
pallets/evm-transaction-payment/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-transaction-payment/Cargo.toml
+++ b/pallets/evm-transaction-payment/Cargo.toml
@@ -18,7 +18,7 @@
fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.18' }
-up-evm-mapping = { default-features = false, path = "../../primitives/evm-mapping" }
+up-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
[dependencies.codec]
default-features = false
pallets/fungible/Cargo.tomldiffbeforeafterboth--- a/pallets/fungible/Cargo.toml
+++ b/pallets/fungible/Cargo.toml
@@ -25,6 +25,7 @@
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
] }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
[features]
default = ["std"]
pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -21,7 +21,7 @@
use pallet_common::erc::{CommonEvmHandler, PrecompileResult};
use sp_core::{H160, U256};
use sp_std::vec::Vec;
-use pallet_common::account::CrossAccountId;
+use frame_common::account::CrossAccountId;
use pallet_evm_coder_substrate::{call, dispatch_to_evm};
use crate::{
pallets/fungible/src/lib.rsdiffbeforeafterboth--- a/pallets/fungible/src/lib.rs
+++ b/pallets/fungible/src/lib.rs
@@ -20,8 +20,9 @@
use frame_support::{ensure};
use up_data_structs::{AccessMode, CollectionId, TokenId, CreateCollectionData};
use pallet_common::{
- Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
+ Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
};
+use frame_common::account::CrossAccountId;
use pallet_evm_coder_substrate::WithRecorder;
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
pallets/nonfungible/Cargo.tomldiffbeforeafterboth--- a/pallets/nonfungible/Cargo.toml
+++ b/pallets/nonfungible/Cargo.toml
@@ -25,6 +25,7 @@
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
] }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
[features]
default = ["std"]
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -25,9 +25,9 @@
use sp_core::{H160, U256};
use sp_std::{vec::Vec, vec};
use pallet_common::{
- account::CrossAccountId,
erc::{CommonEvmHandler, PrecompileResult},
};
+use frame_common::account::CrossAccountId;
use pallet_evm_coder_substrate::call;
use crate::{
pallets/nonfungible/src/lib.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/lib.rs
+++ b/pallets/nonfungible/src/lib.rs
@@ -22,8 +22,9 @@
AccessMode, CollectionId, CustomDataLimit, TokenId, CreateCollectionData, CreateNftExData,
};
use pallet_common::{
- Error as CommonError, Pallet as PalletCommon, Event as CommonEvent, account::CrossAccountId,
+ Error as CommonError, Pallet as PalletCommon, Event as CommonEvent,
};
+use frame_common::account::CrossAccountId;
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
use sp_core::H160;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
pallets/refungible/Cargo.tomldiffbeforeafterboth--- a/pallets/refungible/Cargo.toml
+++ b/pallets/refungible/Cargo.toml
@@ -22,6 +22,7 @@
scale-info = { version = "2.0.1", default-features = false, features = [
"derive",
] }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
[features]
default = ["std"]
pallets/refungible/src/lib.rsdiffbeforeafterboth--- a/pallets/refungible/src/lib.rs
+++ b/pallets/refungible/src/lib.rs
@@ -22,8 +22,9 @@
CreateCollectionData, CreateRefungibleExData,
};
use pallet_common::{
- Error as CommonError, Event as CommonEvent, Pallet as PalletCommon, account::CrossAccountId,
+ Error as CommonError, Event as CommonEvent, Pallet as PalletCommon,
};
+use frame_common::account::CrossAccountId;
use sp_runtime::{ArithmeticError, DispatchError, DispatchResult};
use sp_std::{vec::Vec, vec, collections::btree_map::BTreeMap};
use core::ops::Deref;
pallets/unique/Cargo.tomldiffbeforeafterboth--- a/pallets/unique/Cargo.toml
+++ b/pallets/unique/Cargo.toml
@@ -132,7 +132,8 @@
sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.18" }
up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring", branch = 'polkadot-v0.9.18' }
-up-evm-mapping = { default-features = false, path = "../../primitives/evm-mapping" }
+up-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
evm-coder = { default-features = false, path = "../../crates/evm-coder" }
pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }
primitive-types = { version = "0.11.1", default-features = false, features = [
pallets/unique/src/eth/sponsoring.rsdiffbeforeafterboth--- a/pallets/unique/src/eth/sponsoring.rs
+++ b/pallets/unique/src/eth/sponsoring.rs
@@ -25,8 +25,7 @@
use core::marker::PhantomData;
use core::convert::TryInto;
use up_data_structs::TokenId;
-use up_evm_mapping::EvmBackwardsAddressMapping;
-use pallet_common::account::CrossAccountId;
+use frame_common::account::CrossAccountId;
use pallet_nonfungible::erc::{UniqueNFTCall, ERC721UniqueExtensionsCall, ERC721Call};
use pallet_fungible::erc::{UniqueFungibleCall, ERC20Call};
pallets/unique/src/lib.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627pub use serde::{Serialize, Deserialize};2829pub use frame_support::{30 construct_runtime, decl_module, decl_storage, decl_error, decl_event,31 dispatch::DispatchResult,32 ensure, fail, parameter_types,33 traits::{34 ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,35 IsSubType, WithdrawReasons,36 },37 weights::{38 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},39 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,40 WeightToFeePolynomial, DispatchClass,41 },42 StorageValue, transactional,43 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},44 BoundedVec,45};46use scale_info::TypeInfo;47use frame_system::{self as system, ensure_signed};48use sp_runtime::{sp_std::prelude::Vec};49use up_data_structs::{50 MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,51 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,52 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,53 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,54 CreateCollectionData, CustomDataLimit, CreateItemExData,55};56use pallet_common::{57 account::CrossAccountId, CollectionHandle, Pallet as PalletCommon, Error as CommonError,58 CommonWeightInfo,59};60use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};61use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};62use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6364#[cfg(test)]65mod mock;6667#[cfg(test)]68mod tests;6970mod eth;71mod sponsorship;72pub use sponsorship::UniqueSponsorshipHandler;73pub use eth::sponsoring::UniqueEthSponsorshipHandler;7475pub use eth::UniqueErcSupport;7677pub mod common;78use common::CommonWeights;79pub mod dispatch;80use dispatch::dispatch_call;8182#[cfg(feature = "runtime-benchmarks")]83mod benchmarking;84pub mod weights;85use weights::WeightInfo;8687decl_error! {88 /// Error for non-fungible-token module.89 pub enum Error for Module<T: Config> {90 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.91 CollectionDecimalPointLimitExceeded,92 /// This address is not set as sponsor, use setCollectionSponsor first.93 ConfirmUnsetSponsorFail,94 /// Length of items properties must be greater than 0.95 EmptyArgument,96 }97}9899pub trait Config:100 system::Config101 + pallet_evm_coder_substrate::Config102 + pallet_common::Config103 + pallet_nonfungible::Config104 + pallet_refungible::Config105 + pallet_fungible::Config106 + Sized107 + TypeInfo108{109 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;110111 /// Weight information for extrinsics in this pallet.112 type WeightInfo: WeightInfo;113}114115decl_event! {116 pub enum Event<T>117 where118 <T as frame_system::Config>::AccountId,119 <T as pallet_common::Config>::CrossAccountId,120 {121 /// Collection sponsor was removed122 ///123 /// # Arguments124 ///125 /// * collection_id: Globally unique collection identifier.126 CollectionSponsorRemoved(CollectionId),127128 /// Collection admin was added129 ///130 /// # Arguments131 ///132 /// * collection_id: Globally unique collection identifier.133 ///134 /// * admin: Admin address.135 CollectionAdminAdded(CollectionId, CrossAccountId),136137 /// Collection owned was change138 ///139 /// # Arguments140 ///141 /// * collection_id: Globally unique collection identifier.142 ///143 /// * owner: New owner address.144 CollectionOwnedChanged(CollectionId, AccountId),145146 /// Collection sponsor was set147 ///148 /// # Arguments149 ///150 /// * collection_id: Globally unique collection identifier.151 ///152 /// * owner: New sponsor address.153 CollectionSponsorSet(CollectionId, AccountId),154155 /// const on chain schema was set156 ///157 /// # Arguments158 ///159 /// * collection_id: Globally unique collection identifier.160 ConstOnChainSchemaSet(CollectionId),161162 /// New sponsor was confirm163 ///164 /// # Arguments165 ///166 /// * collection_id: Globally unique collection identifier.167 ///168 /// * sponsor: New sponsor address.169 SponsorshipConfirmed(CollectionId, AccountId),170171 /// Collection admin was removed172 ///173 /// # Arguments174 ///175 /// * collection_id: Globally unique collection identifier.176 ///177 /// * admin: Admin address.178 CollectionAdminRemoved(CollectionId, CrossAccountId),179180 /// Address was remove from allow list181 ///182 /// # Arguments183 ///184 /// * collection_id: Globally unique collection identifier.185 ///186 /// * user: Address.187 AllowListAddressRemoved(CollectionId, CrossAccountId),188189 /// Address was add to allow list190 ///191 /// # Arguments192 ///193 /// * collection_id: Globally unique collection identifier.194 ///195 /// * user: Address.196 AllowListAddressAdded(CollectionId, CrossAccountId),197198 /// Collection limits was set199 ///200 /// # Arguments201 ///202 /// * collection_id: Globally unique collection identifier.203 CollectionLimitSet(CollectionId),204205 /// Mint permission was set206 ///207 /// # Arguments208 ///209 /// * collection_id: Globally unique collection identifier.210 MintPermissionSet(CollectionId),211212 /// Offchain schema was set213 ///214 /// # Arguments215 ///216 /// * collection_id: Globally unique collection identifier.217 OffchainSchemaSet(CollectionId),218219 /// Public access mode was set220 ///221 /// # Arguments222 ///223 /// * collection_id: Globally unique collection identifier.224 ///225 /// * mode: New access state.226 PublicAccessModeSet(CollectionId, AccessMode),227228 /// Schema version was set229 ///230 /// # Arguments231 ///232 /// * collection_id: Globally unique collection identifier.233 SchemaVersionSet(CollectionId),234235 /// Variable on chain schema was set236 ///237 /// # Arguments238 ///239 /// * collection_id: Globally unique collection identifier.240 VariableOnChainSchemaSet(CollectionId),241 }242}243244type SelfWeightOf<T> = <T as Config>::WeightInfo;245246// # Used definitions247//248// ## User control levels249//250// chain-controlled - key is uncontrolled by user251// i.e autoincrementing index252// can use non-cryptographic hash253// real - key is controlled by user254// but it is hard to generate enough colliding values, i.e owner of signed txs255// can use non-cryptographic hash256// controlled - key is completly controlled by users257// i.e maps with mutable keys258// should use cryptographic hash259//260// ## User control level downgrade reasons261//262// ?1 - chain-controlled -> controlled263// collections/tokens can be destroyed, resulting in massive holes264// ?2 - chain-controlled -> controlled265// same as ?1, but can be only added, resulting in easier exploitation266// ?3 - real -> controlled267// no confirmation required, so addresses can be easily generated268decl_storage! {269 trait Store for Module<T: Config> as Unique {270271 //#region Private members272 /// Used for migrations273 ChainVersion: u64;274 //#endregion275276 //#region Tokens transfer rate limit baskets277 /// (Collection id (controlled?2), who created (real))278 /// TODO: Off chain worker should remove from this map when collection gets removed279 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;280 /// Collection id (controlled?2), token id (controlled?2)281 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;282 /// Collection id (controlled?2), owning user (real)283 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;284 /// Collection id (controlled?2), token id (controlled?2)285 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;286 //#endregion287288 /// Variable metadata sponsoring289 /// Collection id (controlled?2), token id (controlled?2)290 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;291 /// Approval sponsoring292 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;293 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;294 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;295 }296}297298decl_module! {299 pub struct Module<T: Config> for enum Call300 where301 origin: T::Origin302 {303 type Error = Error<T>;304305 fn deposit_event() = default;306307 fn on_initialize(_now: T::BlockNumber) -> Weight {308 0309 }310311 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.312 ///313 /// # Permissions314 ///315 /// * Anyone.316 ///317 /// # Arguments318 ///319 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.320 ///321 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.322 ///323 /// * token_prefix: UTF-8 string with token prefix.324 ///325 /// * mode: [CollectionMode] collection type and type dependent data.326 // returns collection ID327 #[weight = <SelfWeightOf<T>>::create_collection()]328 #[transactional]329 #[deprecated]330 pub fn create_collection(origin,331 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,332 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,333 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,334 mode: CollectionMode) -> DispatchResult {335 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {336 name: collection_name,337 description: collection_description,338 token_prefix,339 mode,340 ..Default::default()341 };342 Self::create_collection_ex(origin, data)343 }344345 /// This method creates a collection346 ///347 /// Prefer it to deprecated [`created_collection`] method348 #[weight = <SelfWeightOf<T>>::create_collection()]349 #[transactional]350 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {351 let owner = ensure_signed(origin)?;352353 let _id = match data.mode {354 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},355 CollectionMode::Fungible(decimal_points) => {356 // check params357 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);358 <PalletFungible<T>>::init_collection(owner, data)?359 }360 CollectionMode::ReFungible => {361 <PalletRefungible<T>>::init_collection(owner, data)?362 }363 };364365 Ok(())366 }367368 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.369 ///370 /// # Permissions371 ///372 /// * Collection Owner.373 ///374 /// # Arguments375 ///376 /// * collection_id: collection to destroy.377 #[weight = <SelfWeightOf<T>>::destroy_collection()]378 #[transactional]379 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {380 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);381382 let collection = <CollectionHandle<T>>::try_get(collection_id)?;383 collection.check_is_owner(&sender)?;384385 // =========386387 match collection.mode {388 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,389 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,390 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,391 }392393 <NftTransferBasket<T>>::remove_prefix(collection_id, None);394 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);395 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);396397 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);398 <NftApproveBasket<T>>::remove_prefix(collection_id, None);399 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);400 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);401402 Ok(())403 }404405 /// Add an address to allow list.406 ///407 /// # Permissions408 ///409 /// * Collection Owner410 /// * Collection Admin411 ///412 /// # Arguments413 ///414 /// * collection_id.415 ///416 /// * address.417 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]418 #[transactional]419 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{420421 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);422 let collection = <CollectionHandle<T>>::try_get(collection_id)?;423424 <PalletCommon<T>>::toggle_allowlist(425 &collection,426 &sender,427 &address,428 true,429 )?;430431 Self::deposit_event(Event::<T>::AllowListAddressAdded(432 collection_id,433 address434 ));435436 Ok(())437 }438439 /// Remove an address from allow list.440 ///441 /// # Permissions442 ///443 /// * Collection Owner444 /// * Collection Admin445 ///446 /// # Arguments447 ///448 /// * collection_id.449 ///450 /// * address.451 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]452 #[transactional]453 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{454455 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);456 let collection = <CollectionHandle<T>>::try_get(collection_id)?;457458 <PalletCommon<T>>::toggle_allowlist(459 &collection,460 &sender,461 &address,462 false,463 )?;464465 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(466 collection_id,467 address468 ));469470 Ok(())471 }472473 /// Toggle between normal and allow list access for the methods with access for `Anyone`.474 ///475 /// # Permissions476 ///477 /// * Collection Owner.478 ///479 /// # Arguments480 ///481 /// * collection_id.482 ///483 /// * mode: [AccessMode]484 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]485 #[transactional]486 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult487 {488 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);489490 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;491 target_collection.check_is_owner(&sender)?;492493 target_collection.access = mode.clone();494495 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(496 collection_id,497 mode498 ));499500 target_collection.save()501 }502503 /// Allows Anyone to create tokens if:504 /// * Allow List is enabled, and505 /// * Address is added to allow list, and506 /// * This method was called with True parameter507 ///508 /// # Permissions509 /// * Collection Owner510 ///511 /// # Arguments512 ///513 /// * collection_id.514 ///515 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.516 #[weight = <SelfWeightOf<T>>::set_mint_permission()]517 #[transactional]518 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult519 {520 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);521522 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;523 target_collection.check_is_owner(&sender)?;524525 target_collection.mint_mode = mint_permission;526527 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(528 collection_id529 ));530531 target_collection.save()532 }533534 /// Change the owner of the collection.535 ///536 /// # Permissions537 ///538 /// * Collection Owner.539 ///540 /// # Arguments541 ///542 /// * collection_id.543 ///544 /// * new_owner.545 #[weight = <SelfWeightOf<T>>::change_collection_owner()]546 #[transactional]547 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {548549 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);550551 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;552 target_collection.check_is_owner(&sender)?;553554 target_collection.owner = new_owner.clone();555 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(556 collection_id,557 new_owner558 ));559560 target_collection.save()561 }562563 /// Adds an admin of the Collection.564 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.565 ///566 /// # Permissions567 ///568 /// * Collection Owner.569 /// * Collection Admin.570 ///571 /// # Arguments572 ///573 /// * collection_id: ID of the Collection to add admin for.574 ///575 /// * new_admin_id: Address of new admin to add.576 #[weight = <SelfWeightOf<T>>::add_collection_admin()]577 #[transactional]578 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {579 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);580 let collection = <CollectionHandle<T>>::try_get(collection_id)?;581582 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(583 collection_id,584 new_admin_id.clone()585 ));586587 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)588 }589590 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.591 ///592 /// # Permissions593 ///594 /// * Collection Owner.595 /// * Collection Admin.596 ///597 /// # Arguments598 ///599 /// * collection_id: ID of the Collection to remove admin for.600 ///601 /// * account_id: Address of admin to remove.602 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]603 #[transactional]604 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {605 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);606 let collection = <CollectionHandle<T>>::try_get(collection_id)?;607608 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(609 collection_id,610 account_id.clone()611 ));612613 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)614 }615616 /// # Permissions617 ///618 /// * Collection Owner619 ///620 /// # Arguments621 ///622 /// * collection_id.623 ///624 /// * new_sponsor.625 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]626 #[transactional]627 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {628 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);629630 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;631 target_collection.check_is_owner(&sender)?;632633 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());634635 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(636 collection_id,637 new_sponsor638 ));639640 target_collection.save()641 }642643 /// # Permissions644 ///645 /// * Sponsor.646 ///647 /// # Arguments648 ///649 /// * collection_id.650 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]651 #[transactional]652 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {653 let sender = ensure_signed(origin)?;654655 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;656 ensure!(657 target_collection.sponsorship.pending_sponsor() == Some(&sender),658 Error::<T>::ConfirmUnsetSponsorFail659 );660661 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());662663 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(664 collection_id,665 sender666 ));667668 target_collection.save()669 }670671 /// Switch back to pay-per-own-transaction model.672 ///673 /// # Permissions674 ///675 /// * Collection owner.676 ///677 /// # Arguments678 ///679 /// * collection_id.680 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]681 #[transactional]682 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {683 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);684685 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;686 target_collection.check_is_owner(&sender)?;687688 target_collection.sponsorship = SponsorshipState::Disabled;689690 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(691 collection_id692 ));693 target_collection.save()694 }695696 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.697 ///698 /// # Permissions699 ///700 /// * Collection Owner.701 /// * Collection Admin.702 /// * Anyone if703 /// * Allow List is enabled, and704 /// * Address is added to allow list, and705 /// * MintPermission is enabled (see SetMintPermission method)706 ///707 /// # Arguments708 ///709 /// * collection_id: ID of the collection.710 ///711 /// * owner: Address, initial owner of the NFT.712 ///713 /// * data: Token data to store on chain.714 #[weight = <CommonWeights<T>>::create_item()]715 #[transactional]716 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {717 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);718719 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))720 }721722 /// This method creates multiple items in a collection created with CreateCollection method.723 ///724 /// # Permissions725 ///726 /// * Collection Owner.727 /// * Collection Admin.728 /// * Anyone if729 /// * Allow List is enabled, and730 /// * Address is added to allow list, and731 /// * MintPermission is enabled (see SetMintPermission method)732 ///733 /// # Arguments734 ///735 /// * collection_id: ID of the collection.736 ///737 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].738 ///739 /// * owner: Address, initial owner of the NFT.740 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]741 #[transactional]742 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {743 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);744 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);745746 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))747 }748749 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]750 #[transactional]751 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {752 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);753754 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))755 }756757 // TODO! transaction weight758759 /// Set transfers_enabled value for particular collection760 ///761 /// # Permissions762 ///763 /// * Collection Owner.764 ///765 /// # Arguments766 ///767 /// * collection_id: ID of the collection.768 ///769 /// * value: New flag value.770 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]771 #[transactional]772 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {773 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);774 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;775 target_collection.check_is_owner(&sender)?;776777 // =========778779 target_collection.limits.transfers_enabled = Some(value);780 target_collection.save()781 }782783 /// Destroys a concrete instance of NFT.784 ///785 /// # Permissions786 ///787 /// * Collection Owner.788 /// * Collection Admin.789 /// * Current NFT Owner.790 ///791 /// # Arguments792 ///793 /// * collection_id: ID of the collection.794 ///795 /// * item_id: ID of NFT to burn.796 #[weight = <CommonWeights<T>>::burn_item()]797 #[transactional]798 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {799 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);800801 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;802 if value == 1 {803 <NftTransferBasket<T>>::remove(collection_id, item_id);804 <NftApproveBasket<T>>::remove(collection_id, item_id);805 }806 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?807 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());808 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));809 Ok(post_info)810 }811812 /// Destroys a concrete instance of NFT on behalf of the owner813 /// See also: [`approve`]814 ///815 /// # Permissions816 ///817 /// * Collection Owner.818 /// * Collection Admin.819 /// * Current NFT Owner.820 ///821 /// # Arguments822 ///823 /// * collection_id: ID of the collection.824 ///825 /// * item_id: ID of NFT to burn.826 ///827 /// * from: owner of item828 #[weight = <CommonWeights<T>>::burn_from()]829 #[transactional]830 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {831 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);832833 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))834 }835836 /// Change ownership of the token.837 ///838 /// # Permissions839 ///840 /// * Collection Owner841 /// * Collection Admin842 /// * Current NFT owner843 ///844 /// # Arguments845 ///846 /// * recipient: Address of token recipient.847 ///848 /// * collection_id.849 ///850 /// * item_id: ID of the item851 /// * Non-Fungible Mode: Required.852 /// * Fungible Mode: Ignored.853 /// * Re-Fungible Mode: Required.854 ///855 /// * value: Amount to transfer.856 /// * Non-Fungible Mode: Ignored857 /// * Fungible Mode: Must specify transferred amount858 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)859 #[weight = <CommonWeights<T>>::transfer()]860 #[transactional]861 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {862 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);863864 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))865 }866867 /// Set, change, or remove approved address to transfer the ownership of the NFT.868 ///869 /// # Permissions870 ///871 /// * Collection Owner872 /// * Collection Admin873 /// * Current NFT owner874 ///875 /// # Arguments876 ///877 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).878 ///879 /// * collection_id.880 ///881 /// * item_id: ID of the item.882 #[weight = <CommonWeights<T>>::approve()]883 #[transactional]884 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {885 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);886887 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))888 }889890 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.891 ///892 /// # Permissions893 /// * Collection Owner894 /// * Collection Admin895 /// * Current NFT owner896 /// * Address approved by current NFT owner897 ///898 /// # Arguments899 ///900 /// * from: Address that owns token.901 ///902 /// * recipient: Address of token recipient.903 ///904 /// * collection_id.905 ///906 /// * item_id: ID of the item.907 ///908 /// * value: Amount to transfer.909 #[weight = <CommonWeights<T>>::transfer_from()]910 #[transactional]911 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {912 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);913914 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))915 }916917 /// Set off-chain data schema.918 ///919 /// # Permissions920 ///921 /// * Collection Owner922 /// * Collection Admin923 ///924 /// # Arguments925 ///926 /// * collection_id.927 ///928 /// * schema: String representing the offchain data schema.929 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]930 #[transactional]931 pub fn set_variable_meta_data (932 origin,933 collection_id: CollectionId,934 item_id: TokenId,935 data: BoundedVec<u8, CustomDataLimit>,936 ) -> DispatchResultWithPostInfo {937 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);938939 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))940 }941942 /// Set meta_update_permission value for particular collection943 ///944 /// # Permissions945 ///946 /// * Collection Owner.947 ///948 /// # Arguments949 ///950 /// * collection_id: ID of the collection.951 ///952 /// * value: New flag value.953 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]954 #[transactional]955 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {956 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);957 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;958959 ensure!(960 target_collection.meta_update_permission != MetaUpdatePermission::None,961 <CommonError<T>>::MetadataFlagFrozen,962 );963 target_collection.check_is_owner(&sender)?;964965 target_collection.meta_update_permission = value;966967 target_collection.save()968 }969970 /// Set schema standard971 /// ImageURL972 /// Unique973 ///974 /// # Permissions975 ///976 /// * Collection Owner977 /// * Collection Admin978 ///979 /// # Arguments980 ///981 /// * collection_id.982 ///983 /// * schema: SchemaVersion: enum984 #[weight = <SelfWeightOf<T>>::set_schema_version()]985 #[transactional]986 pub fn set_schema_version(987 origin,988 collection_id: CollectionId,989 version: SchemaVersion990 ) -> DispatchResult {991 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);992 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;993 target_collection.check_is_owner_or_admin(&sender)?;994 target_collection.schema_version = version;995996 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(997 collection_id998 ));9991000 target_collection.save()1001 }10021003 /// Set off-chain data schema.1004 ///1005 /// # Permissions1006 ///1007 /// * Collection Owner1008 /// * Collection Admin1009 ///1010 /// # Arguments1011 ///1012 /// * collection_id.1013 ///1014 /// * schema: String representing the offchain data schema.1015 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1016 #[transactional]1017 pub fn set_offchain_schema(1018 origin,1019 collection_id: CollectionId,1020 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1021 ) -> DispatchResult {1022 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1023 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1024 target_collection.check_is_owner_or_admin(&sender)?;10251026 target_collection.offchain_schema = schema;10271028 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1029 collection_id1030 ));10311032 target_collection.save()1033 }10341035 /// Set const on-chain data schema.1036 ///1037 /// # Permissions1038 ///1039 /// * Collection Owner1040 /// * Collection Admin1041 ///1042 /// # Arguments1043 ///1044 /// * collection_id.1045 ///1046 /// * schema: String representing the const on-chain data schema.1047 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1048 #[transactional]1049 pub fn set_const_on_chain_schema (1050 origin,1051 collection_id: CollectionId,1052 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1053 ) -> DispatchResult {1054 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1055 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1056 target_collection.check_is_owner_or_admin(&sender)?;10571058 target_collection.const_on_chain_schema = schema;10591060 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1061 collection_id1062 ));10631064 target_collection.save()1065 }10661067 /// Set variable on-chain data schema.1068 ///1069 /// # Permissions1070 ///1071 /// * Collection Owner1072 /// * Collection Admin1073 ///1074 /// # Arguments1075 ///1076 /// * collection_id.1077 ///1078 /// * schema: String representing the variable on-chain data schema.1079 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1080 #[transactional]1081 pub fn set_variable_on_chain_schema (1082 origin,1083 collection_id: CollectionId,1084 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1085 ) -> DispatchResult {1086 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1087 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1088 target_collection.check_is_owner_or_admin(&sender)?;10891090 target_collection.variable_on_chain_schema = schema;10911092 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1093 collection_id1094 ));10951096 target_collection.save()1097 }10981099 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1100 #[transactional]1101 pub fn set_collection_limits(1102 origin,1103 collection_id: CollectionId,1104 new_limit: CollectionLimits,1105 ) -> DispatchResult {1106 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1107 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1108 target_collection.check_is_owner(&sender)?;1109 let old_limit = &target_collection.limits;11101111 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11121113 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1114 collection_id1115 ));11161117 target_collection.save()1118 }1119 }1120}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617#![recursion_limit = "1024"]18#![cfg_attr(not(feature = "std"), no_std)]19#![allow(20 clippy::too_many_arguments,21 clippy::unnecessary_mut_passed,22 clippy::unused_unit23)]2425extern crate alloc;2627pub use serde::{Serialize, Deserialize};2829pub use frame_support::{30 construct_runtime, decl_module, decl_storage, decl_error, decl_event,31 dispatch::DispatchResult,32 ensure, fail, parameter_types,33 traits::{34 ExistenceRequirement, Get, Imbalance, KeyOwnerProofSystem, OnUnbalanced, Randomness,35 IsSubType, WithdrawReasons,36 },37 weights::{38 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},39 DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,40 WeightToFeePolynomial, DispatchClass,41 },42 StorageValue, transactional,43 pallet_prelude::{DispatchResultWithPostInfo, ConstU32},44 BoundedVec,45};46use scale_info::TypeInfo;47use frame_system::{self as system, ensure_signed};48use sp_runtime::{sp_std::prelude::Vec};49use up_data_structs::{50 MAX_DECIMAL_POINTS, VARIABLE_ON_CHAIN_SCHEMA_LIMIT, CONST_ON_CHAIN_SCHEMA_LIMIT,51 OFFCHAIN_SCHEMA_LIMIT, MAX_COLLECTION_NAME_LENGTH, MAX_COLLECTION_DESCRIPTION_LENGTH,52 MAX_TOKEN_PREFIX_LENGTH, AccessMode, CreateItemData, CollectionLimits, CollectionId,53 CollectionMode, TokenId, SchemaVersion, SponsorshipState, MetaUpdatePermission,54 CreateCollectionData, CustomDataLimit, CreateItemExData,55};56use pallet_common::{57 CollectionHandle, Pallet as PalletCommon, Error as CommonError,58 CommonWeightInfo,59};60use frame_common::account::CrossAccountId;61use pallet_refungible::{Pallet as PalletRefungible, RefungibleHandle};62use pallet_fungible::{Pallet as PalletFungible, FungibleHandle};63use pallet_nonfungible::{Pallet as PalletNonfungible, NonfungibleHandle};6465#[cfg(test)]66mod mock;6768#[cfg(test)]69mod tests;7071mod eth;72mod sponsorship;73pub use sponsorship::UniqueSponsorshipHandler;74pub use eth::sponsoring::UniqueEthSponsorshipHandler;7576pub use eth::UniqueErcSupport;7778pub mod common;79use common::CommonWeights;80pub mod dispatch;81use dispatch::dispatch_call;8283#[cfg(feature = "runtime-benchmarks")]84mod benchmarking;85pub mod weights;86use weights::WeightInfo;8788decl_error! {89 /// Error for non-fungible-token module.90 pub enum Error for Module<T: Config> {91 /// Decimal_points parameter must be lower than MAX_DECIMAL_POINTS constant, currently it is 30.92 CollectionDecimalPointLimitExceeded,93 /// This address is not set as sponsor, use setCollectionSponsor first.94 ConfirmUnsetSponsorFail,95 /// Length of items properties must be greater than 0.96 EmptyArgument,97 }98}99100pub trait Config:101 system::Config102 + pallet_evm_coder_substrate::Config103 + pallet_common::Config104 + pallet_nonfungible::Config105 + pallet_refungible::Config106 + pallet_fungible::Config107 + Sized108 + TypeInfo109{110 type Event: From<Event<Self>> + Into<<Self as frame_system::Config>::Event>;111112 /// Weight information for extrinsics in this pallet.113 type WeightInfo: WeightInfo;114}115116decl_event! {117 pub enum Event<T>118 where119 <T as frame_system::Config>::AccountId,120 <T as pallet_common::Config>::CrossAccountId,121 {122 /// Collection sponsor was removed123 ///124 /// # Arguments125 ///126 /// * collection_id: Globally unique collection identifier.127 CollectionSponsorRemoved(CollectionId),128129 /// Collection admin was added130 ///131 /// # Arguments132 ///133 /// * collection_id: Globally unique collection identifier.134 ///135 /// * admin: Admin address.136 CollectionAdminAdded(CollectionId, CrossAccountId),137138 /// Collection owned was change139 ///140 /// # Arguments141 ///142 /// * collection_id: Globally unique collection identifier.143 ///144 /// * owner: New owner address.145 CollectionOwnedChanged(CollectionId, AccountId),146147 /// Collection sponsor was set148 ///149 /// # Arguments150 ///151 /// * collection_id: Globally unique collection identifier.152 ///153 /// * owner: New sponsor address.154 CollectionSponsorSet(CollectionId, AccountId),155156 /// const on chain schema was set157 ///158 /// # Arguments159 ///160 /// * collection_id: Globally unique collection identifier.161 ConstOnChainSchemaSet(CollectionId),162163 /// New sponsor was confirm164 ///165 /// # Arguments166 ///167 /// * collection_id: Globally unique collection identifier.168 ///169 /// * sponsor: New sponsor address.170 SponsorshipConfirmed(CollectionId, AccountId),171172 /// Collection admin was removed173 ///174 /// # Arguments175 ///176 /// * collection_id: Globally unique collection identifier.177 ///178 /// * admin: Admin address.179 CollectionAdminRemoved(CollectionId, CrossAccountId),180181 /// Address was remove from allow list182 ///183 /// # Arguments184 ///185 /// * collection_id: Globally unique collection identifier.186 ///187 /// * user: Address.188 AllowListAddressRemoved(CollectionId, CrossAccountId),189190 /// Address was add to allow list191 ///192 /// # Arguments193 ///194 /// * collection_id: Globally unique collection identifier.195 ///196 /// * user: Address.197 AllowListAddressAdded(CollectionId, CrossAccountId),198199 /// Collection limits was set200 ///201 /// # Arguments202 ///203 /// * collection_id: Globally unique collection identifier.204 CollectionLimitSet(CollectionId),205206 /// Mint permission was set207 ///208 /// # Arguments209 ///210 /// * collection_id: Globally unique collection identifier.211 MintPermissionSet(CollectionId),212213 /// Offchain schema was set214 ///215 /// # Arguments216 ///217 /// * collection_id: Globally unique collection identifier.218 OffchainSchemaSet(CollectionId),219220 /// Public access mode was set221 ///222 /// # Arguments223 ///224 /// * collection_id: Globally unique collection identifier.225 ///226 /// * mode: New access state.227 PublicAccessModeSet(CollectionId, AccessMode),228229 /// Schema version was set230 ///231 /// # Arguments232 ///233 /// * collection_id: Globally unique collection identifier.234 SchemaVersionSet(CollectionId),235236 /// Variable on chain schema was set237 ///238 /// # Arguments239 ///240 /// * collection_id: Globally unique collection identifier.241 VariableOnChainSchemaSet(CollectionId),242 }243}244245type SelfWeightOf<T> = <T as Config>::WeightInfo;246247// # Used definitions248//249// ## User control levels250//251// chain-controlled - key is uncontrolled by user252// i.e autoincrementing index253// can use non-cryptographic hash254// real - key is controlled by user255// but it is hard to generate enough colliding values, i.e owner of signed txs256// can use non-cryptographic hash257// controlled - key is completly controlled by users258// i.e maps with mutable keys259// should use cryptographic hash260//261// ## User control level downgrade reasons262//263// ?1 - chain-controlled -> controlled264// collections/tokens can be destroyed, resulting in massive holes265// ?2 - chain-controlled -> controlled266// same as ?1, but can be only added, resulting in easier exploitation267// ?3 - real -> controlled268// no confirmation required, so addresses can be easily generated269decl_storage! {270 trait Store for Module<T: Config> as Unique {271272 //#region Private members273 /// Used for migrations274 ChainVersion: u64;275 //#endregion276277 //#region Tokens transfer rate limit baskets278 /// (Collection id (controlled?2), who created (real))279 /// TODO: Off chain worker should remove from this map when collection gets removed280 pub CreateItemBasket get(fn create_item_basket): map hasher(blake2_128_concat) (CollectionId, T::AccountId) => Option<T::BlockNumber>;281 /// Collection id (controlled?2), token id (controlled?2)282 pub NftTransferBasket get(fn nft_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;283 /// Collection id (controlled?2), owning user (real)284 pub FungibleTransferBasket get(fn fungible_transfer_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;285 /// Collection id (controlled?2), token id (controlled?2)286 pub ReFungibleTransferBasket get(fn refungible_transfer_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;287 //#endregion288289 /// Variable metadata sponsoring290 /// Collection id (controlled?2), token id (controlled?2)291 pub VariableMetaDataBasket get(fn variable_meta_data_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;292 /// Approval sponsoring293 pub NftApproveBasket get(fn nft_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId => Option<T::BlockNumber>;294 pub FungibleApproveBasket get(fn fungible_approve_basket): double_map hasher(blake2_128_concat) CollectionId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;295 pub RefungibleApproveBasket get(fn refungible_approve_basket): nmap hasher(blake2_128_concat) CollectionId, hasher(blake2_128_concat) TokenId, hasher(twox_64_concat) T::AccountId => Option<T::BlockNumber>;296 }297}298299decl_module! {300 pub struct Module<T: Config> for enum Call301 where302 origin: T::Origin303 {304 type Error = Error<T>;305306 fn deposit_event() = default;307308 fn on_initialize(_now: T::BlockNumber) -> Weight {309 0310 }311312 /// This method creates a Collection of NFTs. Each Token may have multiple properties encoded as an array of bytes of certain length. The initial owner of the collection is set to the address that signed the transaction and can be changed later.313 ///314 /// # Permissions315 ///316 /// * Anyone.317 ///318 /// # Arguments319 ///320 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.321 ///322 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.323 ///324 /// * token_prefix: UTF-8 string with token prefix.325 ///326 /// * mode: [CollectionMode] collection type and type dependent data.327 // returns collection ID328 #[weight = <SelfWeightOf<T>>::create_collection()]329 #[transactional]330 #[deprecated]331 pub fn create_collection(origin,332 collection_name: BoundedVec<u16, ConstU32<MAX_COLLECTION_NAME_LENGTH>>,333 collection_description: BoundedVec<u16, ConstU32<MAX_COLLECTION_DESCRIPTION_LENGTH>>,334 token_prefix: BoundedVec<u8, ConstU32<MAX_TOKEN_PREFIX_LENGTH>>,335 mode: CollectionMode) -> DispatchResult {336 let data: CreateCollectionData<T::AccountId> = CreateCollectionData {337 name: collection_name,338 description: collection_description,339 token_prefix,340 mode,341 ..Default::default()342 };343 Self::create_collection_ex(origin, data)344 }345346 /// This method creates a collection347 ///348 /// Prefer it to deprecated [`created_collection`] method349 #[weight = <SelfWeightOf<T>>::create_collection()]350 #[transactional]351 pub fn create_collection_ex(origin, data: CreateCollectionData<T::AccountId>) -> DispatchResult {352 let owner = ensure_signed(origin)?;353354 let _id = match data.mode {355 CollectionMode::NFT => {<PalletNonfungible<T>>::init_collection(owner, data)?},356 CollectionMode::Fungible(decimal_points) => {357 // check params358 ensure!(decimal_points <= MAX_DECIMAL_POINTS, Error::<T>::CollectionDecimalPointLimitExceeded);359 <PalletFungible<T>>::init_collection(owner, data)?360 }361 CollectionMode::ReFungible => {362 <PalletRefungible<T>>::init_collection(owner, data)?363 }364 };365366 Ok(())367 }368369 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.370 ///371 /// # Permissions372 ///373 /// * Collection Owner.374 ///375 /// # Arguments376 ///377 /// * collection_id: collection to destroy.378 #[weight = <SelfWeightOf<T>>::destroy_collection()]379 #[transactional]380 pub fn destroy_collection(origin, collection_id: CollectionId) -> DispatchResult {381 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);382383 let collection = <CollectionHandle<T>>::try_get(collection_id)?;384 collection.check_is_owner(&sender)?;385386 // =========387388 match collection.mode {389 CollectionMode::ReFungible => PalletRefungible::destroy_collection(RefungibleHandle::cast(collection), &sender)?,390 CollectionMode::Fungible(_) => PalletFungible::destroy_collection(FungibleHandle::cast(collection), &sender)?,391 CollectionMode::NFT => PalletNonfungible::destroy_collection(NonfungibleHandle::cast(collection), &sender)?,392 }393394 <NftTransferBasket<T>>::remove_prefix(collection_id, None);395 <FungibleTransferBasket<T>>::remove_prefix(collection_id, None);396 <ReFungibleTransferBasket<T>>::remove_prefix((collection_id,), None);397398 <VariableMetaDataBasket<T>>::remove_prefix(collection_id, None);399 <NftApproveBasket<T>>::remove_prefix(collection_id, None);400 <FungibleApproveBasket<T>>::remove_prefix(collection_id, None);401 <RefungibleApproveBasket<T>>::remove_prefix((collection_id,), None);402403 Ok(())404 }405406 /// Add an address to allow list.407 ///408 /// # Permissions409 ///410 /// * Collection Owner411 /// * Collection Admin412 ///413 /// # Arguments414 ///415 /// * collection_id.416 ///417 /// * address.418 #[weight = <SelfWeightOf<T>>::add_to_allow_list()]419 #[transactional]420 pub fn add_to_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{421422 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);423 let collection = <CollectionHandle<T>>::try_get(collection_id)?;424425 <PalletCommon<T>>::toggle_allowlist(426 &collection,427 &sender,428 &address,429 true,430 )?;431432 Self::deposit_event(Event::<T>::AllowListAddressAdded(433 collection_id,434 address435 ));436437 Ok(())438 }439440 /// Remove an address from allow list.441 ///442 /// # Permissions443 ///444 /// * Collection Owner445 /// * Collection Admin446 ///447 /// # Arguments448 ///449 /// * collection_id.450 ///451 /// * address.452 #[weight = <SelfWeightOf<T>>::remove_from_allow_list()]453 #[transactional]454 pub fn remove_from_allow_list(origin, collection_id: CollectionId, address: T::CrossAccountId) -> DispatchResult{455456 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);457 let collection = <CollectionHandle<T>>::try_get(collection_id)?;458459 <PalletCommon<T>>::toggle_allowlist(460 &collection,461 &sender,462 &address,463 false,464 )?;465466 <Pallet<T>>::deposit_event(Event::<T>::AllowListAddressRemoved(467 collection_id,468 address469 ));470471 Ok(())472 }473474 /// Toggle between normal and allow list access for the methods with access for `Anyone`.475 ///476 /// # Permissions477 ///478 /// * Collection Owner.479 ///480 /// # Arguments481 ///482 /// * collection_id.483 ///484 /// * mode: [AccessMode]485 #[weight = <SelfWeightOf<T>>::set_public_access_mode()]486 #[transactional]487 pub fn set_public_access_mode(origin, collection_id: CollectionId, mode: AccessMode) -> DispatchResult488 {489 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);490491 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;492 target_collection.check_is_owner(&sender)?;493494 target_collection.access = mode.clone();495496 <Pallet<T>>::deposit_event(Event::<T>::PublicAccessModeSet(497 collection_id,498 mode499 ));500501 target_collection.save()502 }503504 /// Allows Anyone to create tokens if:505 /// * Allow List is enabled, and506 /// * Address is added to allow list, and507 /// * This method was called with True parameter508 ///509 /// # Permissions510 /// * Collection Owner511 ///512 /// # Arguments513 ///514 /// * collection_id.515 ///516 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.517 #[weight = <SelfWeightOf<T>>::set_mint_permission()]518 #[transactional]519 pub fn set_mint_permission(origin, collection_id: CollectionId, mint_permission: bool) -> DispatchResult520 {521 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);522523 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;524 target_collection.check_is_owner(&sender)?;525526 target_collection.mint_mode = mint_permission;527528 <Pallet<T>>::deposit_event(Event::<T>::MintPermissionSet(529 collection_id530 ));531532 target_collection.save()533 }534535 /// Change the owner of the collection.536 ///537 /// # Permissions538 ///539 /// * Collection Owner.540 ///541 /// # Arguments542 ///543 /// * collection_id.544 ///545 /// * new_owner.546 #[weight = <SelfWeightOf<T>>::change_collection_owner()]547 #[transactional]548 pub fn change_collection_owner(origin, collection_id: CollectionId, new_owner: T::AccountId) -> DispatchResult {549550 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);551552 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;553 target_collection.check_is_owner(&sender)?;554555 target_collection.owner = new_owner.clone();556 <Pallet<T>>::deposit_event(Event::<T>::CollectionOwnedChanged(557 collection_id,558 new_owner559 ));560561 target_collection.save()562 }563564 /// Adds an admin of the Collection.565 /// NFT Collection can be controlled by multiple admin addresses (some which can also be servers, for example). Admins can issue and burn NFTs, as well as add and remove other admins, but cannot change NFT or Collection ownership.566 ///567 /// # Permissions568 ///569 /// * Collection Owner.570 /// * Collection Admin.571 ///572 /// # Arguments573 ///574 /// * collection_id: ID of the Collection to add admin for.575 ///576 /// * new_admin_id: Address of new admin to add.577 #[weight = <SelfWeightOf<T>>::add_collection_admin()]578 #[transactional]579 pub fn add_collection_admin(origin, collection_id: CollectionId, new_admin_id: T::CrossAccountId) -> DispatchResult {580 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);581 let collection = <CollectionHandle<T>>::try_get(collection_id)?;582583 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminAdded(584 collection_id,585 new_admin_id.clone()586 ));587588 <PalletCommon<T>>::toggle_admin(&collection, &sender, &new_admin_id, true)589 }590591 /// Remove admin address of the Collection. An admin address can remove itself. List of admins may become empty, in which case only Collection Owner will be able to add an Admin.592 ///593 /// # Permissions594 ///595 /// * Collection Owner.596 /// * Collection Admin.597 ///598 /// # Arguments599 ///600 /// * collection_id: ID of the Collection to remove admin for.601 ///602 /// * account_id: Address of admin to remove.603 #[weight = <SelfWeightOf<T>>::remove_collection_admin()]604 #[transactional]605 pub fn remove_collection_admin(origin, collection_id: CollectionId, account_id: T::CrossAccountId) -> DispatchResult {606 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);607 let collection = <CollectionHandle<T>>::try_get(collection_id)?;608609 <Pallet<T>>::deposit_event(Event::<T>::CollectionAdminRemoved(610 collection_id,611 account_id.clone()612 ));613614 <PalletCommon<T>>::toggle_admin(&collection, &sender, &account_id, false)615 }616617 /// # Permissions618 ///619 /// * Collection Owner620 ///621 /// # Arguments622 ///623 /// * collection_id.624 ///625 /// * new_sponsor.626 #[weight = <SelfWeightOf<T>>::set_collection_sponsor()]627 #[transactional]628 pub fn set_collection_sponsor(origin, collection_id: CollectionId, new_sponsor: T::AccountId) -> DispatchResult {629 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);630631 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;632 target_collection.check_is_owner(&sender)?;633634 target_collection.sponsorship = SponsorshipState::Unconfirmed(new_sponsor.clone());635636 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorSet(637 collection_id,638 new_sponsor639 ));640641 target_collection.save()642 }643644 /// # Permissions645 ///646 /// * Sponsor.647 ///648 /// # Arguments649 ///650 /// * collection_id.651 #[weight = <SelfWeightOf<T>>::confirm_sponsorship()]652 #[transactional]653 pub fn confirm_sponsorship(origin, collection_id: CollectionId) -> DispatchResult {654 let sender = ensure_signed(origin)?;655656 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;657 ensure!(658 target_collection.sponsorship.pending_sponsor() == Some(&sender),659 Error::<T>::ConfirmUnsetSponsorFail660 );661662 target_collection.sponsorship = SponsorshipState::Confirmed(sender.clone());663664 <Pallet<T>>::deposit_event(Event::<T>::SponsorshipConfirmed(665 collection_id,666 sender667 ));668669 target_collection.save()670 }671672 /// Switch back to pay-per-own-transaction model.673 ///674 /// # Permissions675 ///676 /// * Collection owner.677 ///678 /// # Arguments679 ///680 /// * collection_id.681 #[weight = <SelfWeightOf<T>>::remove_collection_sponsor()]682 #[transactional]683 pub fn remove_collection_sponsor(origin, collection_id: CollectionId) -> DispatchResult {684 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);685686 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;687 target_collection.check_is_owner(&sender)?;688689 target_collection.sponsorship = SponsorshipState::Disabled;690691 <Pallet<T>>::deposit_event(Event::<T>::CollectionSponsorRemoved(692 collection_id693 ));694 target_collection.save()695 }696697 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.698 ///699 /// # Permissions700 ///701 /// * Collection Owner.702 /// * Collection Admin.703 /// * Anyone if704 /// * Allow List is enabled, and705 /// * Address is added to allow list, and706 /// * MintPermission is enabled (see SetMintPermission method)707 ///708 /// # Arguments709 ///710 /// * collection_id: ID of the collection.711 ///712 /// * owner: Address, initial owner of the NFT.713 ///714 /// * data: Token data to store on chain.715 #[weight = <CommonWeights<T>>::create_item()]716 #[transactional]717 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResultWithPostInfo {718 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);719720 dispatch_call::<T, _>(collection_id, |d| d.create_item(sender, owner, data))721 }722723 /// This method creates multiple items in a collection created with CreateCollection method.724 ///725 /// # Permissions726 ///727 /// * Collection Owner.728 /// * Collection Admin.729 /// * Anyone if730 /// * Allow List is enabled, and731 /// * Address is added to allow list, and732 /// * MintPermission is enabled (see SetMintPermission method)733 ///734 /// # Arguments735 ///736 /// * collection_id: ID of the collection.737 ///738 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].739 ///740 /// * owner: Address, initial owner of the NFT.741 #[weight = <CommonWeights<T>>::create_multiple_items(items_data.len() as u32)]742 #[transactional]743 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResultWithPostInfo {744 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);745 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);746747 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items(sender, owner, items_data))748 }749750 #[weight = <CommonWeights<T>>::create_multiple_items_ex(&data)]751 #[transactional]752 pub fn create_multiple_items_ex(origin, collection_id: CollectionId, data: CreateItemExData<T::CrossAccountId>) -> DispatchResultWithPostInfo {753 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);754755 dispatch_call::<T, _>(collection_id, |d| d.create_multiple_items_ex(sender, data))756 }757758 // TODO! transaction weight759760 /// Set transfers_enabled value for particular collection761 ///762 /// # Permissions763 ///764 /// * Collection Owner.765 ///766 /// # Arguments767 ///768 /// * collection_id: ID of the collection.769 ///770 /// * value: New flag value.771 #[weight = <SelfWeightOf<T>>::set_transfers_enabled_flag()]772 #[transactional]773 pub fn set_transfers_enabled_flag(origin, collection_id: CollectionId, value: bool) -> DispatchResult {774 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);775 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;776 target_collection.check_is_owner(&sender)?;777778 // =========779780 target_collection.limits.transfers_enabled = Some(value);781 target_collection.save()782 }783784 /// Destroys a concrete instance of NFT.785 ///786 /// # Permissions787 ///788 /// * Collection Owner.789 /// * Collection Admin.790 /// * Current NFT Owner.791 ///792 /// # Arguments793 ///794 /// * collection_id: ID of the collection.795 ///796 /// * item_id: ID of NFT to burn.797 #[weight = <CommonWeights<T>>::burn_item()]798 #[transactional]799 pub fn burn_item(origin, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {800 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);801802 let post_info = dispatch_call::<T, _>(collection_id, |d| d.burn_item(sender, item_id, value))?;803 if value == 1 {804 <NftTransferBasket<T>>::remove(collection_id, item_id);805 <NftApproveBasket<T>>::remove(collection_id, item_id);806 }807 // Those maps should be cleared only if token disappears completly, need to move this part of logic to pallets?808 // <FungibleApproveBasket<T>>::remove(collection_id, sender.as_sub());809 // <RefungibleApproveBasket<T>>::remove((collection_id, item_id, sender.as_sub()));810 Ok(post_info)811 }812813 /// Destroys a concrete instance of NFT on behalf of the owner814 /// See also: [`approve`]815 ///816 /// # Permissions817 ///818 /// * Collection Owner.819 /// * Collection Admin.820 /// * Current NFT Owner.821 ///822 /// # Arguments823 ///824 /// * collection_id: ID of the collection.825 ///826 /// * item_id: ID of NFT to burn.827 ///828 /// * from: owner of item829 #[weight = <CommonWeights<T>>::burn_from()]830 #[transactional]831 pub fn burn_from(origin, collection_id: CollectionId, from: T::CrossAccountId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {832 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);833834 dispatch_call::<T, _>(collection_id, |d| d.burn_from(sender, from, item_id, value))835 }836837 /// Change ownership of the token.838 ///839 /// # Permissions840 ///841 /// * Collection Owner842 /// * Collection Admin843 /// * Current NFT owner844 ///845 /// # Arguments846 ///847 /// * recipient: Address of token recipient.848 ///849 /// * collection_id.850 ///851 /// * item_id: ID of the item852 /// * Non-Fungible Mode: Required.853 /// * Fungible Mode: Ignored.854 /// * Re-Fungible Mode: Required.855 ///856 /// * value: Amount to transfer.857 /// * Non-Fungible Mode: Ignored858 /// * Fungible Mode: Must specify transferred amount859 /// * Re-Fungible Mode: Must specify transferred portion (between 0 and 1)860 #[weight = <CommonWeights<T>>::transfer()]861 #[transactional]862 pub fn transfer(origin, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128) -> DispatchResultWithPostInfo {863 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);864865 dispatch_call::<T, _>(collection_id, |d| d.transfer(sender, recipient, item_id, value))866 }867868 /// Set, change, or remove approved address to transfer the ownership of the NFT.869 ///870 /// # Permissions871 ///872 /// * Collection Owner873 /// * Collection Admin874 /// * Current NFT owner875 ///876 /// # Arguments877 ///878 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).879 ///880 /// * collection_id.881 ///882 /// * item_id: ID of the item.883 #[weight = <CommonWeights<T>>::approve()]884 #[transactional]885 pub fn approve(origin, spender: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, amount: u128) -> DispatchResultWithPostInfo {886 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);887888 dispatch_call::<T, _>(collection_id, |d| d.approve(sender, spender, item_id, amount))889 }890891 /// Change ownership of a NFT on behalf of the owner. See Approve method for additional information. After this method executes, the approval is removed so that the approved address will not be able to transfer this NFT again from this owner.892 ///893 /// # Permissions894 /// * Collection Owner895 /// * Collection Admin896 /// * Current NFT owner897 /// * Address approved by current NFT owner898 ///899 /// # Arguments900 ///901 /// * from: Address that owns token.902 ///903 /// * recipient: Address of token recipient.904 ///905 /// * collection_id.906 ///907 /// * item_id: ID of the item.908 ///909 /// * value: Amount to transfer.910 #[weight = <CommonWeights<T>>::transfer_from()]911 #[transactional]912 pub fn transfer_from(origin, from: T::CrossAccountId, recipient: T::CrossAccountId, collection_id: CollectionId, item_id: TokenId, value: u128 ) -> DispatchResultWithPostInfo {913 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);914915 dispatch_call::<T, _>(collection_id, |d| d.transfer_from(sender, from, recipient, item_id, value))916 }917918 /// Set off-chain data schema.919 ///920 /// # Permissions921 ///922 /// * Collection Owner923 /// * Collection Admin924 ///925 /// # Arguments926 ///927 /// * collection_id.928 ///929 /// * schema: String representing the offchain data schema.930 #[weight = <CommonWeights<T>>::set_variable_metadata(data.len() as u32)]931 #[transactional]932 pub fn set_variable_meta_data (933 origin,934 collection_id: CollectionId,935 item_id: TokenId,936 data: BoundedVec<u8, CustomDataLimit>,937 ) -> DispatchResultWithPostInfo {938 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);939940 dispatch_call::<T, _>(collection_id, |d| d.set_variable_metadata(sender, item_id, data))941 }942943 /// Set meta_update_permission value for particular collection944 ///945 /// # Permissions946 ///947 /// * Collection Owner.948 ///949 /// # Arguments950 ///951 /// * collection_id: ID of the collection.952 ///953 /// * value: New flag value.954 #[weight = <SelfWeightOf<T>>::set_meta_update_permission_flag()]955 #[transactional]956 pub fn set_meta_update_permission_flag(origin, collection_id: CollectionId, value: MetaUpdatePermission) -> DispatchResult {957 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);958 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;959960 ensure!(961 target_collection.meta_update_permission != MetaUpdatePermission::None,962 <CommonError<T>>::MetadataFlagFrozen,963 );964 target_collection.check_is_owner(&sender)?;965966 target_collection.meta_update_permission = value;967968 target_collection.save()969 }970971 /// Set schema standard972 /// ImageURL973 /// Unique974 ///975 /// # Permissions976 ///977 /// * Collection Owner978 /// * Collection Admin979 ///980 /// # Arguments981 ///982 /// * collection_id.983 ///984 /// * schema: SchemaVersion: enum985 #[weight = <SelfWeightOf<T>>::set_schema_version()]986 #[transactional]987 pub fn set_schema_version(988 origin,989 collection_id: CollectionId,990 version: SchemaVersion991 ) -> DispatchResult {992 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);993 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;994 target_collection.check_is_owner_or_admin(&sender)?;995 target_collection.schema_version = version;996997 <Pallet<T>>::deposit_event(Event::<T>::SchemaVersionSet(998 collection_id999 ));10001001 target_collection.save()1002 }10031004 /// Set off-chain data schema.1005 ///1006 /// # Permissions1007 ///1008 /// * Collection Owner1009 /// * Collection Admin1010 ///1011 /// # Arguments1012 ///1013 /// * collection_id.1014 ///1015 /// * schema: String representing the offchain data schema.1016 #[weight = <SelfWeightOf<T>>::set_offchain_schema(schema.len() as u32)]1017 #[transactional]1018 pub fn set_offchain_schema(1019 origin,1020 collection_id: CollectionId,1021 schema: BoundedVec<u8, ConstU32<OFFCHAIN_SCHEMA_LIMIT>>,1022 ) -> DispatchResult {1023 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1024 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1025 target_collection.check_is_owner_or_admin(&sender)?;10261027 target_collection.offchain_schema = schema;10281029 <Pallet<T>>::deposit_event(Event::<T>::OffchainSchemaSet(1030 collection_id1031 ));10321033 target_collection.save()1034 }10351036 /// Set const on-chain data schema.1037 ///1038 /// # Permissions1039 ///1040 /// * Collection Owner1041 /// * Collection Admin1042 ///1043 /// # Arguments1044 ///1045 /// * collection_id.1046 ///1047 /// * schema: String representing the const on-chain data schema.1048 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1049 #[transactional]1050 pub fn set_const_on_chain_schema (1051 origin,1052 collection_id: CollectionId,1053 schema: BoundedVec<u8, ConstU32<CONST_ON_CHAIN_SCHEMA_LIMIT>>1054 ) -> DispatchResult {1055 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1056 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1057 target_collection.check_is_owner_or_admin(&sender)?;10581059 target_collection.const_on_chain_schema = schema;10601061 <Pallet<T>>::deposit_event(Event::<T>::ConstOnChainSchemaSet(1062 collection_id1063 ));10641065 target_collection.save()1066 }10671068 /// Set variable on-chain data schema.1069 ///1070 /// # Permissions1071 ///1072 /// * Collection Owner1073 /// * Collection Admin1074 ///1075 /// # Arguments1076 ///1077 /// * collection_id.1078 ///1079 /// * schema: String representing the variable on-chain data schema.1080 #[weight = <SelfWeightOf<T>>::set_const_on_chain_schema(schema.len() as u32)]1081 #[transactional]1082 pub fn set_variable_on_chain_schema (1083 origin,1084 collection_id: CollectionId,1085 schema: BoundedVec<u8, ConstU32<VARIABLE_ON_CHAIN_SCHEMA_LIMIT>>1086 ) -> DispatchResult {1087 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1088 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1089 target_collection.check_is_owner_or_admin(&sender)?;10901091 target_collection.variable_on_chain_schema = schema;10921093 <Pallet<T>>::deposit_event(Event::<T>::VariableOnChainSchemaSet(1094 collection_id1095 ));10961097 target_collection.save()1098 }10991100 #[weight = <SelfWeightOf<T>>::set_collection_limits()]1101 #[transactional]1102 pub fn set_collection_limits(1103 origin,1104 collection_id: CollectionId,1105 new_limit: CollectionLimits,1106 ) -> DispatchResult {1107 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);1108 let mut target_collection = <CollectionHandle<T>>::try_get(collection_id)?;1109 target_collection.check_is_owner(&sender)?;1110 let old_limit = &target_collection.limits;11111112 target_collection.limits = <PalletCommon<T>>::clamp_limits(target_collection.mode.clone(), &old_limit, new_limit)?;11131114 <Pallet<T>>::deposit_event(Event::<T>::CollectionLimitSet(1115 collection_id1116 ));11171118 target_collection.save()1119 }1120 }1121}pallets/unique/src/mock.rsdiffbeforeafterboth--- a/pallets/unique/src/mock.rs
+++ b/pallets/unique/src/mock.rs
@@ -26,7 +26,8 @@
use pallet_transaction_payment::{CurrencyAdapter};
use frame_system as system;
use pallet_evm::{AddressMapping, runner::stack::MaybeMirroredLog};
-use pallet_common::account::{EvmBackwardsAddressMapping, CrossAccountId};
+use up_evm_mapping::EvmBackwardsAddressMapping;
+use frame_common::account::CrossAccountId;
use codec::{Encode, Decode, MaxEncodedLen};
use scale_info::TypeInfo;
use up_data_structs::ConstU32;
pallets/unique/src/sponsorship.rsdiffbeforeafterboth--- a/pallets/unique/src/sponsorship.rs
+++ b/pallets/unique/src/sponsorship.rs
@@ -30,7 +30,7 @@
NFT_SPONSOR_TRANSFER_TIMEOUT, REFUNGIBLE_SPONSOR_TRANSFER_TIMEOUT, TokenId,
};
use pallet_common::{CollectionHandle};
-use pallet_common::account::CrossAccountId;
+use frame_common::account::CrossAccountId;
pub fn withdraw_transfer<T: Config>(
collection: &CollectionHandle<T>,
primitives/evm-mapping/Cargo.tomldiffbeforeafterboth--- a/primitives/evm-mapping/Cargo.toml
+++ /dev/null
@@ -1,13 +0,0 @@
-[package]
-name = "up-evm-mapping"
-version = "0.1.0"
-license = "GPLv3"
-edition = "2021"
-
-[dependencies]
-sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
-frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
-
-[features]
-default = ["std"]
-std = ["sp-core/std", "frame-support/std"]
primitives/evm-mapping/src/lib.rsdiffbeforeafterboth--- a/primitives/evm-mapping/src/lib.rs
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-#![cfg_attr(not(feature = "std"), no_std)]
-
-use frame_support::sp_runtime::AccountId32;
-use sp_core::H160;
-
-/// Transforms substrate addresses to ethereum (Reverse of `EvmAddressMapping`)
-/// pallet_evm doesn't have this, as it only checks if eth address
-/// is owned by substrate via `EnsureAddressOrigin` trait
-///
-/// This trait implementations shouldn't conflict with used `EnsureAddressOrigin`
-pub trait EvmBackwardsAddressMapping<AccountId> {
- fn from_account_id(account_id: AccountId) -> H160;
-}
-
-/// Should have same mapping as EnsureAddressTruncated
-pub struct MapBackwardsAddressTruncated;
-impl EvmBackwardsAddressMapping<AccountId32> for MapBackwardsAddressTruncated {
- fn from_account_id(account_id: AccountId32) -> H160 {
- let mut out = [0; 20];
- out.copy_from_slice(&(account_id.as_ref() as &[u8])[0..20]);
- H160(out)
- }
-}
primitives/rpc/Cargo.tomldiffbeforeafterboth--- a/primitives/rpc/Cargo.toml
+++ b/primitives/rpc/Cargo.toml
@@ -14,6 +14,7 @@
sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-api = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.18' }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
[features]
default = ["std"]
primitives/rpc/src/lib.rsdiffbeforeafterboth--- a/primitives/rpc/src/lib.rs
+++ b/primitives/rpc/src/lib.rs
@@ -28,7 +28,7 @@
#[api_version(2)]
pub trait UniqueApi<CrossAccountId, AccountId> where
AccountId: Decode,
- CrossAccountId: pallet_common::account::CrossAccountId<AccountId>,
+ CrossAccountId: frame_common::account::CrossAccountId<AccountId>,
{
#[changed_in(2)]
fn token_owner(collection: CollectionId, token: TokenId) -> Result<CrossAccountId>;
runtime/opal/src/lib.rsdiffbeforeafterboth--- a/runtime/opal/src/lib.rs
+++ b/runtime/opal/src/lib.rs
@@ -116,11 +116,10 @@
pub const RUNTIME_NAME: &str = "Opal";
-type CrossAccountId = pallet_common::account::BasicCrossAccountId<Runtime>;
+type CrossAccountId = frame_common::account::BasicCrossAccountId<Runtime>;
impl RuntimeInstance for Runtime {
type CrossAccountId = self::CrossAccountId;
-
type TransactionConverter = self::TransactionConverter;
fn get_transaction_converter() -> TransactionConverter {
@@ -286,6 +285,11 @@
type WeightInfo = pallet_evm_migration::weights::SubstrateWeight<Self>;
}
+impl frame_common::account::Config for Runtime {
+ type EvmAddressMapping = pallet_evm::HashedAddressMapping<Self::Hashing>;
+ type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
+}
+
pub struct EthereumFindAuthor<F>(core::marker::PhantomData<F>);
impl<F: FindAuthor<u32>> FindAuthor<H160> for EthereumFindAuthor<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
@@ -846,7 +850,7 @@
type Event = Event;
type EvmBackwardsAddressMapping = up_evm_mapping::MapBackwardsAddressTruncated;
type EvmAddressMapping = HashedAddressMapping<Self::Hashing>;
- type CrossAccountId = pallet_common::account::BasicCrossAccountId<Self>;
+ type CrossAccountId = frame_common::account::BasicCrossAccountId<Self>;
type Currency = Balances;
type CollectionCreationPrice = CollectionCreationPrice;
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -382,7 +382,6 @@
derivative = "2.2.0"
pallet-unique = { path = '../../pallets/unique', default-features = false }
up-rpc = { path = "../../primitives/rpc", default-features = false }
-up-evm-mapping = { path = "../../primitives/evm-mapping", default-features = false }
pallet-inflation = { path = '../../pallets/inflation', default-features = false }
up-data-structs = { path = '../../primitives/data-structs', default-features = false }
pallet-common = { default-features = false, path = "../../pallets/common" }
@@ -401,6 +400,8 @@
pallet-base-fee = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
fp-rpc = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
fp-self-contained = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.18" }
+up-evm-mapping = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
+frame-common = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "feature/300" }
################################################################################
# Build Dependencies