git.delta.rocks / unique-network / refs/commits / 25b82cffb2c3

difftreelog

style fix clippy/rustfmt warnings

Yaroslav Bolyukin2021-06-25parent: #fa23d15.patch.diff
in: master

35 files changed

modifiedcrates/evm-coder-macros/src/lib.rsdiffbeforeafterboth
1#![allow(dead_code)]
2
1use darling::FromMeta;3use darling::FromMeta;
2use inflector::cases;4use inflector::cases;
modifiedcrates/evm-coder-macros/src/solidity_interface.rsdiffbeforeafterboth
1#![allow(dead_code)]
2
1use quote::quote;3use quote::quote;
2use darling::FromMeta;4use darling::FromMeta;
545 #(547 #(
546 #call_inner548 #call_inner
547 )*549 )*
550 #[allow(unreachable_code)] // In case of no inner calls
548 fn call(&mut self, c: Msg<#call_name>) -> ::core::result::Result<::evm_coder::abi::AbiWriter, Self::Error> {551 fn call(&mut self, c: Msg<#call_name>) -> ::core::result::Result<::evm_coder::abi::AbiWriter, Self::Error> {
549 use ::evm_coder::abi::AbiWrite;552 use ::evm_coder::abi::AbiWrite;
550 type InternalCall = #call_name;553 type InternalCall = #call_name;
modifiedcrates/evm-coder/tests/a.rsdiffbeforeafterboth
1#![allow(dead_code)] // This test only checks that macros is not panicking
2
1use evm_coder::{solidity_interface, types::*, ToLog};3use evm_coder::{solidity_interface, types::*, ToLog};
2use evm_coder_macros::solidity;4use evm_coder_macros::solidity;
modifiednode/cli/build.rsdiffbeforeafterboth

no syntactic changes

modifiednode/cli/src/chain_spec.rsdiffbeforeafterboth
64 // ID64 // ID
65 "dev",65 "dev",
66 ChainType::Local,66 ChainType::Local,
67 move || testnet_genesis(67 move || {
68 testnet_genesis(
68 // Sudo account69 // Sudo account
69 get_account_id_from_seed::<sr25519::Public>("Alice"),70 get_account_id_from_seed::<sr25519::Public>("Alice"),
78 ],79 ],
79 id,80 id,
80 ),81 )
82 },
81 // Bootnodes83 // Bootnodes
82 vec![],84 vec![],
83 // Telemetry85 // Telemetry
101 // ID103 // ID
102 "local_testnet",104 "local_testnet",
103 ChainType::Local,105 ChainType::Local,
104 move || testnet_genesis(106 move || {
107 testnet_genesis(
105 // Sudo account108 // Sudo account
106 get_account_id_from_seed::<sr25519::Public>("Alice"),109 get_account_id_from_seed::<sr25519::Public>("Alice"),
125 ],128 ],
126 id,129 id,
127 ),130 )
131 },
128 // Bootnodes132 // Bootnodes
129 vec![],133 vec![],
130 // Telemetry134 // Telemetry
190 offchain_schema: vec![],191 offchain_schema: vec![],
191 schema_version: SchemaVersion::default(),192 schema_version: SchemaVersion::default(),
192 sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<sr25519::Public>("Alice")),193 sponsorship: SponsorshipState::Confirmed(get_account_id_from_seed::<
194 sr25519::Public,
195 >("Alice")),
193 const_on_chain_schema: vec![],196 const_on_chain_schema: vec![],
194 variable_on_chain_schema: vec![],197 variable_on_chain_schema: vec![],
195 limits: CollectionLimits::default()198 limits: CollectionLimits::default(),
196 },199 },
197 )],200 )],
198 nft_item_id: vec![],201 nft_item_id: vec![],
modifiednode/cli/src/command.rsdiffbeforeafterboth
18use crate::{18use crate::{
19 chain_spec,19 chain_spec,
20 cli::{Cli, RelayChainCli, Subcommand},20 cli::{Cli, RelayChainCli, Subcommand},
21 service::{new_partial, ParachainRuntimeExecutor}21 service::{new_partial, ParachainRuntimeExecutor},
22};22};
23use codec::Encode;23use codec::Encode;
24use cumulus_primitives_core::ParaId;24use cumulus_primitives_core::ParaId;
31 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,31 NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
32};32};
33use sc_service::{33use sc_service::{
34 config::{BasePath, PrometheusConfig}34 config::{BasePath, PrometheusConfig},
35};35};
36use sp_core::hexdisplay::HexDisplay;36use sp_core::hexdisplay::HexDisplay;
37use sp_runtime::traits::Block as BlockT;37use sp_runtime::traits::Block as BlockT;
251 }251 }
252252
253 Ok(())253 Ok(())
254 },254 }
255 Some(Subcommand::Benchmark(cmd)) => {255 Some(Subcommand::Benchmark(cmd)) => {
256 if cfg!(feature = "runtime-benchmarks") {256 if cfg!(feature = "runtime-benchmarks") {
257 let runner = cli.create_runner(cmd)?;257 let runner = cli.create_runner(cmd)?;
262 You can enable it with `--features runtime-benchmarks`.".into())262 You can enable it with `--features runtime-benchmarks`."
263 .into())
263 }264 }
264 },265 }
265 None => {266 None => {
266 let runner = cli.create_runner(&cli.run.normalize())?;267 let runner = cli.create_runner(&cli.run.normalize())?;
267268
modifiednode/cli/src/service.rsdiffbeforeafterboth
1616
17// Cumulus Imports17// Cumulus Imports
18use cumulus_client_consensus_aura::{18use cumulus_client_consensus_aura::{build_aura_consensus, BuildAuraConsensusParams, SlotProportion};
19 build_aura_consensus, BuildAuraConsensusParams, SlotProportion,
20};
21use cumulus_client_consensus_common::ParachainConsensus;19use cumulus_client_consensus_common::ParachainConsensus;
22use cumulus_client_network::build_block_announce_validator;20use cumulus_client_network::build_block_announce_validator;
71 source: fc_db::DatabaseSettingsSrc::RocksDb {71 source: fc_db::DatabaseSettingsSrc::RocksDb {
72 path: database_dir,72 path: database_dir,
73 cache_size: 0,73 cache_size: 0,
74 }74 },
75 })?))75 },
76 )?))
76}77}
7778
85///86///
86/// Use this macro if you don't actually need the full service, but just the builder in order to87/// Use this macro if you don't actually need the full service, but just the builder in order to
87/// be able to perform chain operations.88/// be able to perform chain operations.
89#[allow(clippy::type_complexity)]
88pub fn new_partial<BIQ>(90pub fn new_partial<BIQ>(
89 config: &Configuration,91 config: &Configuration,
90 build_import_queue: BIQ,92 build_import_queue: BIQ,
102 PendingTransactions,
103 Option<FilterPool>,
104 Arc<fc_db::Backend<Block>>,
105 Option<TelemetryWorkerHandle>,
106 ),
99 >,107 >,
100 sc_service::Error,108 sc_service::Error,
109 &TaskManager,117 &TaskManager,
110 ) -> Result<118 ) -> Result<sp_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error>,
111 sp_consensus::DefaultImportQueue<Block, FullClient>,
112 sc_service::Error,
113 >,
114{119{
115 let telemetry = config120 let _telemetry = config
116 .telemetry_endpoints121 .telemetry_endpoints
117 .clone()122 .clone()
118 .filter(|x| !x.is_empty())123 .filter(|x| !x.is_empty())
189 pending_transactions,
190 filter_pool,
191 frontier_backend,
192 telemetry_worker_handle,
193 ),
182 };194 };
183195
206 &TaskManager,218 &TaskManager,
207 ) -> Result<219 ) -> Result<sp_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error>,
208 sp_consensus::DefaultImportQueue<Block, FullClient>,
209 sc_service::Error,
210 >,
211 BIC: FnOnce(220 BIC: FnOnce(
212 Arc<FullClient>,221 Arc<FullClient>,
241 pending_transactions,
242 filter_pool,
243 frontier_backend,
244 telemetry_worker_handle,
245 ) = params.other;
231246
232 let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(247 let relay_chain_full_node = cumulus_client_service::build_polkadot_full_node(
283 network: rpc_network.clone(),298 network: rpc_network.clone(),
284 pending_transactions: pending_transactions.clone(),299 pending_transactions: pending_transactions.clone(),
285 select_chain: select_chain.clone(),300 select_chain: select_chain.clone(),
286 is_authority: is_authority.clone(),301 is_authority,
287 // TODO: Unhardcode302 // TODO: Unhardcode
288 max_past_logs: 10000,303 max_past_logs: 10000,
289 };304 };
367) -> Result<382) -> Result<sp_consensus::DefaultImportQueue<Block, FullClient>, sc_service::Error> {
368 sp_consensus::DefaultImportQueue<
369 Block,
370 FullClient,
371 >,
372 sc_service::Error,
373> {
374 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;383 let slot_duration = cumulus_client_consensus_aura::slot_duration(&*client)?;
375
396404
397 Ok((time, slot))405 Ok((time, slot))
398 },406 },
399 registry: config.prometheus_registry().clone(),407 registry: config.prometheus_registry(),
400 can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),408 can_author_with: sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone()),
401 spawner: &task_manager.spawn_essential_handle(),409 spawner: &task_manager.spawn_essential_handle(),
402 telemetry,410 telemetry,
432 task_manager.spawn_handle(),440 task_manager.spawn_handle(),
433 client.clone(),441 client.clone(),
434 transaction_pool,442 transaction_pool,
435 prometheus_registry.clone(),443 prometheus_registry,
436 telemetry.clone(),444 telemetry.clone(),
437 );445 );
438446
480 block_import: client.clone(),488 block_import: client.clone(),
481 relay_chain_client: relay_chain_node.client.clone(),489 relay_chain_client: relay_chain_node.client.clone(),
482 relay_chain_backend: relay_chain_node.backend.clone(),490 relay_chain_backend: relay_chain_node.backend.clone(),
483 para_client: client.clone(),491 para_client: client,
484 backoff_authoring_blocks: Option::<()>::None,492 backoff_authoring_blocks: Option::<()>::None,
485 sync_oracle,493 sync_oracle,
486 keystore,494 keystore,
modifiednode/rpc/src/lib.rsdiffbeforeafterboth
189 pool.clone(),189 pool.clone(),
190 nft_runtime::TransactionConverter,190 nft_runtime::TransactionConverter,
191 network.clone(),191 network.clone(),
192 pending_transactions.clone(),192 pending_transactions,
193 signers,193 signers,
194 overrides.clone(),194 overrides.clone(),
195 backend,195 backend,
200 if let Some(filter_pool) = filter_pool {200 if let Some(filter_pool) = filter_pool {
201 io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new(201 io.extend_with(EthFilterApiServer::to_delegate(EthFilterApi::new(
202 client.clone(),202 client.clone(),
203 filter_pool.clone(),203 filter_pool,
204 500 as usize, // max stored filters204 500_usize, // max stored filters
205 overrides.clone(),205 overrides.clone(),
206 max_past_logs,206 max_past_logs,
207 )));207 )));
217 io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(client.clone())));217 io.extend_with(Web3ApiServer::to_delegate(Web3Api::new(client.clone())));
218218
219 io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new(219 io.extend_with(EthPubSubApiServer::to_delegate(EthPubSubApi::new(
220 pool.clone(),220 pool,
221 client.clone(),221 client,
222 network.clone(),222 network,
223 SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(223 SubscriptionManager::<HexEncodedIdProvider>::with_id_provider(
224 HexEncodedIdProvider::default(),224 HexEncodedIdProvider::default(),
225 Arc::new(subscription_task_executor),225 Arc::new(subscription_task_executor),
modifiedpallets/contract-helpers/src/lib.rsdiffbeforeafterboth
174 _info: &DispatchInfoOf<Self::Call>,186 _info: &DispatchInfoOf<Self::Call>,
175 _len: usize,187 _len: usize,
176 ) -> transaction_validity::TransactionValidity {188 ) -> transaction_validity::TransactionValidity {
177 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {
178 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {189 if let Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) =
190 IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call)
191 {
179 let called_contract: T::AccountId =192 let called_contract: T::AccountId =
180 T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());193 T::Lookup::lookup((*dest).clone()).unwrap_or_default();
181 if <AllowlistEnabled<T>>::get(&called_contract) {194 if <AllowlistEnabled<T>>::get(&called_contract)
182 if !<Allowlist<T>>::get(&called_contract, who)195 && !<Allowlist<T>>::get(&called_contract, who)
183 && &<Owner<T>>::get(&called_contract) != who196 && &<Owner<T>>::get(&called_contract) != who
184 {197 {
185 return Err(transaction_validity::InvalidTransaction::Call.into());198 return Err(transaction_validity::InvalidTransaction::Call.into());
186 }199 }
187 }
188 }200 }
189 _ => {}
190 }
191 Ok(transaction_validity::ValidTransaction::default())201 Ok(transaction_validity::ValidTransaction::default())
192 }202 }
193203
200 ) -> Result<Self::Pre, TransactionValidityError> {210 ) -> Result<Self::Pre, TransactionValidityError> {
201 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {211 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {
202 Some(pallet_contracts::Call::instantiate(_, _, code_hash, _, salt)) => {212 Some(pallet_contracts::Call::instantiate(_, _, code_hash, _, salt)) => {
203 Ok(Some((who.clone(), code_hash.clone(), salt.clone())))213 Ok(Some((who.clone(), *code_hash, salt.clone())))
204 }214 }
205 Some(pallet_contracts::Call::instantiate_with_code(_, _, code, _, salt)) => {215 Some(pallet_contracts::Call::instantiate_with_code(_, _, code, _, salt)) => {
206 let code_hash = &T::Hashing::hash(&code);216 let code_hash = &T::Hashing::hash(&code);
207 Ok(Some((who.clone(), code_hash.clone(), salt.clone())))217 Ok(Some((who.clone(), *code_hash, salt.clone())))
208 }218 }
209 _ => Ok(None),219 _ => Ok(None),
210 }220 }
236 T::AccountId: AsRef<[u8]>,246 T::AccountId: AsRef<[u8]>,
237 {247 {
238 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {248 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {
239 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {
240 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {249 if let Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) =
250 IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call)
251 {
241 let called_contract: T::AccountId =252 let called_contract: T::AccountId =
253 }263 }
254 }264 }
255 }265 }
256 _ => {}
257 }
258 None266 None
259 }267 }
260 }268 }
modifiedpallets/inflation/src/benchmarking.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/inflation/src/lib.rsdiffbeforeafterboth
3936
40use sp_runtime::{37use sp_runtime::{
41 Perbill,38 Perbill,
42 traits::{Zero}39 traits::{Zero},
43};40};
44use sp_std::convert::TryInto;41use sp_std::convert::TryInto;
4542
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
1#[cfg(test)]1#![cfg(test)]
2mod tests {2#![allow(clippy::from_over_into)]
3 use crate as pallet_inflation;3use crate as pallet_inflation;
44
5 use frame_system;5use frame_support::{
6 use frame_support::{traits::{Currency}, parameter_types};6 traits::{Currency},
7 use frame_support::{traits::OnInitialize};7 parameter_types,
8 use sp_core::H256;8};
9 use sp_runtime::{traits::{BlakeTwo256, IdentityLookup}, testing::Header};9use frame_support::{traits::OnInitialize};
1010use sp_core::H256;
11 type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;11use sp_runtime::{
12 type Block = frame_system::mocking::MockBlock<Test>;12 traits::{BlakeTwo256, IdentityLookup},
1313 testing::Header,
14 const YEAR: u64 = 5_259_600;14};
1515
16 parameter_types! {16type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
17 pub const ExistentialDeposit: u64 = 1;17type Block = frame_system::mocking::MockBlock<Test>;
18 pub const MaxLocks: u32 = 50;18
19 }19const YEAR: u64 = 5_259_600;
20 20
21 impl pallet_balances::Config for Test {21parameter_types! {
22 type AccountStore = System;22 pub const ExistentialDeposit: u64 = 1;
23 type Balance = u64;23 pub const MaxLocks: u32 = 50;
24 type DustRemoval = ();24}
25 type Event = ();25
26 type ExistentialDeposit = ExistentialDeposit;26impl pallet_balances::Config for Test {
27 type WeightInfo = ();27 type AccountStore = System;
28 type MaxLocks = MaxLocks;28 type Balance = u64;
29 }29 type DustRemoval = ();
30 30 type Event = ();
31 frame_support::construct_runtime!(31 type ExistentialDeposit = ExistentialDeposit;
32 pub enum Test where32 type WeightInfo = ();
33 Block = Block,33 type MaxLocks = MaxLocks;
34 NodeBlock = Block,34}
35 UncheckedExtrinsic = UncheckedExtrinsic,35
36 {36frame_support::construct_runtime!(
37 Balances: pallet_balances::{Pallet, Call, Storage},37 pub enum Test where
38 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},38 Block = Block,
39 Inflation: pallet_inflation::{Pallet, Call, Storage},39 NodeBlock = Block,
40 }40 UncheckedExtrinsic = UncheckedExtrinsic,
41 );41 {
4242 Balances: pallet_balances::{Pallet, Call, Storage},
43 parameter_types! {43 System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
44 pub const BlockHashCount: u64 = 250;44 Inflation: pallet_inflation::{Pallet, Call, Storage},
45 pub BlockWeights: frame_system::limits::BlockWeights =45 }
46 frame_system::limits::BlockWeights::simple_max(1024);46);
47 pub const SS58Prefix: u8 = 42;47
48 }48parameter_types! {
4949 pub const BlockHashCount: u64 = 250;
50 impl frame_system::Config for Test {50 pub BlockWeights: frame_system::limits::BlockWeights =
51 type BaseCallFilter = ();51 frame_system::limits::BlockWeights::simple_max(1024);
52 type BlockWeights = ();52 pub const SS58Prefix: u8 = 42;
53 type BlockLength = ();53}
54 type DbWeight = ();54
55 type Origin = Origin;55impl frame_system::Config for Test {
56 type Call = Call;56 type BaseCallFilter = ();
57 type Index = u64;57 type BlockWeights = ();
58 type BlockNumber = u64;58 type BlockLength = ();
59 type Hash = H256;59 type DbWeight = ();
60 type Hashing = BlakeTwo256;60 type Origin = Origin;
61 type AccountId = u64;61 type Call = Call;
62 type Lookup = IdentityLookup<Self::AccountId>;62 type Index = u64;
63 type Header = Header;63 type BlockNumber = u64;
64 type Event = ();64 type Hash = H256;
65 type BlockHashCount = BlockHashCount;65 type Hashing = BlakeTwo256;
66 type Version = ();66 type AccountId = u64;
67 type PalletInfo = PalletInfo;67 type Lookup = IdentityLookup<Self::AccountId>;
68 type AccountData = pallet_balances::AccountData<u64>;68 type Header = Header;
69 type OnNewAccount = ();69 type Event = ();
70 type OnKilledAccount = ();70 type BlockHashCount = BlockHashCount;
71 type SystemWeightInfo = ();71 type Version = ();
72 type SS58Prefix = SS58Prefix;72 type PalletInfo = PalletInfo;
73 type OnSetCode = ();73 type AccountData = pallet_balances::AccountData<u64>;
74 }74 type OnNewAccount = ();
7575 type OnKilledAccount = ();
76 parameter_types! {76 type SystemWeightInfo = ();
77 pub TreasuryAccountId: u64 = 1234;77 type SS58Prefix = SS58Prefix;
78 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied78 type OnSetCode = ();
79 }79}
80 80
81 impl pallet_inflation::Config for Test {81parameter_types! {
82 type Currency = Balances;82 pub TreasuryAccountId: u64 = 1234;
83 type TreasuryAccountId = TreasuryAccountId;83 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied
84 type InflationBlockInterval = InflationBlockInterval;84}
85 }85
8686impl pallet_inflation::Config for Test {
87 // Build genesis storage according to the mock runtime.87 type Currency = Balances;
88 pub fn new_test_ext() -> sp_io::TestExternalities {88 type TreasuryAccountId = TreasuryAccountId;
89 frame_system::GenesisConfig::default().build_storage::<Test>().unwrap().into()89 type InflationBlockInterval = InflationBlockInterval;
90 }90}
91
92// Build genesis storage according to the mock runtime.
93pub fn new_test_ext() -> sp_io::TestExternalities {
94 frame_system::GenesisConfig::default()
95 .build_storage::<Test>()
96 .unwrap()
97 .into()
98}
99
100#[test]
101fn inflation_works() {
102 new_test_ext().execute_with(|| {
103 // Total issuance = 1_000_000_000
104 let initial_issuance: u64 = 1_000_000_000;
105 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
106 assert_eq!(Balances::free_balance(1234), initial_issuance);
107
108 // BlockInflation should be set after 1st block and
109 // first inflation deposit should be equal to BlockInflation
110 Inflation::on_initialize(1);
111 assert!(Inflation::block_inflation() > 0);
112 assert_eq!(
113 Balances::free_balance(1234) - initial_issuance,
114 Inflation::block_inflation()
115 );
116 });
117}
118
119#[test]
120fn inflation_second_deposit() {
121 new_test_ext().execute_with(|| {
122 // Total issuance = 1_000_000_000
123 let initial_issuance: u64 = 1_000_000_000;
124 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
125 assert_eq!(Balances::free_balance(1234), initial_issuance);
126 Inflation::on_initialize(1);
127
128 // Next inflation deposit happens when block is multiple of InflationBlockInterval
129 let mut block: u32 = 2;
130 let balance_before: u64 = Balances::free_balance(1234);
131 while block % InflationBlockInterval::get() != 0 {
132 Inflation::on_initialize(block as u64);
133 block += 1;
134 }
135 let balance_just_before: u64 = Balances::free_balance(1234);
136 assert_eq!(balance_before, balance_just_before);
137
138 // The block with inflation
139 Inflation::on_initialize(block as u64);
140 let balance_after: u64 = Balances::free_balance(1234);
141 assert_eq!(
142 balance_after - balance_just_before,
143 Inflation::block_inflation()
144 );
145 });
146}
147
148#[test]
149fn inflation_in_1_year() {
150 new_test_ext().execute_with(|| {
151 // Total issuance = 1_000_000_000
152 let initial_issuance: u64 = 1_000_000_000;
153 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
154 assert_eq!(Balances::free_balance(1234), initial_issuance);
155 Inflation::on_initialize(1);
156 let block_inflation_year_0 = Inflation::block_inflation();
157
158 Inflation::on_initialize(YEAR);
159 let block_inflation_year_1 = Inflation::block_inflation();
160
161 // Assert that year 1 inflation is less than year 0
162 assert!(block_inflation_year_0 > block_inflation_year_1);
163 });
164}
165
166#[test]
167fn inflation_in_1_to_9_years() {
168 new_test_ext().execute_with(|| {
169 // Total issuance = 1_000_000_000
170 let initial_issuance: u64 = 1_000_000_000;
171 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
172 assert_eq!(Balances::free_balance(1234), initial_issuance);
173 Inflation::on_initialize(1);
174
175 for year in 1..=9 {
176 let block_inflation_year_before = Inflation::block_inflation();
177 Inflation::on_initialize(YEAR * year);
178 let block_inflation_year_after = Inflation::block_inflation();
179
180 // Assert that next year inflation is less than previous year inflation
181 assert!(block_inflation_year_before > block_inflation_year_after);
182 }
183 });
184}
185
186#[test]
187fn inflation_after_year_10_is_flat() {
188 new_test_ext().execute_with(|| {
189 // Total issuance = 1_000_000_000
190 let initial_issuance: u64 = 1_000_000_000;
191 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
192 assert_eq!(Balances::free_balance(1234), initial_issuance);
193 Inflation::on_initialize(YEAR * 9);
194
195 for year in 10..=20 {
196 let block_inflation_year_before = Inflation::block_inflation();
197 Inflation::on_initialize(YEAR * year);
198 let block_inflation_year_after = Inflation::block_inflation();
199
200 // Assert that next year inflation is equal to previous year inflation
201 assert_eq!(block_inflation_year_before, block_inflation_year_after);
202 }
203 });
204}
91205
92 #[test]206#[test]
93 fn inflation_works() {207fn inflation_rate_by_year() {
94 new_test_ext().execute_with(|| {
95 // Total issuance = 1_000_000_000
96 let initial_issuance: u64 = 1_000_000_000;
97 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
98 assert_eq!(Balances::free_balance(1234), initial_issuance);
99
100 // BlockInflation should be set after 1st block and
101 // first inflation deposit should be equal to BlockInflation
102 Inflation::on_initialize(1);
103 assert!(Inflation::block_inflation() > 0);
104 assert_eq!(Balances::free_balance(1234) - initial_issuance, Inflation::block_inflation());
105 });
106 }
107
108 #[test]
109 fn inflation_second_deposit() {
110 new_test_ext().execute_with(|| {
111 // Total issuance = 1_000_000_000
112 let initial_issuance: u64 = 1_000_000_000;
113 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
114 assert_eq!(Balances::free_balance(1234), initial_issuance);
115 Inflation::on_initialize(1);
116
117 // Next inflation deposit happens when block is multiple of InflationBlockInterval
118 let mut block: u32 = 2;
119 let balance_before: u64 = Balances::free_balance(1234);
120 while block % InflationBlockInterval::get() != 0 {
121 Inflation::on_initialize(block as u64);
122 block += 1;
123 }
124 let balance_just_before: u64 = Balances::free_balance(1234);
125 assert_eq!(balance_before, balance_just_before);
126
127 // The block with inflation
128 Inflation::on_initialize(block as u64);
129 let balance_after: u64 = Balances::free_balance(1234);
130 assert_eq!(balance_after - balance_just_before, Inflation::block_inflation());
131 });
132 }
133
134 #[test]
135 fn inflation_in_1_year() {
136 new_test_ext().execute_with(|| {
137 // Total issuance = 1_000_000_000
138 let initial_issuance: u64 = 1_000_000_000;
139 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
140 assert_eq!(Balances::free_balance(1234), initial_issuance);
141 Inflation::on_initialize(1);
142 let block_inflation_year_0 = Inflation::block_inflation();
143
144 Inflation::on_initialize(YEAR);
145 let block_inflation_year_1 = Inflation::block_inflation();
146
147 // Assert that year 1 inflation is less than year 0
148 assert!(block_inflation_year_0 > block_inflation_year_1);
149 });
150 }
151
152 #[test]
153 fn inflation_in_1_to_9_years() {
154 new_test_ext().execute_with(|| {
155 // Total issuance = 1_000_000_000
156 let initial_issuance: u64 = 1_000_000_000;
157 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
158 assert_eq!(Balances::free_balance(1234), initial_issuance);
159 Inflation::on_initialize(1);
160
161 for year in 1..=9 {
162 let block_inflation_year_before = Inflation::block_inflation();
163 Inflation::on_initialize(YEAR * year);
164 let block_inflation_year_after = Inflation::block_inflation();
165
166 // Assert that next year inflation is less than previous year inflation
167 assert!(block_inflation_year_before > block_inflation_year_after);
168 }
169
170 });
171 }
172
173 #[test]
174 fn inflation_after_year_10_is_flat() {
175 new_test_ext().execute_with(|| {
176 // Total issuance = 1_000_000_000
177 let initial_issuance: u64 = 1_000_000_000;
178 let _ = <Balances as Currency<_>>::deposit_creating(&1234, initial_issuance);
179 assert_eq!(Balances::free_balance(1234), initial_issuance);
180 Inflation::on_initialize(YEAR * 9);
181
182 for year in 10..=20 {
183 let block_inflation_year_before = Inflation::block_inflation();
184 Inflation::on_initialize(YEAR * year);
185 let block_inflation_year_after = Inflation::block_inflation();
186
187 // Assert that next year inflation is equal to previous year inflation
188 assert_eq!(block_inflation_year_before, block_inflation_year_after);
189 }
190 });
191 }
192
193 #[test]
194 fn inflation_rate_by_year() {
195 new_test_ext().execute_with(|| {208 new_test_ext().execute_with(|| {
196 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;209 let payouts: u64 = YEAR / InflationBlockInterval::get() as u64;
197210
198 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included), 211 // Inflation starts at 10% and does down by 2/3% every year until year 9 (included),
199 // then it is flat.212 // then it is flat.
200 let payout_by_year: [u64; 11] = [213 let payout_by_year: [u64; 11] = [1000, 933, 867, 800, 733, 667, 600, 533, 467, 400, 400];
201 1000,
239 }240 }
240 });241 });
241 }242}
242}
243243
modifiedpallets/nft-charge-transaction/src/lib.rsdiffbeforeafterboth
11#[cfg(feature = "std")]11#[cfg(feature = "std")]
12pub use serde::*;12pub use serde::*;
13
14#[cfg(feature = "runtime-benchmarks")]
15mod benchmarking;
1613
17use codec::{Decode, Encode};14use codec::{Decode, Encode};
18use frame_support::traits::Get;15use frame_support::traits::Get;
19use frame_support::{16use frame_support::{
20 decl_module, decl_storage,17 decl_module, decl_storage,
21 weights::{18 weights::{DispatchInfo, PostDispatchInfo, DispatchClass},
22 DispatchInfo, PostDispatchInfo, DispatchClass
23 }
24};19};
29 transaction_validity::{ 25 transaction_validity::{
30 TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,26 TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,
31 },27 },
32 FixedPointOperand, DispatchResult28 FixedPointOperand, DispatchResult,
33};29};
34use pallet_transaction_payment::OnChargeTransaction;30use pallet_transaction_payment::OnChargeTransaction;
35use sp_std::prelude::*;31use sp_std::prelude::*;
102 .saturated_into::<TransactionPriority>()95 .saturated_into::<TransactionPriority>()
103 }96 }
10497
98 #[allow(clippy::type_complexity)]
105 fn withdraw_fee(99 fn withdraw_fee(
106 &self,100 &self,
107 who: &T::AccountId,101 who: &T::AccountId,
126 }120 }
127121
128 // Determine who is paying transaction fee based on ecnomic model122 // Determine who is paying transaction fee based on ecnomic model
129 // Parse call to extract collection ID and access collection sponsor 123 // Parse call to extract collection ID and access collection sponsor
130 let sponsor = <pallet_nft_transaction_payment::Module<T>>::withdraw_type(who, call);124 let sponsor = <pallet_nft_transaction_payment::Module<T>>::withdraw_type(who, call);
131125
132 let who_pays_fee = sponsor.unwrap_or_else(|| who.clone());126 let who_pays_fee = sponsor.unwrap_or_else(|| who.clone());
modifiedpallets/nft-transaction-payment/src/benchmarking.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/nft-transaction-payment/src/lib.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/nft/src/benchmarking.rsdiffbeforeafterboth
55
6use sp_std::prelude::*;6use sp_std::prelude::*;
7use frame_system::RawOrigin;7use frame_system::RawOrigin;
8use frame_benchmarking::{benchmarks, account, whitelisted_caller}; // , TrackedStorageKey, 8use frame_benchmarking::{benchmarks, account, whitelisted_caller}; // , TrackedStorageKey,
99
10const SEED: u32 = 1;10const SEED: u32 = 1;
11/*11/*
31 let mode: CollectionMode = CollectionMode::NFT;31 let mode: CollectionMode = CollectionMode::NFT;
32 let caller: T::AccountId = account("caller", 0, SEED);32 let caller: T::AccountId = account("caller", 0, SEED);
33 }: _(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)33 }: _(RawOrigin::Signed(caller.clone()), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode)
34/*34/*
35 verify {35 verify {
36 assert_eq!(Nft::<T>::collection_id(2).owner, caller);36 assert_eq!(Nft::<T>::collection_id(2).owner, caller);
37 }37 }
38 destroy_collection {38 destroy_collection {
39 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();39 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
40 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();40 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
41 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();41 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
42 let mode: CollectionMode = CollectionMode::NFT;42 let mode: CollectionMode = CollectionMode::NFT;
43 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());43 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
44 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;44 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
45 }: _(RawOrigin::Signed(caller.clone()), 2)45 }: _(RawOrigin::Signed(caller.clone()), 2)
4646
47 add_to_white_list {47 add_to_white_list {
48 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();48 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
49 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();49 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
50 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();50 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
51 let mode: CollectionMode = CollectionMode::NFT;51 let mode: CollectionMode = CollectionMode::NFT;
52 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());52 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
53 let whitelist_account: T::AccountId = account("admin", 0, SEED);53 let whitelist_account: T::AccountId = account("admin", 0, SEED);
54 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;54 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
55 }: add_to_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)55 }: add_to_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)
5656
57 remove_from_white_list {57 remove_from_white_list {
58 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();58 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
59 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();59 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
60 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();60 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
61 let mode: CollectionMode = CollectionMode::NFT;61 let mode: CollectionMode = CollectionMode::NFT;
62 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());62 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
63 let whitelist_account: T::AccountId = account("admin", 0, SEED);63 let whitelist_account: T::AccountId = account("admin", 0, SEED);
64 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;64 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
65 Nft::<T>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), 2, whitelist_account.clone())?;65 Nft::<T>::add_to_white_list(RawOrigin::Signed(caller.clone()).into(), 2, whitelist_account.clone())?;
66 }: remove_from_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)66 }: remove_from_white_list(RawOrigin::Signed(caller.clone()), 2, whitelist_account)
6767
68 set_public_access_mode {68 set_public_access_mode {
69 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();69 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
70 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();70 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
71 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();71 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
72 let mode: CollectionMode = CollectionMode::NFT;72 let mode: CollectionMode = CollectionMode::NFT;
73 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());73 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
74 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;74 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
75 }: set_public_access_mode(RawOrigin::Signed(caller.clone()), 2, AccessMode::WhiteList)75 }: set_public_access_mode(RawOrigin::Signed(caller.clone()), 2, AccessMode::WhiteList)
7676
77 set_mint_permission {77 set_mint_permission {
78 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();78 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
79 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();79 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
80 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();80 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
81 let mode: CollectionMode = CollectionMode::NFT;81 let mode: CollectionMode = CollectionMode::NFT;
82 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());82 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
83 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;83 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
84 }: set_mint_permission(RawOrigin::Signed(caller.clone()), 2, true)84 }: set_mint_permission(RawOrigin::Signed(caller.clone()), 2, true)
8585
86 change_collection_owner {86 change_collection_owner {
87 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();87 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
88 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();88 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
89 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();89 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
90 let mode: CollectionMode = CollectionMode::NFT;90 let mode: CollectionMode = CollectionMode::NFT;
91 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());91 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
92 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;92 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
93 let new_owner: T::AccountId = account("admin", 0, SEED);93 let new_owner: T::AccountId = account("admin", 0, SEED);
94 }: change_collection_owner(RawOrigin::Signed(caller.clone()), 2, new_owner)94 }: change_collection_owner(RawOrigin::Signed(caller.clone()), 2, new_owner)
9595
96 add_collection_admin {96 add_collection_admin {
97 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();97 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
98 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();98 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
99 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();99 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
100 let mode: CollectionMode = CollectionMode::NFT;100 let mode: CollectionMode = CollectionMode::NFT;
101 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());101 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
102 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;102 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
103 let new_admin: T::AccountId = account("admin", 0, SEED);103 let new_admin: T::AccountId = account("admin", 0, SEED);
104 }: add_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)104 }: add_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)
105105
106 remove_collection_admin {106 remove_collection_admin {
107 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();107 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
108 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();108 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
109 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();109 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
110 let mode: CollectionMode = CollectionMode::NFT;110 let mode: CollectionMode = CollectionMode::NFT;
111 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());111 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
112 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;112 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
113 let new_admin: T::AccountId = account("admin", 0, SEED);113 let new_admin: T::AccountId = account("admin", 0, SEED);
114 Nft::<T>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, new_admin.clone())?;114 Nft::<T>::add_collection_admin(RawOrigin::Signed(caller.clone()).into(), 2, new_admin.clone())?;
115 }: remove_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)115 }: remove_collection_admin(RawOrigin::Signed(caller.clone()), 2, new_admin)
116116
117 set_collection_sponsor {117 set_collection_sponsor {
118 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();118 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
119 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();119 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
120 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();120 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
121 let mode: CollectionMode = CollectionMode::NFT;121 let mode: CollectionMode = CollectionMode::NFT;
122 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());122 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
123 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;123 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
124 }: set_collection_sponsor(RawOrigin::Signed(caller.clone()), 2, caller.clone())124 }: set_collection_sponsor(RawOrigin::Signed(caller.clone()), 2, caller.clone())
125125
126 confirm_sponsorship {126 confirm_sponsorship {
127 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();127 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
128 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();128 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
129 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();129 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
130 let mode: CollectionMode = CollectionMode::NFT;130 let mode: CollectionMode = CollectionMode::NFT;
131 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());131 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
132 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;132 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
133 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;133 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;
134 }: confirm_sponsorship(RawOrigin::Signed(caller.clone()), 2)134 }: confirm_sponsorship(RawOrigin::Signed(caller.clone()), 2)
135135
136 remove_collection_sponsor {136 remove_collection_sponsor {
137 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();137 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
138 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();138 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
139 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();139 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
140 let mode: CollectionMode = CollectionMode::NFT;140 let mode: CollectionMode = CollectionMode::NFT;
141 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());141 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
142 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;142 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
143 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;143 Nft::<T>::set_collection_sponsor(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone())?;
144 Nft::<T>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;144 Nft::<T>::confirm_sponsorship(RawOrigin::Signed(caller.clone()).into(), 2)?;
145 }: remove_collection_sponsor(RawOrigin::Signed(caller.clone()), 2)145 }: remove_collection_sponsor(RawOrigin::Signed(caller.clone()), 2)
146146
147 // nft item147 // nft item
148 create_item_nft {148 create_item_nft {
149 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();149 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
150 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();150 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
151 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();151 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
152 let mode: CollectionMode = CollectionMode::NFT;152 let mode: CollectionMode = CollectionMode::NFT;
153 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());153 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
154 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;154 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
155 let data = default_nft_data();155 let data = default_nft_data();
156 156
157 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)157 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)
158158
159 #[extra]159 #[extra]
160 create_item_nft_large {160 create_item_nft_large {
161 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();161 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
162 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();162 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
163 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();163 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
164 let mode: CollectionMode = CollectionMode::NFT;164 let mode: CollectionMode = CollectionMode::NFT;
165 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());165 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
166 let mut nft_data = CreateNftData {166 let mut nft_data = CreateNftData {
167 const_data: vec![],167 const_data: vec![],
168 variable_data: vec![]168 variable_data: vec![]
169 };169 };
170 for i in 0..1998 {170 for i in 0..1998 {
171 nft_data.const_data.push(10);171 nft_data.const_data.push(10);
172 nft_data.variable_data.push(10);172 nft_data.variable_data.push(10);
173 }173 }
174 let data = CreateItemData::NFT(nft_data);174 let data = CreateItemData::NFT(nft_data);
175 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;175 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
176176
177 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)177 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)
178178
179 // fungible item179 // fungible item
180 create_item_fungible {180 create_item_fungible {
181 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();181 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
182 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();182 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
183 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();183 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
184 let mode: CollectionMode = CollectionMode::Fungible(3);184 let mode: CollectionMode = CollectionMode::Fungible(3);
185 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());185 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
186 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;186 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
187 let data = default_fungible_data();187 let data = default_fungible_data();
188188
189 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)189 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)
190190
191 // refungible item191 // refungible item
192 create_item_refungible {192 create_item_refungible {
193 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();193 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
194 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();194 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
195 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();195 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
196 let mode: CollectionMode = CollectionMode::ReFungible(3);196 let mode: CollectionMode = CollectionMode::ReFungible(3);
197 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());197 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
198 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;198 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
199 let data = default_re_fungible_data();199 let data = default_re_fungible_data();
200200
201 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)201 }: create_item(RawOrigin::Signed(caller.clone()), 2, caller.clone(), data)
202202
203 burn_item {203 burn_item {
204 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();204 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
205 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();205 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
206 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();206 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
207 let mode: CollectionMode = CollectionMode::NFT;207 let mode: CollectionMode = CollectionMode::NFT;
208 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());208 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
209 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;209 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
210 let data = default_nft_data();210 let data = default_nft_data();
211 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;211 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
212212
213 }: burn_item(RawOrigin::Signed(caller.clone()), 2, 1)213 }: burn_item(RawOrigin::Signed(caller.clone()), 2, 1)
214214
215 transfer_nft {215 transfer_nft {
216 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();216 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
217 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();217 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
218 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();218 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
219 let mode: CollectionMode = CollectionMode::NFT;219 let mode: CollectionMode = CollectionMode::NFT;
220 let recipient: T::AccountId = account("recipient", 0, SEED);220 let recipient: T::AccountId = account("recipient", 0, SEED);
221 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());221 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
222 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;222 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
223 let data = default_nft_data();223 let data = default_nft_data();
224 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;224 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
225225
226 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)226 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)
227 227
228 transfer_fungible {228 transfer_fungible {
229 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();229 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
230 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();230 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
231 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();231 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
232 let mode: CollectionMode = CollectionMode::Fungible(3);232 let mode: CollectionMode = CollectionMode::Fungible(3);
233 let recipient: T::AccountId = account("recipient", 0, SEED);233 let recipient: T::AccountId = account("recipient", 0, SEED);
234 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());234 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
235 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;235 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
236 let data = default_fungible_data();236 let data = default_fungible_data();
237 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;237 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
238238
239 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)239 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)
240240
241 transfer_refungible {241 transfer_refungible {
242 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();242 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
243 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();243 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
244 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();244 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
245 let mode: CollectionMode = CollectionMode::ReFungible(3);245 let mode: CollectionMode = CollectionMode::ReFungible(3);
246 let recipient: T::AccountId = account("recipient", 0, SEED);246 let recipient: T::AccountId = account("recipient", 0, SEED);
247 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());247 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
248 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;248 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
249 let data = default_re_fungible_data();249 let data = default_re_fungible_data();
250 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;250 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
251251
252 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)252 }: transfer(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1, 1)
253253
254 approve {254 approve {
255 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();255 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
256 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();256 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
257 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();257 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
258 let mode: CollectionMode = CollectionMode::ReFungible(3);258 let mode: CollectionMode = CollectionMode::ReFungible(3);
259 let recipient: T::AccountId = account("recipient", 0, SEED);259 let recipient: T::AccountId = account("recipient", 0, SEED);
260 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());260 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
261 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;261 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
262 let data = default_re_fungible_data();262 let data = default_re_fungible_data();
263 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;263 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
264264
265 }: approve(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1)265 }: approve(RawOrigin::Signed(caller.clone()), recipient.clone(), 2, 1)
266266
267 // Nft267 // Nft
268 transfer_from_nft {268 transfer_from_nft {
269 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();269 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
270 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();270 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
271 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();271 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
272 let mode: CollectionMode = CollectionMode::NFT;272 let mode: CollectionMode = CollectionMode::NFT;
273 let recipient: T::AccountId = account("recipient", 0, SEED);273 let recipient: T::AccountId = account("recipient", 0, SEED);
274 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());274 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
275 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;275 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
276 let data = default_nft_data();276 let data = default_nft_data();
277 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;277 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
278 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;278 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;
279279
280 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)280 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)
281281
282 // Fungible282 // Fungible
283 transfer_from_fungible {283 transfer_from_fungible {
284 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();284 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
285 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();285 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
286 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();286 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
287 let mode: CollectionMode = CollectionMode::Fungible(3);287 let mode: CollectionMode = CollectionMode::Fungible(3);
288 let recipient: T::AccountId = account("recipient", 0, SEED);288 let recipient: T::AccountId = account("recipient", 0, SEED);
289 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());289 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
290 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;290 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
291 let data = default_fungible_data();291 let data = default_fungible_data();
292 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;292 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
293 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;293 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;
294294
295 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)295 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)
296296
297 // ReFungible297 // ReFungible
298 transfer_from_refungible {298 transfer_from_refungible {
299 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();299 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
300 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();300 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
301 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();301 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
302 let mode: CollectionMode = CollectionMode::ReFungible(3);302 let mode: CollectionMode = CollectionMode::ReFungible(3);
303 let recipient: T::AccountId = account("recipient", 0, SEED);303 let recipient: T::AccountId = account("recipient", 0, SEED);
304 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());304 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
305 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;305 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
306 let data = default_re_fungible_data();306 let data = default_re_fungible_data();
307 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;307 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
308 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;308 Nft::<T>::approve(RawOrigin::Signed(caller.clone()).into(), recipient.clone(), 2, 1)?;
309309
310 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)310 }: transfer_from(RawOrigin::Signed(caller.clone()), caller.clone(), recipient.clone(), 2, 1, 1)
311311
312 enable_contract_sponsoring {312 enable_contract_sponsoring {
313 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());313 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
314314
315 }: enable_contract_sponsoring(RawOrigin::Signed(caller.clone()), caller.clone(), true)315 }: enable_contract_sponsoring(RawOrigin::Signed(caller.clone()), caller.clone(), true)
316316
317 set_offchain_schema {317 set_offchain_schema {
318 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();318 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
319 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();319 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
320 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();320 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
321 let mode: CollectionMode = CollectionMode::ReFungible(3);321 let mode: CollectionMode = CollectionMode::ReFungible(3);
322 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());322 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
323 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;323 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
324324
325 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())325 }: set_offchain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())
326326
327 set_const_on_chain_schema {327 set_const_on_chain_schema {
328 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();328 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
329 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();329 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
330 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();330 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
331 let mode: CollectionMode = CollectionMode::ReFungible(3);331 let mode: CollectionMode = CollectionMode::ReFungible(3);
332 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());332 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
333 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;333 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
334 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())334 }: set_const_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())
335 335
336 set_variable_on_chain_schema {336 set_variable_on_chain_schema {
337 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();337 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
338 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();338 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
339 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();339 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
340 let mode: CollectionMode = CollectionMode::ReFungible(3);340 let mode: CollectionMode = CollectionMode::ReFungible(3);
341 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());341 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
342 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;342 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
343 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())343 }: set_variable_on_chain_schema(RawOrigin::Signed(caller.clone()), 2, [1,2,3].to_vec())
344344
345 set_variable_meta_data {345 set_variable_meta_data {
346 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();346 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
347 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();347 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
348 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();348 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
349 let mode: CollectionMode = CollectionMode::NFT;349 let mode: CollectionMode = CollectionMode::NFT;
350 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());350 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
351 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;351 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
352 let data = default_nft_data();352 let data = default_nft_data();
353 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;353 Nft::<T>::create_item(RawOrigin::Signed(caller.clone()).into(), 2, caller.clone(), data)?;
354354
355 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())355 }: set_variable_meta_data(RawOrigin::Signed(caller.clone()), 2, 1, [1, 2, 3].to_vec())
356356
357 set_schema_version {357 set_schema_version {
358 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();358 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
359 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();359 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
360 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();360 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
361 let mode: CollectionMode = CollectionMode::NFT;361 let mode: CollectionMode = CollectionMode::NFT;
362 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());362 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
363 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;363 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
364 }: set_schema_version(RawOrigin::Signed(caller.clone()), 2, SchemaVersion::Unique)364 }: set_schema_version(RawOrigin::Signed(caller.clone()), 2, SchemaVersion::Unique)
365365
366 set_chain_limits {366 set_chain_limits {
367 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());367 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
368 let limits = ChainLimits { 368 let limits = ChainLimits {
369 collection_numbers_limit: 0,369 collection_numbers_limit: 0,
370 account_token_ownership_limit: 0,370 account_token_ownership_limit: 0,
371 collections_admins_limit: 0,371 collections_admins_limit: 0,
372 custom_data_limit: 0,372 custom_data_limit: 0,
373 nft_sponsor_transfer_timeout: 0,373 nft_sponsor_transfer_timeout: 0,
374 fungible_sponsor_transfer_timeout: 0,374 fungible_sponsor_transfer_timeout: 0,
375 refungible_sponsor_transfer_timeout: 0375 refungible_sponsor_transfer_timeout: 0
376 };376 };
377 }: set_chain_limits(RawOrigin::Signed(caller.clone()), limits)377 }: set_chain_limits(RawOrigin::Signed(caller.clone()), limits)
378378
379 set_contract_sponsoring_rate_limit {379 set_contract_sponsoring_rate_limit {
380 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();380 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
381 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();381 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
382 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();382 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
383 let mode: CollectionMode = CollectionMode::NFT;383 let mode: CollectionMode = CollectionMode::NFT;
384 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());384 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
385 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;385 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
386 let block_number: T::BlockNumber = 0.into(); 386 let block_number: T::BlockNumber = 0.into();
387 }: set_contract_sponsoring_rate_limit(RawOrigin::Signed(caller.clone()), caller.clone(), block_number)387 }: set_contract_sponsoring_rate_limit(RawOrigin::Signed(caller.clone()), caller.clone(), block_number)
388388
389 set_collection_limits{389 set_collection_limits{
390 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();390 let col_name1: Vec<u16> = "Test1".encode_utf16().collect::<Vec<u16>>();
391 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();391 let col_desc1: Vec<u16> = "TestDescription1".encode_utf16().collect::<Vec<u16>>();
392 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();392 let token_prefix1: Vec<u8> = b"token_prefix1".to_vec();
393 let mode: CollectionMode = CollectionMode::NFT;393 let mode: CollectionMode = CollectionMode::NFT;
394 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());394 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
395 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;395 Nft::<T>::create_collection(RawOrigin::Signed(caller.clone()).into(), col_name1.clone(), col_desc1.clone(), token_prefix1.clone(), mode.clone())?;
396 396
397 let cl = CollectionLimits {397 let cl = CollectionLimits {
398 account_token_ownership_limit: 0,398 account_token_ownership_limit: 0,
399 sponsored_data_size: 0,399 sponsored_data_size: 0,
400 token_limit: 0,400 token_limit: 0,
401 sponsor_transfer_timeout: 0401 sponsor_transfer_timeout: 0
402 };402 };
403403
404 }: set_collection_limits(RawOrigin::Signed(caller.clone()), 2, cl)404 }: set_collection_limits(RawOrigin::Signed(caller.clone()), 2, cl)
405405
406 add_to_contract_white_list{406 add_to_contract_white_list{
407 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());407 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
408 }: add_to_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())408 }: add_to_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())
409409
410 remove_from_contract_white_list{410 remove_from_contract_white_list{
411 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());411 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
412 Nft::<T>::add_to_contract_white_list(RawOrigin::Signed(caller.clone()).into(), caller.clone(), caller.clone())?;412 Nft::<T>::add_to_contract_white_list(RawOrigin::Signed(caller.clone()).into(), caller.clone(), caller.clone())?;
413 }: remove_from_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())413 }: remove_from_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), caller.clone())
414414
415 toggle_contract_white_list{415 toggle_contract_white_list{
416 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());416 let caller: T::AccountId = T::AccountId::from(whitelisted_caller());
417 }: toggle_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), true)417 }: toggle_contract_white_list(RawOrigin::Signed(caller.clone()), caller.clone(), true)
418*/418*/
419}419}
420420
modifiedpallets/nft/src/default_weights.rsdiffbeforeafterboth
22
3impl crate::WeightInfo for () {3impl crate::WeightInfo for () {
4 fn create_collection() -> Weight {4 fn create_collection() -> Weight {
5 (70_000_000 as Weight)5 70_000_000_u64
6 .saturating_add(DbWeight::get().reads(7 as Weight))6 .saturating_add(DbWeight::get().reads(7_u64))
7 .saturating_add(DbWeight::get().writes(5 as Weight))7 .saturating_add(DbWeight::get().writes(5_u64))
8 }8 }
9 fn destroy_collection() -> Weight {9 fn destroy_collection() -> Weight {
10 (90_000_000 as Weight)10 90_000_000_u64
11 .saturating_add(DbWeight::get().reads(2 as Weight))11 .saturating_add(DbWeight::get().reads(2_u64))
12 .saturating_add(DbWeight::get().writes(5 as Weight))12 .saturating_add(DbWeight::get().writes(5_u64))
13 }13 }
14 fn add_to_white_list() -> Weight {14 fn add_to_white_list() -> Weight {
15 (30_000_000 as Weight)15 30_000_000_u64
16 .saturating_add(DbWeight::get().reads(3 as Weight))16 .saturating_add(DbWeight::get().reads(3_u64))
17 .saturating_add(DbWeight::get().writes(1 as Weight))17 .saturating_add(DbWeight::get().writes(1_u64))
18 }18 }
19 fn remove_from_white_list() -> Weight {19 fn remove_from_white_list() -> Weight {
20 (35_000_000 as Weight)20 35_000_000_u64
21 .saturating_add(DbWeight::get().reads(3 as Weight))21 .saturating_add(DbWeight::get().reads(3_u64))
22 .saturating_add(DbWeight::get().writes(1 as Weight))22 .saturating_add(DbWeight::get().writes(1_u64))
23 }23 }
24 fn set_public_access_mode() -> Weight {24 fn set_public_access_mode() -> Weight {
25 (27_000_000 as Weight)25 27_000_000_u64
26 .saturating_add(DbWeight::get().reads(1 as Weight))26 .saturating_add(DbWeight::get().reads(1_u64))
27 .saturating_add(DbWeight::get().writes(1 as Weight))27 .saturating_add(DbWeight::get().writes(1_u64))
28 }28 }
29 fn set_mint_permission() -> Weight {29 fn set_mint_permission() -> Weight {
30 (27_000_000 as Weight)30 27_000_000_u64
31 .saturating_add(DbWeight::get().reads(1 as Weight))31 .saturating_add(DbWeight::get().reads(1_u64))
32 .saturating_add(DbWeight::get().writes(1 as Weight))32 .saturating_add(DbWeight::get().writes(1_u64))
33 }33 }
34 fn change_collection_owner() -> Weight {34 fn change_collection_owner() -> Weight {
35 (27_000_000 as Weight)35 27_000_000_u64
36 .saturating_add(DbWeight::get().reads(1 as Weight))36 .saturating_add(DbWeight::get().reads(1_u64))
37 .saturating_add(DbWeight::get().writes(1 as Weight))37 .saturating_add(DbWeight::get().writes(1_u64))
38 }38 }
39 fn add_collection_admin() -> Weight {39 fn add_collection_admin() -> Weight {
40 (32_000_000 as Weight)40 32_000_000_u64
41 .saturating_add(DbWeight::get().reads(3 as Weight))41 .saturating_add(DbWeight::get().reads(3_u64))
42 .saturating_add(DbWeight::get().writes(1 as Weight))42 .saturating_add(DbWeight::get().writes(1_u64))
43 }43 }
44 fn remove_collection_admin() -> Weight {44 fn remove_collection_admin() -> Weight {
45 (50_000_000 as Weight)45 50_000_000_u64
46 .saturating_add(DbWeight::get().reads(2 as Weight))46 .saturating_add(DbWeight::get().reads(2_u64))
47 .saturating_add(DbWeight::get().writes(1 as Weight))47 .saturating_add(DbWeight::get().writes(1_u64))
48 }48 }
49 fn set_collection_sponsor() -> Weight {49 fn set_collection_sponsor() -> Weight {
50 (32_000_000 as Weight)50 32_000_000_u64
51 .saturating_add(DbWeight::get().reads(2 as Weight))51 .saturating_add(DbWeight::get().reads(2_u64))
52 .saturating_add(DbWeight::get().writes(1 as Weight))52 .saturating_add(DbWeight::get().writes(1_u64))
53 } 53 }
54 fn confirm_sponsorship() -> Weight {54 fn confirm_sponsorship() -> Weight {
55 (22_000_000 as Weight)55 22_000_000_u64
56 .saturating_add(DbWeight::get().reads(1 as Weight))56 .saturating_add(DbWeight::get().reads(1_u64))
57 .saturating_add(DbWeight::get().writes(1 as Weight))57 .saturating_add(DbWeight::get().writes(1_u64))
58 } 58 }
59 fn remove_collection_sponsor() -> Weight {59 fn remove_collection_sponsor() -> Weight {
60 (24_000_000 as Weight)60 24_000_000_u64
61 .saturating_add(DbWeight::get().reads(1 as Weight))61 .saturating_add(DbWeight::get().reads(1_u64))
62 .saturating_add(DbWeight::get().writes(1 as Weight))62 .saturating_add(DbWeight::get().writes(1_u64))
63 } 63 }
64 fn create_item(s: usize, ) -> Weight {64 fn create_item(s: usize) -> Weight {
65 (130_000_000 as Weight)65 130_000_000_u64
66 .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temporary multiplier, fee for storage66 .saturating_add(2135_u64.saturating_mul(s as Weight).saturating_mul(500_u64)) // 500 is temporary multiplier, fee for storage
67 .saturating_add(DbWeight::get().reads(10 as Weight))67 .saturating_add(DbWeight::get().reads(10_u64))
68 .saturating_add(DbWeight::get().writes(8 as Weight))68 .saturating_add(DbWeight::get().writes(8_u64))
69 } 69 }
70 fn burn_item() -> Weight {70 fn burn_item() -> Weight {
71 (170_000_000 as Weight)71 170_000_000_u64
72 .saturating_add(DbWeight::get().reads(9 as Weight))72 .saturating_add(DbWeight::get().reads(9_u64))
73 .saturating_add(DbWeight::get().writes(7 as Weight))73 .saturating_add(DbWeight::get().writes(7_u64))
74 } 74 }
75 fn transfer() -> Weight {75 fn transfer() -> Weight {
76 (125_000_000 as Weight)76 125_000_000_u64
77 .saturating_add(DbWeight::get().reads(7 as Weight))77 .saturating_add(DbWeight::get().reads(7_u64))
78 .saturating_add(DbWeight::get().writes(7 as Weight))78 .saturating_add(DbWeight::get().writes(7_u64))
79 } 79 }
80 fn approve() -> Weight {80 fn approve() -> Weight {
81 (45_000_000 as Weight)81 45_000_000_u64
82 .saturating_add(DbWeight::get().reads(3 as Weight))82 .saturating_add(DbWeight::get().reads(3_u64))
83 .saturating_add(DbWeight::get().writes(1 as Weight))83 .saturating_add(DbWeight::get().writes(1_u64))
84 }84 }
85 fn transfer_from() -> Weight {85 fn transfer_from() -> Weight {
86 (150_000_000 as Weight)86 150_000_000_u64
87 .saturating_add(DbWeight::get().reads(9 as Weight))87 .saturating_add(DbWeight::get().reads(9_u64))
88 .saturating_add(DbWeight::get().writes(8 as Weight))88 .saturating_add(DbWeight::get().writes(8_u64))
89 }89 }
90 fn set_offchain_schema() -> Weight {90 fn set_offchain_schema() -> Weight {
91 (33_000_000 as Weight)91 33_000_000_u64
92 .saturating_add(DbWeight::get().reads(2 as Weight))92 .saturating_add(DbWeight::get().reads(2_u64))
93 .saturating_add(DbWeight::get().writes(1 as Weight))93 .saturating_add(DbWeight::get().writes(1_u64))
94 }94 }
95 fn set_const_on_chain_schema() -> Weight {95 fn set_const_on_chain_schema() -> Weight {
96 (11_100_000 as Weight)96 11_100_000_u64
97 .saturating_add(DbWeight::get().reads(2 as Weight))97 .saturating_add(DbWeight::get().reads(2_u64))
98 .saturating_add(DbWeight::get().writes(1 as Weight))98 .saturating_add(DbWeight::get().writes(1_u64))
99 }99 }
100 fn set_variable_on_chain_schema() -> Weight {100 fn set_variable_on_chain_schema() -> Weight {
101 (11_100_000 as Weight)101 11_100_000_u64
102 .saturating_add(DbWeight::get().reads(2 as Weight))102 .saturating_add(DbWeight::get().reads(2_u64))
103 .saturating_add(DbWeight::get().writes(1 as Weight))103 .saturating_add(DbWeight::get().writes(1_u64))
104 }104 }
105 fn set_variable_meta_data() -> Weight {105 fn set_variable_meta_data() -> Weight {
106 (17_500_000 as Weight)106 17_500_000_u64
107 .saturating_add(DbWeight::get().reads(2 as Weight))107 .saturating_add(DbWeight::get().reads(2_u64))
108 .saturating_add(DbWeight::get().writes(1 as Weight))108 .saturating_add(DbWeight::get().writes(1_u64))
109 }109 }
110 fn enable_contract_sponsoring() -> Weight {110 fn enable_contract_sponsoring() -> Weight {
111 (13_000_000 as Weight)111 13_000_000_u64
112 .saturating_add(DbWeight::get().reads(1 as Weight))112 .saturating_add(DbWeight::get().reads(1_u64))
113 .saturating_add(DbWeight::get().writes(1 as Weight))113 .saturating_add(DbWeight::get().writes(1_u64))
114 }114 }
115 fn set_schema_version() -> Weight {115 fn set_schema_version() -> Weight {
116 (8_500_000 as Weight)116 8_500_000_u64
117 .saturating_add(DbWeight::get().reads(2 as Weight))117 .saturating_add(DbWeight::get().reads(2_u64))
118 .saturating_add(DbWeight::get().writes(1 as Weight))118 .saturating_add(DbWeight::get().writes(1_u64))
119 }119 }
120 fn set_chain_limits() -> Weight {120 fn set_chain_limits() -> Weight {
121 (1_300_000 as Weight)121 1_300_000_u64
122 .saturating_add(DbWeight::get().reads(0 as Weight))122 .saturating_add(DbWeight::get().reads(0_u64))
123 .saturating_add(DbWeight::get().writes(1 as Weight))123 .saturating_add(DbWeight::get().writes(1_u64))
124 }124 }
125 fn set_contract_sponsoring_rate_limit() -> Weight {125 fn set_contract_sponsoring_rate_limit() -> Weight {
126 (3_500_000 as Weight)126 3_500_000_u64
127 .saturating_add(DbWeight::get().reads(0 as Weight))127 .saturating_add(DbWeight::get().reads(0_u64))
128 .saturating_add(DbWeight::get().writes(2 as Weight))128 .saturating_add(DbWeight::get().writes(2_u64))
129 } 129 }
130 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {130 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {
131 (3_500_000 as Weight)131 3_500_000_u64
132 .saturating_add(DbWeight::get().reads(2 as Weight))132 .saturating_add(DbWeight::get().reads(2_u64))
133 .saturating_add(DbWeight::get().writes(1 as Weight))133 .saturating_add(DbWeight::get().writes(1_u64))
134 }134 }
135 fn toggle_contract_white_list() -> Weight {135 fn toggle_contract_white_list() -> Weight {
136 (3_000_000 as Weight)136 3_000_000_u64
137 .saturating_add(DbWeight::get().reads(0 as Weight))137 .saturating_add(DbWeight::get().reads(0_u64))
138 .saturating_add(DbWeight::get().writes(2 as Weight))138 .saturating_add(DbWeight::get().writes(2_u64))
139 } 139 }
140 fn add_to_contract_white_list() -> Weight {140 fn add_to_contract_white_list() -> Weight {
141 (3_000_000 as Weight)141 3_000_000_u64
142 .saturating_add(DbWeight::get().reads(0 as Weight))142 .saturating_add(DbWeight::get().reads(0_u64))
143 .saturating_add(DbWeight::get().writes(2 as Weight))143 .saturating_add(DbWeight::get().writes(2_u64))
144 } 144 }
145 fn remove_from_contract_white_list() -> Weight {145 fn remove_from_contract_white_list() -> Weight {
146 (3_200_000 as Weight)146 3_200_000_u64
147 .saturating_add(DbWeight::get().reads(0 as Weight))147 .saturating_add(DbWeight::get().reads(0_u64))
148 .saturating_add(DbWeight::get().writes(2 as Weight))148 .saturating_add(DbWeight::get().writes(2_u64))
149 }149 }
150 fn set_collection_limits() -> Weight {150 fn set_collection_limits() -> Weight {
151 (8_900_000 as Weight)151 8_900_000_u64
152 .saturating_add(DbWeight::get().reads(2 as Weight))152 .saturating_add(DbWeight::get().reads(2_u64))
153 .saturating_add(DbWeight::get().writes(1 as Weight))153 .saturating_add(DbWeight::get().writes(1_u64))
154 }154 }
155}155}
156156
modifiedpallets/nft/src/eth/account.rsdiffbeforeafterboth
1010
11pub trait CrossAccountId<AccountId>: 11pub trait CrossAccountId<AccountId>:
12 Encode + EncodeLike + Decode + 12 Encode + EncodeLike + Decode + Clone + PartialEq + Ord + core::fmt::Debug
13 Clone + PartialEq + Ord + core::fmt::Debug // + 13// +
14 // Serialize + Deserialize<'static> 14// Serialize + Deserialize<'static>
15{15{
16 fn as_sub(&self) -> &AccountId;16 fn as_sub(&self) -> &AccountId;
17 fn as_eth(&self) -> &H160;17 fn as_eth(&self) -> &H160;
20 fn from_eth(account: H160) -> Self;20 fn from_eth(account: H160) -> Self;
21}21}
2222
23#[derive(Eq)]23#[derive(Eq, Serialize, Deserialize)]
24#[derive(Serialize, Deserialize)]
25pub struct BasicCrossAccountId<T: Config> {24pub struct BasicCrossAccountId<T: Config> {
26 /// If true - then ethereum is canonical encoding25 /// If true - then ethereum is canonical encoding
27 from_ethereum: bool,26 from_ethereum: bool,
90impl<T: Config> Decode for BasicCrossAccountId<T> {90impl<T: Config> Decode for BasicCrossAccountId<T> {
91 fn decode<I>(input: &mut I) -> Result<Self, codec::Error>91 fn decode<I>(input: &mut I) -> Result<Self, codec::Error>
92 where I: codec::Input92 where
93 I: codec::Input,
93 {94 {
94 Ok(match <Result<T::AccountId, H160>>::decode(input)? {95 Ok(match <Result<T::AccountId, H160>>::decode(input)? {
95 Ok(s) => Self::from_sub(s),96 Ok(s) => Self::from_sub(s),
modifiedpallets/nft/src/eth/erc.rsdiffbeforeafterboth
58 #[indexed] operator: address,68 #[indexed]
69 operator: address,
59 approved: bool,70 approved: bool,
60 }71 },
61}72}
6273
63#[solidity_interface(is(ERC165), events(ERC721Events))]74#[solidity_interface(is(ERC165), events(ERC721Events))]
103 #[indexed] spender: address,164 #[indexed]
165 spender: address,
104 value: uint256,166 value: uint256,
105 }167 },
106}168}
107169
108#[solidity_interface(inline_is(InlineNameSymbol, InlineTotalSupply), events(ERC20Events))]170#[solidity_interface(inline_is(InlineNameSymbol, InlineTotalSupply), events(ERC20Events))]
122 type Error;200 type Error;
123}201}
124202
125/// Runtime metadata like helpers for evm
126#[solidity_interface]
127trait UniqueHelpers {
128 type Error;
129
130 /// Returns interface for NFT collections
131 fn nft_interface(&self) -> Result<string, Self::Error>;
132 /// Returns interface for Fungible collections
133 fn fungible_interface(&self) -> Result<string, Self::Error>;
134}
modifiedpallets/nft/src/eth/erc_impl.rsdiffbeforeafterboth
56 Ok(index)56 Ok(index)
57 }57 }
5858
59 fn token_of_owner_by_index(&self, owner: address, index: uint256) -> Result<uint256> {59 fn token_of_owner_by_index(&self, _owner: address, _index: uint256) -> Result<uint256> {
60 // TODO: Not implemetable60 // TODO: Not implemetable
61 Err("not implemented".into())61 Err("not implemented".into())
62 }62 }
77 fn owner_of(&self, token_id: uint256) -> Result<address> {77 fn owner_of(&self, token_id: uint256) -> Result<address> {
78 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;78 let token_id: u32 = token_id.try_into().map_err(|_| "token id overflow")?;
79 let token = <NftItemList<T>>::get(self.id, token_id).ok_or("unknown token")?;79 let token = <NftItemList<T>>::get(self.id, token_id).ok_or("unknown token")?;
80 Ok(token.owner.as_eth().clone())80 Ok(*token.owner.as_eth())
81 }81 }
82 fn safe_transfer_from_with_data(82 fn safe_transfer_from_with_data(
83 &mut self,83 &mut self,
170 caller: caller,170 caller: caller,
171 to: address,171 to: address,
172 token_id: uint256,172 token_id: uint256,
173 value: value,173 _value: value,
174 ) -> Result<void> {174 ) -> Result<void> {
175 let caller = T::CrossAccountId::from_eth(caller);175 let caller = T::CrossAccountId::from_eth(caller);
176 let to = T::CrossAccountId::from_eth(to);176 let to = T::CrossAccountId::from_eth(to);
modifiedpallets/nft/src/eth/log.rsdiffbeforeafterboth
1use sp_std::cell::RefCell;1use sp_std::cell::RefCell;
2use sp_std::vec::Vec;2use sp_std::vec::Vec;
3use sp_core::{H160, H256};3
4use ethereum::Log;4use ethereum::Log;
55
6#[derive(Default)]6#[derive(Default)]
modifiedpallets/nft/src/eth/mod.rsdiffbeforeafterboth
28];28];
2929
30fn map_eth_to_id(eth: &H160) -> Option<CollectionId> {30fn map_eth_to_id(eth: &H160) -> Option<CollectionId> {
31 if &eth[0..16] != ETH_ACCOUNT_PREFIX {31 if eth[0..16] != ETH_ACCOUNT_PREFIX {
32 return None;32 return None;
33 }33 }
34 let mut id_bytes = [0; 4];34 let mut id_bytes = [0; 4];
92 },92 },
93 )?))93 )?))
94 }94 }
95 _ => {95 _ => Err(StringError::from(
96 return Err(StringError::from(
97 "erc calls only supported to fungible and nft collections for now",96 "erc calls only supported to fungible and nft collections for now",
98 )97 )),
99 .into())
100 }
101 }98 }
102}99}
103100
156153
157// TODO: This function is slow, and output can be memoized154// TODO: This function is slow, and output can be memoized
158pub fn generate_transaction(collection_id: u32, chain_id: u64) -> ethereum::Transaction {155pub fn generate_transaction(collection_id: u32, chain_id: u64) -> ethereum::Transaction {
159 let contract = collection_id_to_address(collection_id);
160
161 // FIXME: Can be done on wasm runtime with https://github.com/paritytech/substrate/pull/8728156 // FIXME: Can be done on wasm runtime with https://github.com/paritytech/substrate/pull/8728
162 #[cfg(feature = "std")]157 #[cfg(feature = "std")]
163 {158 {
159 let contract = collection_id_to_address(collection_id);
164 let signed = ethereum_tx_sign::RawTransaction {160 let signed = ethereum_tx_sign::RawTransaction {
165 nonce: 0.into(),161 nonce: 0.into(),
166 to: Some(contract.0.into()),162 to: Some(contract.0.into()),
183 }179 }
184 #[cfg(not(feature = "std"))]180 #[cfg(not(feature = "std"))]
185 {181 {
186 panic!("transaction generation not yet supported by wasm runtime")182 panic!("transaction generation not yet supported by wasm runtime while generating transaction for collection_id {}, chain_id {}", collection_id, chain_id)
187 }183 }
188}184}
189185
modifiedpallets/nft/src/eth/sponsoring.rsdiffbeforeafterboth
22
3use crate::{Collection, ChainLimit, CollectionById, Config, NftTransferBasket, FungibleTransferBasket, eth::account::EvmBackwardsAddressMapping};3use crate::{
4 Collection, ChainLimit, CollectionById, Config, NftTransferBasket, FungibleTransferBasket,
5 eth::account::EvmBackwardsAddressMapping,
6};
4use evm_coder::abi::AbiReader;7use evm_coder::abi::AbiReader;
5use frame_support::{storage::{StorageMap, StorageDoubleMap, StorageValue}, traits::Currency};8use frame_support::{
9 storage::{StorageMap, StorageDoubleMap, StorageValue},
10 traits::Currency,
11};
6use pallet_evm::{EVMCurrencyAdapter, WithdrawReason};12use pallet_evm::{EVMCurrencyAdapter, WithdrawReason};
7use sp_core::{H160, U256};13use sp_core::{H160, U256};
8use sp_std::prelude::*;14use sp_std::prelude::*;
9use super::{account::CrossAccountId, erc::{UniqueFungibleCall, UniqueNFTCall, ERC721Call, ERC20Call, ERC721UniqueExtensionsCall}};15use super::{
16 account::CrossAccountId,
17 erc::{UniqueFungibleCall, UniqueNFTCall, ERC721Call, ERC20Call, ERC721UniqueExtensionsCall},
18};
10use core::convert::TryInto;19use core::convert::TryInto;
1120
50 }70 }
51 if sponsor {71 if sponsor {
52 <NftTransferBasket<T>>::insert(collection_id, token_id, block_number);72 <NftTransferBasket<T>>::insert(collection_id, token_id, block_number);
53 return Ok(())73 return Ok(());
54 }74 }
55 },75 }
56 _ => {},76 _ => {}
57 }77 }
58 },78 }
59 crate::CollectionMode::Fungible(_) => {79 crate::CollectionMode::Fungible(_) => {
60 let call: UniqueFungibleCall = UniqueFungibleCall::parse(method_id, &mut reader).map_err(|_| AnyError)?.ok_or(AnyError)?;80 let call: UniqueFungibleCall = UniqueFungibleCall::parse(method_id, &mut reader)
81 .map_err(|_| AnyError)?
82 .ok_or(AnyError)?;
83 #[allow(clippy::single_match)]
61 match call {84 match call {
62 UniqueFungibleCall::ERC20(ERC20Call::Transfer {..}) => {85 UniqueFungibleCall::ERC20(ERC20Call::Transfer { .. }) => {
63 let who = T::CrossAccountId::from_eth(caller.clone());86 let who = T::CrossAccountId::from_eth(*caller);
64 let collection_limits = &collection.limits;87 let collection_limits = &collection.limits;
65 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {88 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
66 collection_limits.sponsor_transfer_timeout89 collection_limits.sponsor_transfer_timeout
107 who.as_sub(),
108 block_number,
109 );
82 return Ok(())110 return Ok(());
83 }111 }
84 },112 }
85 _ => {},113 _ => {}
86 }114 }
87 },115 }
88 _ => {},116 _ => {}
89 }117 }
90 return Err(AnyError)118 Err(AnyError)
91}119}
92120
93impl<T> pallet_evm::OnChargeEVMTransaction<T> for ChargeEvmTransaction121impl<T> pallet_evm::OnChargeEVMTransaction<T> for ChargeEvmTransaction
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
6#![recursion_limit = "1024"]6#![recursion_limit = "1024"]
7
8#![cfg_attr(not(feature = "std"), no_std)]7#![cfg_attr(not(feature = "std"), no_std)]
8#![allow(
9 clippy::too_many_arguments,
10 clippy::unnecessary_mut_passed,
11 clippy::unused_unit
12)]
913
10extern crate alloc;14extern crate alloc;
1115
3033
31use frame_system::{self as system, ensure_signed, ensure_root};34use frame_system::{self as system, ensure_signed, ensure_root};
32use sp_core::H160;35use sp_core::H160;
36use sp_std::vec;
33use sp_runtime::sp_std::prelude::Vec;37use sp_runtime::sp_std::prelude::Vec;
34use core::ops::{Deref, DerefMut};38use core::ops::{Deref, DerefMut};
35use core::cell::RefCell;39use core::cell::RefCell;
36use nft_data_structs::{40use nft_data_structs::{
37 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,41 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,
38 AccessMode, ChainLimits, Collection, CreateItemData, CollectionLimits,42 AccessMode, ChainLimits, Collection, CreateItemData, CollectionLimits, CollectionId,
39 CollectionId, CollectionMode, TokenId, 43 CollectionMode, TokenId, SchemaVersion, SponsorshipState, Ownership, NftItemType,
40 SchemaVersion, SponsorshipState, Ownership,
41 NftItemType, FungibleItemType, ReFungibleItemType44 FungibleItemType, ReFungibleItemType,
42};45};
43use pallet_ethereum::EthereumTransactionSender;46use pallet_ethereum::EthereumTransactionSender;
4447
211 self.logs.log(log.to_log(self.evm_address))213 self.logs.log(log.to_log(self.evm_address))
212 }214 }
213 pub fn into_inner(self) -> Collection<T> {215 pub fn into_inner(self) -> Collection<T> {
214 self.collection.clone()216 self.collection
215 }217 }
216}218}
217impl<T: Config> Deref for CollectionHandle<T> {219impl<T: Config> Deref for CollectionHandle<T> {
240 type CrossAccountId: CrossAccountId<Self::AccountId>;242 type CrossAccountId: CrossAccountId<Self::AccountId>;
241 type Currency: Currency<Self::AccountId>;243 type Currency: Currency<Self::AccountId>;
242 type CollectionCreationPrice: Get<<<Self as Config>::Currency as Currency<Self::AccountId>>::Balance>;244 type CollectionCreationPrice: Get<
245 <<Self as Config>::Currency as Currency<Self::AccountId>>::Balance,
246 >;
243 type TreasuryAccountId: Get<Self::AccountId>;247 type TreasuryAccountId: Get<Self::AccountId>;
244248
374 CrossAccountId = <T as Config>::CrossAccountId,378 CrossAccountId = <T as Config>::CrossAccountId,
375 {379 {
376 /// New collection was created380 /// New collection was created
377 /// 381 ///
378 /// # Arguments382 /// # Arguments
379 /// 383 ///
380 /// * collection_id: Globally unique identifier of newly created collection.384 /// * collection_id: Globally unique identifier of newly created collection.
381 /// 385 ///
382 /// * mode: [CollectionMode] converted into u8.386 /// * mode: [CollectionMode] converted into u8.
383 /// 387 ///
384 /// * account_id: Collection owner.388 /// * account_id: Collection owner.
385 CollectionCreated(CollectionId, u8, AccountId),389 CollectionCreated(CollectionId, u8, AccountId),
386390
387 /// New item was created.391 /// New item was created.
388 /// 392 ///
389 /// # Arguments393 /// # Arguments
390 /// 394 ///
391 /// * collection_id: Id of the collection where item was created.395 /// * collection_id: Id of the collection where item was created.
392 /// 396 ///
393 /// * item_id: Id of an item. Unique within the collection.397 /// * item_id: Id of an item. Unique within the collection.
394 ///398 ///
395 /// * recipient: Owner of newly created item 399 /// * recipient: Owner of newly created item
396 ItemCreated(CollectionId, TokenId, CrossAccountId),400 ItemCreated(CollectionId, TokenId, CrossAccountId),
397401
398 /// Collection item was burned.402 /// Collection item was burned.
399 /// 403 ///
400 /// # Arguments404 /// # Arguments
401 /// 405 ///
402 /// collection_id.406 /// collection_id.
403 /// 407 ///
404 /// item_id: Identifier of burned NFT.408 /// item_id: Identifier of burned NFT.
405 ItemDestroyed(CollectionId, TokenId),409 ItemDestroyed(CollectionId, TokenId),
406410
443 }447 }
444448
445 /// 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 and admin of the collection are set to the address that signed the transaction. Both addresses can be changed later.449 /// 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 and admin of the collection are set to the address that signed the transaction. Both addresses can be changed later.
446 /// 450 ///
447 /// # Permissions451 /// # Permissions
448 /// 452 ///
449 /// * Anyone.453 /// * Anyone.
450 /// 454 ///
451 /// # Arguments455 /// # Arguments
452 /// 456 ///
453 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.457 /// * collection_name: UTF-16 string with collection name (limit 64 characters), will be stored as zero-terminated.
454 /// 458 ///
455 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.459 /// * collection_description: UTF-16 string with collection description (limit 256 characters), will be stored as zero-terminated.
456 /// 460 ///
457 /// * token_prefix: UTF-8 string with token prefix.461 /// * token_prefix: UTF-8 string with token prefix.
458 /// 462 ///
459 /// * mode: [CollectionMode] collection type and type dependent data.463 /// * mode: [CollectionMode] collection type and type dependent data.
460 // returns collection ID464 // returns collection ID
461 #[weight = <T as Config>::WeightInfo::create_collection()]465 #[weight = <T as Config>::WeightInfo::create_collection()]
521 mint_mode: false,525 mint_mode: false,
522 access: AccessMode::Normal,526 access: AccessMode::Normal,
523 description: collection_description,527 description: collection_description,
524 decimal_points: decimal_points,528 decimal_points,
525 token_prefix: token_prefix,529 token_prefix,
526 offchain_schema: Vec::new(),530 offchain_schema: Vec::new(),
527 schema_version: SchemaVersion::ImageURL,531 schema_version: SchemaVersion::ImageURL,
528 sponsorship: SponsorshipState::Disabled,532 sponsorship: SponsorshipState::Disabled,
535 <CollectionById<T>>::insert(next_id, new_collection);539 <CollectionById<T>>::insert(next_id, new_collection);
536540
537 // call event541 // call event
538 Self::deposit_event(RawEvent::CollectionCreated(next_id, mode.into(), who));542 Self::deposit_event(RawEvent::CollectionCreated(next_id, mode.id(), who));
539543
540 Ok(())544 Ok(())
541 }545 }
542546
543 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.547 /// **DANGEROUS**: Destroys collection and all NFTs within this collection. Users irrecoverably lose their assets and may lose real money.
544 /// 548 ///
545 /// # Permissions549 /// # Permissions
546 /// 550 ///
547 /// * Collection Owner.551 /// * Collection Owner.
548 /// 552 ///
549 /// # Arguments553 /// # Arguments
550 /// 554 ///
551 /// * collection_id: collection to destroy.555 /// * collection_id: collection to destroy.
552 #[weight = <T as Config>::WeightInfo::destroy_collection()]556 #[weight = <T as Config>::WeightInfo::destroy_collection()]
553 #[transactional]557 #[transactional]
586 }590 }
587591
588 /// Add an address to white list.592 /// Add an address to white list.
589 /// 593 ///
590 /// # Permissions594 /// # Permissions
591 /// 595 ///
592 /// * Collection Owner596 /// * Collection Owner
593 /// * Collection Admin597 /// * Collection Admin
594 /// 598 ///
595 /// # Arguments599 /// # Arguments
596 /// 600 ///
597 /// * collection_id.601 /// * collection_id.
598 /// 602 ///
599 /// * address.603 /// * address.
600 #[weight = <T as Config>::WeightInfo::add_to_white_list()]604 #[weight = <T as Config>::WeightInfo::add_to_white_list()]
601 #[transactional]605 #[transactional]
615 }619 }
616620
617 /// Remove an address from white list.621 /// Remove an address from white list.
618 /// 622 ///
619 /// # Permissions623 /// # Permissions
620 /// 624 ///
621 /// * Collection Owner625 /// * Collection Owner
622 /// * Collection Admin626 /// * Collection Admin
623 /// 627 ///
624 /// # Arguments628 /// # Arguments
625 /// 629 ///
626 /// * collection_id.630 /// * collection_id.
627 /// 631 ///
628 /// * address.632 /// * address.
629 #[weight = <T as Config>::WeightInfo::remove_from_white_list()]633 #[weight = <T as Config>::WeightInfo::remove_from_white_list()]
630 #[transactional]634 #[transactional]
644 }648 }
645649
646 /// Toggle between normal and white list access for the methods with access for `Anyone`.650 /// Toggle between normal and white list access for the methods with access for `Anyone`.
647 /// 651 ///
648 /// # Permissions652 /// # Permissions
649 /// 653 ///
650 /// * Collection Owner.654 /// * Collection Owner.
651 /// 655 ///
652 /// # Arguments656 /// # Arguments
653 /// 657 ///
654 /// * collection_id.658 /// * collection_id.
655 /// 659 ///
656 /// * mode: [AccessMode]660 /// * mode: [AccessMode]
657 #[weight = <T as Config>::WeightInfo::set_public_access_mode()]661 #[weight = <T as Config>::WeightInfo::set_public_access_mode()]
658 #[transactional]662 #[transactional]
672 /// * White List is enabled, and676 /// * White List is enabled, and
673 /// * Address is added to white list, and677 /// * Address is added to white list, and
674 /// * This method was called with True parameter678 /// * This method was called with True parameter
675 /// 679 ///
676 /// # Permissions680 /// # Permissions
677 /// * Collection Owner681 /// * Collection Owner
678 ///682 ///
679 /// # Arguments683 /// # Arguments
680 /// 684 ///
681 /// * collection_id.685 /// * collection_id.
682 /// 686 ///
683 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.687 /// * mint_permission: Boolean parameter. If True, allows minting to Anyone with conditions above.
684 #[weight = <T as Config>::WeightInfo::set_mint_permission()]688 #[weight = <T as Config>::WeightInfo::set_mint_permission()]
685 #[transactional]689 #[transactional]
696 }700 }
697701
698 /// Change the owner of the collection.702 /// Change the owner of the collection.
699 /// 703 ///
700 /// # Permissions704 /// # Permissions
701 /// 705 ///
702 /// * Collection Owner.706 /// * Collection Owner.
703 /// 707 ///
704 /// # Arguments708 /// # Arguments
705 /// 709 ///
706 /// * collection_id.710 /// * collection_id.
707 /// 711 ///
708 /// * new_owner.712 /// * new_owner.
709 #[weight = <T as Config>::WeightInfo::change_collection_owner()]713 #[weight = <T as Config>::WeightInfo::change_collection_owner()]
710 #[transactional]714 #[transactional]
720 }724 }
721725
722 /// Adds an admin of the Collection.726 /// Adds an admin of the Collection.
723 /// 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. 727 /// 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.
724 /// 728 ///
725 /// # Permissions729 /// # Permissions
726 /// 730 ///
727 /// * Collection Owner.731 /// * Collection Owner.
728 /// * Collection Admin.732 /// * Collection Admin.
729 /// 733 ///
730 /// # Arguments734 /// # Arguments
731 /// 735 ///
732 /// * collection_id: ID of the Collection to add admin for.736 /// * collection_id: ID of the Collection to add admin for.
733 /// 737 ///
734 /// * new_admin_id: Address of new admin to add.738 /// * new_admin_id: Address of new admin to add.
735 #[weight = <T as Config>::WeightInfo::add_collection_admin()]739 #[weight = <T as Config>::WeightInfo::add_collection_admin()]
736 #[transactional]740 #[transactional]
755 /// 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.759 /// 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.
756 ///760 ///
757 /// # Permissions761 /// # Permissions
758 /// 762 ///
759 /// * Collection Owner.763 /// * Collection Owner.
760 /// * Collection Admin.764 /// * Collection Admin.
761 /// 765 ///
762 /// # Arguments766 /// # Arguments
763 /// 767 ///
764 /// * collection_id: ID of the Collection to remove admin for.768 /// * collection_id: ID of the Collection to remove admin for.
765 /// 769 ///
766 /// * account_id: Address of admin to remove.770 /// * account_id: Address of admin to remove.
767 #[weight = <T as Config>::WeightInfo::remove_collection_admin()]771 #[weight = <T as Config>::WeightInfo::remove_collection_admin()]
768 #[transactional]772 #[transactional]
772 Self::check_owner_or_admin_permissions(&collection, &sender)?;776 Self::check_owner_or_admin_permissions(&collection, &sender)?;
773 let mut admin_arr = <AdminList<T>>::get(collection_id);777 let mut admin_arr = <AdminList<T>>::get(collection_id);
774778
775 match admin_arr.binary_search(&account_id) {779 if let Ok(idx) = admin_arr.binary_search(&account_id) {
776 Ok(idx) => {
777 admin_arr.remove(idx);780 admin_arr.remove(idx);
778 <AdminList<T>>::insert(collection_id, admin_arr);781 <AdminList<T>>::insert(collection_id, admin_arr);
779 },
780 Err(_) => {}
781 }782 }
782 Ok(())783 Ok(())
783 }784 }
784785
785 /// # Permissions786 /// # Permissions
786 /// 787 ///
787 /// * Collection Owner788 /// * Collection Owner
788 /// 789 ///
789 /// # Arguments790 /// # Arguments
790 /// 791 ///
791 /// * collection_id.792 /// * collection_id.
792 /// 793 ///
793 /// * new_sponsor.794 /// * new_sponsor.
794 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]795 #[weight = <T as Config>::WeightInfo::set_collection_sponsor()]
795 #[transactional]796 #[transactional]
805 }806 }
806807
807 /// # Permissions808 /// # Permissions
808 /// 809 ///
809 /// * Sponsor.810 /// * Sponsor.
810 /// 811 ///
811 /// # Arguments812 /// # Arguments
812 /// 813 ///
813 /// * collection_id.814 /// * collection_id.
814 #[weight = <T as Config>::WeightInfo::confirm_sponsorship()]815 #[weight = <T as Config>::WeightInfo::confirm_sponsorship()]
815 #[transactional]816 #[transactional]
833 /// # Permissions834 /// # Permissions
834 ///835 ///
835 /// * Collection owner.836 /// * Collection owner.
836 /// 837 ///
837 /// # Arguments838 /// # Arguments
838 /// 839 ///
839 /// * collection_id.840 /// * collection_id.
840 #[weight = <T as Config>::WeightInfo::remove_collection_sponsor()]841 #[weight = <T as Config>::WeightInfo::remove_collection_sponsor()]
841 #[transactional]842 #[transactional]
852 }853 }
853854
854 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.855 /// This method creates a concrete instance of NFT Collection created with CreateCollection method.
855 /// 856 ///
856 /// # Permissions857 /// # Permissions
857 /// 858 ///
858 /// * Collection Owner.859 /// * Collection Owner.
859 /// * Collection Admin.860 /// * Collection Admin.
860 /// * Anyone if861 /// * Anyone if
861 /// * White List is enabled, and862 /// * White List is enabled, and
862 /// * Address is added to white list, and863 /// * Address is added to white list, and
863 /// * MintPermission is enabled (see SetMintPermission method)864 /// * MintPermission is enabled (see SetMintPermission method)
864 /// 865 ///
865 /// # Arguments866 /// # Arguments
866 /// 867 ///
867 /// * collection_id: ID of the collection.868 /// * collection_id: ID of the collection.
868 /// 869 ///
869 /// * owner: Address, initial owner of the NFT.870 /// * owner: Address, initial owner of the NFT.
870 ///871 ///
871 /// * data: Token data to store on chain.872 /// * data: Token data to store on chain.
875 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))876 // .saturating_add(RocksDbWeight::get().reads(10 as Weight))
876 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]877 // .saturating_add(RocksDbWeight::get().writes(8 as Weight))]
877878
878 #[weight = <T as Config>::WeightInfo::create_item(data.len())]879 #[weight = <T as Config>::WeightInfo::create_item(data.data_size())]
879 #[transactional]880 #[transactional]
880 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {881 pub fn create_item(origin, collection_id: CollectionId, owner: T::CrossAccountId, data: CreateItemData) -> DispatchResult {
881 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);882 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
888 }889 }
889890
890 /// This method creates multiple items in a collection created with CreateCollection method.891 /// This method creates multiple items in a collection created with CreateCollection method.
891 /// 892 ///
892 /// # Permissions893 /// # Permissions
893 /// 894 ///
894 /// * Collection Owner.895 /// * Collection Owner.
895 /// * Collection Admin.896 /// * Collection Admin.
896 /// * Anyone if897 /// * Anyone if
897 /// * White List is enabled, and898 /// * White List is enabled, and
898 /// * Address is added to white list, and899 /// * Address is added to white list, and
899 /// * MintPermission is enabled (see SetMintPermission method)900 /// * MintPermission is enabled (see SetMintPermission method)
900 /// 901 ///
901 /// # Arguments902 /// # Arguments
902 /// 903 ///
903 /// * collection_id: ID of the collection.904 /// * collection_id: ID of the collection.
904 /// 905 ///
905 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].906 /// * itemsData: Array items properties. Each property is an array of bytes itself, see [create_item].
906 /// 907 ///
907 /// * owner: Address, initial owner of the NFT.908 /// * owner: Address, initial owner of the NFT.
908 #[weight = <T as Config>::WeightInfo::create_item(items_data.into_iter()909 #[weight = <T as Config>::WeightInfo::create_item(items_data.iter()
909 .map(|data| { data.len() })910 .map(|data| { data.data_size() })
910 .sum())]911 .sum())]
911 #[transactional]912 #[transactional]
912 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {913 pub fn create_multiple_items(origin, collection_id: CollectionId, owner: T::CrossAccountId, items_data: Vec<CreateItemData>) -> DispatchResult {
913914
914 ensure!(items_data.len() > 0, Error::<T>::EmptyArgument);915 ensure!(!items_data.is_empty(), Error::<T>::EmptyArgument);
915 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);916 let sender = T::CrossAccountId::from_sub(ensure_signed(origin)?);
916 let collection = Self::get_collection(collection_id)?;917 let collection = Self::get_collection(collection_id)?;
917918
922 }923 }
923924
924 /// Destroys a concrete instance of NFT.925 /// Destroys a concrete instance of NFT.
925 /// 926 ///
926 /// # Permissions927 /// # Permissions
927 /// 928 ///
928 /// * Collection Owner.929 /// * Collection Owner.
929 /// * Collection Admin.930 /// * Collection Admin.
930 /// * Current NFT Owner.931 /// * Current NFT Owner.
931 /// 932 ///
932 /// # Arguments933 /// # Arguments
933 /// 934 ///
934 /// * collection_id: ID of the collection.935 /// * collection_id: ID of the collection.
935 /// 936 ///
936 /// * item_id: ID of NFT to burn.937 /// * item_id: ID of NFT to burn.
937 #[weight = <T as Config>::WeightInfo::burn_item()]938 #[weight = <T as Config>::WeightInfo::burn_item()]
938 #[transactional]939 #[transactional]
948 }949 }
949950
950 /// Change ownership of the token.951 /// Change ownership of the token.
951 /// 952 ///
952 /// # Permissions953 /// # Permissions
953 /// 954 ///
954 /// * Collection Owner955 /// * Collection Owner
955 /// * Collection Admin956 /// * Collection Admin
956 /// * Current NFT owner957 /// * Current NFT owner
957 ///958 ///
958 /// # Arguments959 /// # Arguments
959 /// 960 ///
960 /// * recipient: Address of token recipient.961 /// * recipient: Address of token recipient.
961 /// 962 ///
962 /// * collection_id.963 /// * collection_id.
963 /// 964 ///
964 /// * item_id: ID of the item965 /// * item_id: ID of the item
965 /// * Non-Fungible Mode: Required.966 /// * Non-Fungible Mode: Required.
966 /// * Fungible Mode: Ignored.967 /// * Fungible Mode: Ignored.
967 /// * Re-Fungible Mode: Required.968 /// * Re-Fungible Mode: Required.
968 /// 969 ///
969 /// * value: Amount to transfer.970 /// * value: Amount to transfer.
970 /// * Non-Fungible Mode: Ignored971 /// * Non-Fungible Mode: Ignored
971 /// * Fungible Mode: Must specify transferred amount972 /// * Fungible Mode: Must specify transferred amount
983 }984 }
984985
985 /// Set, change, or remove approved address to transfer the ownership of the NFT.986 /// Set, change, or remove approved address to transfer the ownership of the NFT.
986 /// 987 ///
987 /// # Permissions988 /// # Permissions
988 /// 989 ///
989 /// * Collection Owner990 /// * Collection Owner
990 /// * Collection Admin991 /// * Collection Admin
991 /// * Current NFT owner992 /// * Current NFT owner
992 /// 993 ///
993 /// # Arguments994 /// # Arguments
994 /// 995 ///
995 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).996 /// * approved: Address that is approved to transfer this NFT or zero (if needed to remove approval).
996 /// 997 ///
997 /// * collection_id.998 /// * collection_id.
998 /// 999 ///
999 /// * item_id: ID of the item.1000 /// * item_id: ID of the item.
1000 #[weight = <T as Config>::WeightInfo::approve()]1001 #[weight = <T as Config>::WeightInfo::approve()]
1001 #[transactional]1002 #[transactional]
1010 }1011 }
1011 1012
1012 /// 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.1013 /// 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.
1013 /// 1014 ///
1014 /// # Permissions1015 /// # Permissions
1015 /// * Collection Owner1016 /// * Collection Owner
1016 /// * Collection Admin1017 /// * Collection Admin
1017 /// * Current NFT owner1018 /// * Current NFT owner
1018 /// * Address approved by current NFT owner1019 /// * Address approved by current NFT owner
1019 /// 1020 ///
1020 /// # Arguments1021 /// # Arguments
1021 /// 1022 ///
1022 /// * from: Address that owns token.1023 /// * from: Address that owns token.
1023 /// 1024 ///
1024 /// * recipient: Address of token recipient.1025 /// * recipient: Address of token recipient.
1025 /// 1026 ///
1026 /// * collection_id.1027 /// * collection_id.
1027 /// 1028 ///
1028 /// * item_id: ID of the item.1029 /// * item_id: ID of the item.
1029 /// 1030 ///
1030 /// * value: Amount to transfer.1031 /// * value: Amount to transfer.
1031 #[weight = <T as Config>::WeightInfo::transfer_from()]1032 #[weight = <T as Config>::WeightInfo::transfer_from()]
1032 #[transactional]1033 #[transactional]
1053 // }1054 // }
10541055
1055 /// Set off-chain data schema.1056 /// Set off-chain data schema.
1056 /// 1057 ///
1057 /// # Permissions1058 /// # Permissions
1058 /// 1059 ///
1059 /// * Collection Owner1060 /// * Collection Owner
1060 /// * Collection Admin1061 /// * Collection Admin
1061 /// 1062 ///
1062 /// # Arguments1063 /// # Arguments
1063 /// 1064 ///
1064 /// * collection_id.1065 /// * collection_id.
1065 /// 1066 ///
1066 /// * schema: String representing the offchain data schema.1067 /// * schema: String representing the offchain data schema.
1067 #[weight = <T as Config>::WeightInfo::set_variable_meta_data()]1068 #[weight = <T as Config>::WeightInfo::set_variable_meta_data()]
1068 #[transactional]1069 #[transactional]
1084 /// Set schema standard1085 /// Set schema standard
1085 /// ImageURL1086 /// ImageURL
1086 /// Unique1087 /// Unique
1087 /// 1088 ///
1088 /// # Permissions1089 /// # Permissions
1089 /// 1090 ///
1090 /// * Collection Owner1091 /// * Collection Owner
1091 /// * Collection Admin1092 /// * Collection Admin
1092 /// 1093 ///
1093 /// # Arguments1094 /// # Arguments
1094 /// 1095 ///
1095 /// * collection_id.1096 /// * collection_id.
1096 /// 1097 ///
1097 /// * schema: SchemaVersion: enum1098 /// * schema: SchemaVersion: enum
1098 #[weight = <T as Config>::WeightInfo::set_schema_version()]1099 #[weight = <T as Config>::WeightInfo::set_schema_version()]
1099 #[transactional]1100 #[transactional]
1112 }1113 }
11131114
1114 /// Set off-chain data schema.1115 /// Set off-chain data schema.
1115 /// 1116 ///
1116 /// # Permissions1117 /// # Permissions
1117 /// 1118 ///
1118 /// * Collection Owner1119 /// * Collection Owner
1119 /// * Collection Admin1120 /// * Collection Admin
1120 /// 1121 ///
1121 /// # Arguments1122 /// # Arguments
1122 /// 1123 ///
1123 /// * collection_id.1124 /// * collection_id.
1124 /// 1125 ///
1125 /// * schema: String representing the offchain data schema.1126 /// * schema: String representing the offchain data schema.
1126 #[weight = <T as Config>::WeightInfo::set_offchain_schema()]1127 #[weight = <T as Config>::WeightInfo::set_offchain_schema()]
1127 #[transactional]1128 #[transactional]
1144 }1145 }
11451146
1146 /// Set const on-chain data schema.1147 /// Set const on-chain data schema.
1147 /// 1148 ///
1148 /// # Permissions1149 /// # Permissions
1149 /// 1150 ///
1150 /// * Collection Owner1151 /// * Collection Owner
1151 /// * Collection Admin1152 /// * Collection Admin
1152 /// 1153 ///
1153 /// # Arguments1154 /// # Arguments
1154 /// 1155 ///
1155 /// * collection_id.1156 /// * collection_id.
1156 /// 1157 ///
1157 /// * schema: String representing the const on-chain data schema.1158 /// * schema: String representing the const on-chain data schema.
1158 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1159 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]
1159 #[transactional]1160 #[transactional]
1176 }1177 }
11771178
1178 /// Set variable on-chain data schema.1179 /// Set variable on-chain data schema.
1179 /// 1180 ///
1180 /// # Permissions1181 /// # Permissions
1181 /// 1182 ///
1182 /// * Collection Owner1183 /// * Collection Owner
1183 /// * Collection Admin1184 /// * Collection Admin
1184 /// 1185 ///
1185 /// # Arguments1186 /// # Arguments
1186 /// 1187 ///
1187 /// * collection_id.1188 /// * collection_id.
1188 /// 1189 ///
1189 /// * schema: String representing the variable on-chain data schema.1190 /// * schema: String representing the variable on-chain data schema.
1190 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]1191 #[weight = <T as Config>::WeightInfo::set_const_on_chain_schema()]
1191 #[transactional]1192 #[transactional]
1304 sender.clone(),
1305 recipient.clone(),
1306 )?,
1289 CollectionMode::Fungible(_) => Self::transfer_fungible(target_collection, value, &sender, &recipient)?,1307 CollectionMode::Fungible(_) => {
1308 Self::transfer_fungible(target_collection, value, &sender, &recipient)?
1309 }
1290 CollectionMode::ReFungible => Self::transfer_refungible(target_collection, item_id, value, sender.clone(), recipient.clone())?,1310 CollectionMode::ReFungible => Self::transfer_refungible(
1311 target_collection,
1312 item_id,
1313 value,
1314 sender.clone(),
1315 recipient.clone(),
1316 )?,
1291 _ => ()1317 _ => (),
1292 };1318 };
12931319
1294 Self::deposit_event(RawEvent::Transfer(target_collection.id, item_id, sender.clone(), recipient.clone(), value));1320 Self::deposit_event(RawEvent::Transfer(
1352 collection.log(ERC20Events::Approval {1384 collection.log(ERC20Events::Approval {
1353 owner: *sender.as_eth(),1385 owner: *sender.as_eth(),
1354 spender: *spender.as_eth(),1386 spender: *spender.as_eth(),
1355 value: allowance.into()1387 value: allowance.into(),
1356 });1388 });
1357 }1389 }
13581390
1405 CollectionMode::Fungible(_) => {1446 CollectionMode::Fungible(_) => {
1406 Self::transfer_fungible(&collection, amount, &from, &recipient)?1447 Self::transfer_fungible(&collection, amount, &from, &recipient)?
1407 }1448 }
1408 CollectionMode::ReFungible => {1449 CollectionMode::ReFungible => Self::transfer_refungible(
1409 Self::transfer_refungible(&collection, item_id, amount, from.clone(), recipient.clone())?1450 &collection,
1410 }1451 item_id,
1452 amount,
1453 from.clone(),
1454 recipient.clone(),
1455 )?,
1411 _ => ()1456 _ => (),
1412 };1457 };
14131458
1414 if matches!(collection.mode, CollectionMode::Fungible(_)) {1459 if matches!(collection.mode, CollectionMode::Fungible(_)) {
1415 collection.log(ERC20Events::Approval {1460 collection.log(ERC20Events::Approval {
1416 owner: *from.as_eth(),1461 owner: *from.as_eth(),
1417 spender: *sender.as_eth(),1462 spender: *sender.as_eth(),
1418 value: allowance.into()1463 value: allowance.into(),
1419 });1464 });
1420 }1465 }
14211466
1440 match collection.mode1490 match collection.mode {
1441 {
1442 CollectionMode::NFT => Self::set_nft_variable_data(&collection, item_id, data)?,1491 CollectionMode::NFT => Self::set_nft_variable_data(&collection, item_id, data)?,
1443 CollectionMode::ReFungible => Self::set_re_fungible_variable_data(&collection, item_id, data)?,1492 CollectionMode::ReFungible => {
1493 Self::set_re_fungible_variable_data(&collection, item_id, data)?
1494 }
1444 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),1495 CollectionMode::Fungible(_) => fail!(Error::<T>::CantStoreMetadataInFungibleTokens),
1445 _ => fail!(Error::<T>::UnexpectedCollectionType)1496 _ => fail!(Error::<T>::UnexpectedCollectionType),
1446 };1497 };
14471498
1448 Ok(())1499 Ok(())
1489 {
1490 CollectionMode::NFT => Self::burn_nft_item(&collection, item_id)?,1543 CollectionMode::NFT => Self::burn_nft_item(&collection, item_id)?,
1491 CollectionMode::Fungible(_) => Self::burn_fungible_item(&sender, &collection, value)?,1544 CollectionMode::Fungible(_) => Self::burn_fungible_item(&sender, &collection, value)?,
1492 CollectionMode::ReFungible => Self::burn_refungible_item(&collection, item_id, &sender)?,1545 CollectionMode::ReFungible => {
1546 Self::burn_refungible_item(&collection, item_id, &sender)?
1547 }
1493 _ => ()1548 _ => (),
1494 };1549 };
14951550
1496 Ok(())1551 Ok(())
1611 );
15381612
1539 if !Self::is_owner_or_admin_permissions(collection, &sender) {1613 if !Self::is_owner_or_admin_permissions(collection, &sender) {
1540 ensure!(collection.mint_mode == true, Error::<T>::PublicMintingNotAllowed);1614 ensure!(collection.mint_mode, Error::<T>::PublicMintingNotAllowed);
1541 Self::check_white_list(collection, owner)?;1615 Self::check_white_list(collection, owner)?;
1542 Self::check_white_list(collection, sender)?;1616 Self::check_white_list(collection, sender)?;
1543 }1617 }
1556 } else {1638 } else {
1557 fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);1639 fail!(Error::<T>::NotNftDataUsedToMintNftCollectionToken);
1558 }1640 }
1559 },1641 }
1560 CollectionMode::Fungible(_) => {1642 CollectionMode::Fungible(_) => {
1561 if let CreateItemData::Fungible(_) = data {1643 if let CreateItemData::Fungible(_) = data {
1562 } else {1644 } else {
1563 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);1645 fail!(Error::<T>::NotFungibleDataUsedToMintFungibleCollectionToken);
1564 }1646 }
1565 },1647 }
1566 CollectionMode::ReFungible => {1648 CollectionMode::ReFungible => {
1567 if let CreateItemData::ReFungible(data) = data {1649 if let CreateItemData::ReFungible(data) = data {
1568
1576 } else {1666 } else {
1577 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);1667 fail!(Error::<T>::NotReFungibleDataUsedToMintReFungibleCollectionToken);
1578 }1668 }
1579 },1669 }
1580 _ => { fail!(Error::<T>::UnexpectedCollectionType); }1670 _ => {
1671 fail!(Error::<T>::UnexpectedCollectionType);
1672 }
1590 let item = NftItemType {1685 let item = NftItemType {
1591 owner: owner.clone(),1686 owner: owner.clone(),
1592 const_data: data.const_data,1687 const_data: data.const_data,
1593 variable_data: data.variable_data1688 variable_data: data.variable_data,
1594 };1689 };
15951690
1596 Self::add_nft_item(collection, item)?;1691 Self::add_nft_item(collection, item)?;
1597 },1692 }
1598 CreateItemData::Fungible(data) => {1693 CreateItemData::Fungible(data) => {
1599 Self::add_fungible_item(collection, &owner, data.value)?;1694 Self::add_fungible_item(collection, &owner, data.value)?;
1600 },1695 }
1601 CreateItemData::ReFungible(data) => {1696 CreateItemData::ReFungible(data) => {
1602 let mut owner_list = Vec::new();
1603 owner_list.push(Ownership {owner: owner.clone(), fraction: data.pieces});1697 let owner_list = vec![Ownership {
1698 owner: owner.clone(),
1699 fraction: data.pieces,
1700 }];
16041701
1605 let item = ReFungibleItemType {1702 let item = ReFungibleItemType {
1606 owner: owner_list,1703 owner: owner_list,
1607 const_data: data.const_data,1704 const_data: data.const_data,
1608 variable_data: data.variable_data1705 variable_data: data.variable_data,
1609 };1706 };
16101707
1611 Self::add_refungible_item(collection, item)?;1708 Self::add_refungible_item(collection, item)?;
1621 // Does new owner already have an account?1722 // Does new owner already have an account?
1622 let balance: u128 = <FungibleItemList<T>>::get(collection_id, owner.as_sub()).value;1723 let balance: u128 = <FungibleItemList<T>>::get(collection_id, owner.as_sub()).value;
16231724
1624 // Mint 1725 // Mint
1625 let item = FungibleItemType {1726 let item = FungibleItemType {
1626 value: balance.checked_add(value).ok_or(Error::<T>::NumOverflow)?,1727 value: balance.checked_add(value).ok_or(Error::<T>::NumOverflow)?,
1627 };1728 };
17981909
1799 pub fn submit_logs(collection: CollectionHandle<T>) -> DispatchResult {1910 pub fn submit_logs(collection: CollectionHandle<T>) -> DispatchResult {
1800 if collection.logs.is_empty() {1911 if collection.logs.is_empty() {
1801 return Ok(())1912 return Ok(());
1802 }1913 }
1803 T::EthereumTransactionSender::submit_logs_transaction(1914 T::EthereumTransactionSender::submit_logs_transaction(
1804 eth::generate_transaction(collection.id, T::EthereumChainId::get()),1915 eth::generate_transaction(collection.id, T::EthereumChainId::get()),
1836 let collection_id = target_collection.id;1957 let collection_id = target_collection.id;
18371958
1838 match target_collection.mode {1959 match target_collection.mode {
1839 CollectionMode::NFT => (<NftItemList<T>>::get(collection_id, item_id)?.owner == *subject)1960 CollectionMode::NFT => {
1840 .then(|| 1),1961 (<NftItemList<T>>::get(collection_id, item_id)?.owner == *subject).then(|| 1)
1962 }
1841 CollectionMode::Fungible(_) => Some(<FungibleItemList<T>>::get(collection_id, &subject.as_sub())1963 CollectionMode::Fungible(_) => {
1842 .value),1964 Some(<FungibleItemList<T>>::get(collection_id, &subject.as_sub()).value)
1965 }
1843 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)?1966 CollectionMode::ReFungible => <ReFungibleItemList<T>>::get(collection_id, item_id)?
1844 .owner1967 .owner
1845 .iter()1968 .iter()
1865 Ok(())1998 Ok(())
1866 }1999 }
18672000
1868 /// Check if token exists. In case of Fungible, check if there is an entry for 2001 /// Check if token exists. In case of Fungible, check if there is an entry for
1869 /// the owner in fungible balances double map2002 /// the owner in fungible balances double map
1870 fn token_exists(2003 fn token_exists(target_collection: &CollectionHandle<T>, item_id: TokenId) -> DispatchResult {
1871 target_collection: &CollectionHandle<T>,
1872 item_id: TokenId,
1873 ) -> DispatchResult {
1874 let collection_id = target_collection.id;2004 let collection_id = target_collection.id;
1875 let exists = match target_collection.mode2005 let exists = match target_collection.mode {
1876 {
1877 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),2006 CollectionMode::NFT => <NftItemList<T>>::contains_key(collection_id, item_id),
1878 CollectionMode::Fungible(_) => true,2007 CollectionMode::Fungible(_) => true,
1879 CollectionMode::ReFungible => <ReFungibleItemList<T>>::contains_key(collection_id, item_id),2008 CollectionMode::ReFungible => {
2009 <ReFungibleItemList<T>>::contains_key(collection_id, item_id)
2010 }
1880 _ => false2011 _ => false,
1881 };2012 };
18822013
1883 ensure!(exists == true, Error::<T>::TokenNotFound);2014 ensure!(exists, Error::<T>::TokenNotFound);
1884 Ok(())2015 Ok(())
1885 }2016 }
18862017
1934 let item = full_item2070 let item = full_item
1935 .owner2071 .owner
1936 .iter()2072 .iter()
1937 .filter(|i| i.owner == owner)2073 .find(|i| i.owner == owner)
1938 .next()
1939 .ok_or(Error::<T>::TokenNotFound)?;2074 .ok_or(Error::<T>::TokenNotFound)?;
1940 let amount = item.fraction;2075 let amount = item.fraction;
19412076
1955 let old_owner = item.owner.clone();2090 let old_owner = item.owner.clone();
1956 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);2091 let new_owner_has_account = full_item.owner.iter().any(|i| i.owner == new_owner);
19572092
2093 let mut new_full_item = full_item.clone();
1958 // transfer2094 // transfer
1959 if amount == value && !new_owner_has_account {2095 if amount == value && !new_owner_has_account {
1960 // change owner2096 // change owner
1961 // new owner do not have account2097 // new owner do not have account
1962 let mut new_full_item = full_item.clone();
1963 new_full_item2098 new_full_item
1964 .owner2099 .owner
1965 .iter_mut()2100 .iter_mut()
1971 // update index collection2106 // update index collection
1972 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;2107 Self::move_token_index(collection_id, item_id, &old_owner, &new_owner)?;
1973 } else {2108 } else {
1974 let mut new_full_item = full_item.clone();
1975 new_full_item2109 new_full_item
1976 .owner2110 .owner
1977 .iter_mut()2111 .iter_mut()
2185 let item_contains = list.contains(&item_index.clone());2333 let item_contains = list.contains(&item_index.clone());
21862334
2187 if !item_contains {2335 if !item_contains {
2188 list.push(item_index.clone());2336 list.push(item_index);
2189 }2337 }
21902338
2191 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);2339 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), list);
2192 } else {2340 } else {
2193 let mut itm = Vec::new();2341 let itm = vec![item_index];
2194 itm.push(item_index.clone());
2195 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);2342 <AddressTokens<T>>::insert(collection_id, owner.as_sub(), itm);
2196 }2343 }
21972344
modifiedpallets/nft/src/mock.rsdiffbeforeafterboth
1#![allow(clippy::from_over_into)]
2
1use crate as pallet_template;3use crate as pallet_template;
2use sp_core::H256;4use sp_core::H256;
3use frame_support::{ 5use frame_support::{parameter_types, weights::IdentityFee};
4 parameter_types,
5 weights::IdentityFee,
6};
7use sp_runtime::{6use sp_runtime::{
8 traits::{BlakeTwo256, IdentityLookup}, 7 traits::{BlakeTwo256, IdentityLookup},
144143
145pub struct TestEvmAddressMapping;144pub struct TestEvmAddressMapping;
146impl AddressMapping<u64> for TestEvmAddressMapping {145impl AddressMapping<u64> for TestEvmAddressMapping {
147 fn into_account_id(addr: sp_core::H160) -> u64 {146 fn into_account_id(_addr: sp_core::H160) -> u64 {
148 unimplemented!()147 unimplemented!()
149 }148 }
150}149}
151150
152pub struct TestEvmBackwardsAddressMapping;151pub struct TestEvmBackwardsAddressMapping;
153impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {152impl EvmBackwardsAddressMapping<u64> for TestEvmBackwardsAddressMapping {
154 fn from_account_id(account_id: u64) -> sp_core::H160 {153 fn from_account_id(_account_id: u64) -> sp_core::H160 {
155 unimplemented!()154 unimplemented!()
156 }155 }
157}156}
167 fn as_sub(&self) -> &u64 {166 fn as_sub(&self) -> &u64 {
168 &self.0167 &self.0
169 }168 }
170 fn from_eth(eth: sp_core::H160) -> Self {169 fn from_eth(_eth: sp_core::H160) -> Self {
171 unimplemented!()170 unimplemented!()
172 }171 }
173 fn as_eth(&self) -> &sp_core::H160 {172 fn as_eth(&self) -> &sp_core::H160 {
177176
178pub struct TestEtheremTransactionSender;177pub struct TestEtheremTransactionSender;
179impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {178impl pallet_ethereum::EthereumTransactionSender for TestEtheremTransactionSender {
180 fn submit_logs_transaction(tx: pallet_ethereum::Transaction, logs: Vec<pallet_ethereum::Log>) -> Result<(), sp_runtime::DispatchError> {179 fn submit_logs_transaction(
180 _tx: pallet_ethereum::Transaction,
181 _logs: Vec<pallet_ethereum::Log>,
182 ) -> Result<(), sp_runtime::DispatchError> {
181 Ok(())183 Ok(())
182 }184 }
modifiedpallets/nft/src/sponsorship.rsdiffbeforeafterboth
1use crate::{Config, Call, CollectionById, CreateItemBasket, VariableMetaDataBasket, ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket, ChainLimit, CreateItemData, CollectionMode};1use crate::{
2 Config, Call, CollectionById, CreateItemBasket, VariableMetaDataBasket,
3 ReFungibleTransferBasket, FungibleTransferBasket, NftTransferBasket, ChainLimit,
4 CreateItemData, CollectionMode,
5};
2use core::marker::PhantomData;6use core::marker::PhantomData;
3use up_sponsorship::SponsorshipHandler;7use up_sponsorship::SponsorshipHandler;
4use frame_support::{8use frame_support::{
5 traits::IsSubType,9 traits::IsSubType,
6 storage::{StorageMap, StorageDoubleMap, StorageValue},10 storage::{StorageMap, StorageDoubleMap, StorageValue},
7};11};
8use nft_data_structs::{TokenId, CollectionId};12use nft_data_structs::{TokenId, CollectionId};
9use alloc::vec::Vec;
1013
11pub struct NftSponsorshipHandler<T>(PhantomData<T>);14pub struct NftSponsorshipHandler<T>(PhantomData<T>);
12impl<T: Config> NftSponsorshipHandler<T> {15impl<T: Config> NftSponsorshipHandler<T> {
32 CreateItemBasket::<T>::insert((collection_id, who.clone()), block_number);34 CreateItemBasket::<T>::insert((collection_id, who.clone()), block_number);
3335
34 // check free create limit36 // check free create limit
35 if collection.limits.sponsored_data_size >= (_properties.len() as u32) {37 if collection.limits.sponsored_data_size >= (_properties.data_size() as u32) {
36 collection.sponsorship.sponsor()38 collection.sponsorship.sponsor().cloned()
37 .cloned()
38 } else {39 } else {
128125
129 sponsored126 sponsored
130 }127 }
131 _ => {128 _ => false,
132 false
133 },
134 };129 };
135 }130 }
136131
145 pub fn withdraw_set_variable_meta_data(139 pub fn withdraw_set_variable_meta_data(
146 collection_id: &CollectionId,140 collection_id: &CollectionId,
147 item_id: &TokenId,141 item_id: &TokenId,
148 data: &Vec<u8>,142 data: &[u8],
149 ) -> Option<T::AccountId> {143 ) -> Option<T::AccountId> {
150
151 let mut sponsor_metadata_changes = false;144 let mut sponsor_metadata_changes = false;
184impl<T, C> SponsorshipHandler<T::AccountId, C> for NftSponsorshipHandler<T>175impl<T, C> SponsorshipHandler<T::AccountId, C> for NftSponsorshipHandler<T>
185where 176where
186 T: Config,177 T: Config,
187 C: IsSubType<Call<T>>178 C: IsSubType<Call<T>>,
188{179{
189 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {180 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {
190 match IsSubType::<Call<T>>::is_sub_type(call)? {181 match IsSubType::<Call<T>>::is_sub_type(call)? {
191 Call::create_item(collection_id, _owner, _properties) => {182 Call::create_item(collection_id, _owner, _properties) => {
192 Self::withdraw_create_item(who, collection_id, &_properties)183 Self::withdraw_create_item(who, collection_id, &_properties)
193 },184 }
194 Call::transfer(_new_owner, collection_id, item_id, _value) => {185 Call::transfer(_new_owner, collection_id, item_id, _value) => {
195 Self::withdraw_transfer(who, collection_id, item_id)186 Self::withdraw_transfer(who, collection_id, item_id)
196 },187 }
197 Call::set_variable_meta_data(collection_id, item_id, data) => {188 Call::set_variable_meta_data(collection_id, item_id, data) => {
198 Self::withdraw_set_variable_meta_data(collection_id, item_id, &data)189 Self::withdraw_set_variable_meta_data(collection_id, item_id, &data)
199 },190 }
200 _ => None,191 _ => None,
201 }192 }
202 }193 }
modifiedpallets/nft/src/tests.rsdiffbeforeafterboth
3use crate::mock::*;3use crate::mock::*;
4use crate::{4use crate::{AccessMode, CollectionMode, Ownership, ChainLimits, CreateItemData};
5 AccessMode, CollectionMode,
6 Ownership, ChainLimits, CreateItemData,
7};
8use nft_data_structs::{5use nft_data_structs::{
9 CreateNftData, CreateFungibleData, CreateReFungibleData,6 CreateNftData, CreateFungibleData, CreateReFungibleData, CollectionId, TokenId,
34fn default_nft_data() -> CreateNftData {34fn default_nft_data() -> CreateNftData {
35 CreateNftData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1] }35 CreateNftData {
36 const_data: vec![1, 2, 3],
37 variable_data: vec![3, 2, 1],
38 }
36}39}
3740
38fn default_fungible_data () -> CreateFungibleData {41fn default_fungible_data() -> CreateFungibleData {
39 CreateFungibleData { value: 5 }42 CreateFungibleData { value: 5 }
40}43}
4144
42fn default_re_fungible_data () -> CreateReFungibleData {45fn default_re_fungible_data() -> CreateReFungibleData {
43 CreateReFungibleData { const_data: vec![1, 2, 3], variable_data: vec![3, 2, 1], pieces: 1023 }46 CreateReFungibleData {
47 const_data: vec![1, 2, 3],
48 variable_data: vec![3, 2, 1],
49 pieces: 1023,
50 }
44}51}
4552
5061
51 let origin1 = Origin::signed(owner);62 let origin1 = Origin::signed(owner);
52 assert_ok!(TemplateModule::create_collection(63 assert_ok!(TemplateModule::create_collection(
53 origin1.clone(),64 origin1,
54 col_name1.clone(),65 col_name1,
55 col_desc1.clone(),66 col_desc1,
56 token_prefix1.clone(),67 token_prefix1,
57 mode.clone()68 mode.clone()
58 ));69 ));
5970
75fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {95fn create_test_item(collection_id: CollectionId, data: &CreateItemData) {
76 let origin1 = Origin::signed(1);96 let origin1 = Origin::signed(1);
77 assert_ok!(TemplateModule::create_item(97 assert_ok!(TemplateModule::create_item(
78 origin1.clone(),98 origin1,
79 collection_id,99 collection_id,
80 account(1),100 account(1),
81 data.clone()101 data.clone()
150 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];181 let items_data = vec![default_nft_data(), default_nft_data(), default_nft_data()];
151182
152 assert_ok!(TemplateModule::create_multiple_items(183 assert_ok!(TemplateModule::create_multiple_items(
153 origin1.clone(),184 origin1,
154 1,185 1,
155 account(1),186 account(1),
156 items_data.clone().into_iter().map(|d| { d.into() }).collect()187 items_data
235 ];
203236
204 assert_ok!(TemplateModule::create_multiple_items(237 assert_ok!(TemplateModule::create_multiple_items(
205 origin1.clone(),238 origin1,
206 1,239 1,
207 account(1),240 account(1),
208 items_data.clone().into_iter().map(|d| { d.into() }).collect()241 items_data
280 assert_eq!(TemplateModule::balance_count(1, 1), 5);316 assert_eq!(TemplateModule::balance_count(1, 1), 5);
281317
282 // change owner scenario318 // change owner scenario
283 assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 5));319 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 5));
284 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);320 assert_eq!(TemplateModule::fungible_item_id(1, 1).value, 0);
285 assert_eq!(TemplateModule::balance_count(1, 1), 0);321 assert_eq!(TemplateModule::balance_count(1, 1), 0);
286 assert_eq!(TemplateModule::balance_count(1, 2), 5);322 assert_eq!(TemplateModule::balance_count(1, 2), 5);
291 assert_eq!(TemplateModule::balance_count(1, 3), 3);333 assert_eq!(TemplateModule::balance_count(1, 3), 3);
292334
293 // split item and new owner has account scenario335 // split item and new owner has account scenario
294 assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 1));336 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 1));
295 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);337 assert_eq!(TemplateModule::fungible_item_id(1, 2).value, 1);
296 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);338 assert_eq!(TemplateModule::fungible_item_id(1, 3).value, 4);
297 assert_eq!(TemplateModule::balance_count(1, 2), 1);339 assert_eq!(TemplateModule::balance_count(1, 2), 1);
333 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);369 assert_eq!(TemplateModule::address_tokens(1, 1), [1]);
334370
335 // change owner scenario371 // change owner scenario
336 assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1023));372 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1023));
337 assert_eq!(373 assert_eq!(
338 TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],374 TemplateModule::refungible_item_id(1, 1).unwrap().owner[0],
339 Ownership {375 Ownership {
371 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);413 assert_eq!(TemplateModule::address_tokens(1, 3), [1]);
372414
373 // split item and new owner has account scenario415 // split item and new owner has account scenario
374 assert_ok!(TemplateModule::transfer(origin2.clone(), account(3), 1, 1, 200));416 assert_ok!(TemplateModule::transfer(origin2, account(3), 1, 1, 200));
375 {417 {
376 let item = TemplateModule::refungible_item_id(1, 1).unwrap();418 let item = TemplateModule::refungible_item_id(1, 1).unwrap();
377 assert_eq!(419 assert_eq!(
410452
411 let origin1 = Origin::signed(1);453 let origin1 = Origin::signed(1);
412 // default scenario454 // default scenario
413 assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1000));455 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1000));
414 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));456 assert_eq!(TemplateModule::nft_item_id(1, 1).unwrap().owner, account(2));
415 assert_eq!(TemplateModule::balance_count(1, 1), 0);457 assert_eq!(TemplateModule::balance_count(1, 1), 0);
416 assert_eq!(TemplateModule::balance_count(1, 2), 1);458 assert_eq!(TemplateModule::balance_count(1, 2), 1);
484 );
446485
447 // do approve486 // do approve
448 assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 5));487 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 5));
449 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);488 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
450 assert_eq!(489 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
451 TemplateModule::approved(1, (1, 1, 2)),
452 5
453 );
454490
455 assert_ok!(TemplateModule::transfer_from(491 assert_ok!(TemplateModule::transfer_from(
456 origin2.clone(),492 origin2,
457 account(1),493 account(1),
458 account(3),494 account(3),
459 1,495 1,
555 5
556 ));
500 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);557 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
501 assert_ok!(TemplateModule::approve(origin1.clone(), account(3), 1, 1, 5));558 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
502 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);559 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
503560
504 assert_ok!(TemplateModule::transfer_from(561 assert_ok!(TemplateModule::transfer_from(
505 origin2.clone(),562 origin2,
506 account(1),563 account(1),
507 account(3),564 account(3),
508 1,565 1,
613 ));
545614
546 // do approve615 // do approve
547 assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 1023));616 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1023));
548 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);617 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1023);
549618
550 assert_ok!(TemplateModule::transfer_from(619 assert_ok!(TemplateModule::transfer_from(
551 origin2.clone(),620 origin2,
552 account(1),621 account(1),
553 account(3),622 account(3),
554 1,623 1,
683 5
684 ));
601 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);685 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
602 assert_ok!(TemplateModule::approve(origin1.clone(), account(3), 1, 1, 5));686 assert_ok!(TemplateModule::approve(origin1, account(3), 1, 1, 5));
603 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);687 assert_eq!(TemplateModule::approved(1, (1, 1, 3)), 5);
604 assert_eq!(688 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 5);
605 TemplateModule::approved(1, (1, 1, 2)),
620 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);701 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
621702
622 assert_noop!(TemplateModule::transfer_from(703 assert_noop!(
623 origin2.clone(),704 TemplateModule::transfer_from(origin2, account(1), account(3), 1, 1, 4),
624 account(1),
625 account(3),
626 1,
639 716
640 let origin1 = Origin::signed(1);717 let origin1 = Origin::signed(1);
641 assert_ok!(TemplateModule::change_collection_owner(718 assert_ok!(TemplateModule::change_collection_owner(
642 origin1.clone(),719 origin1,
643 collection_id,720 collection_id,
644 2721 2
645 ));722 ));
655 let collection_id = create_test_collection(&CollectionMode::NFT, 1);735 let collection_id = create_test_collection(&CollectionMode::NFT, 1);
656 736
657 let origin1 = Origin::signed(1);737 let origin1 = Origin::signed(1);
658 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));738 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
659 });739 });
660}740}
661741
678 // burn item762 // burn item
679 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));763 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
680 assert_noop!(764 assert_noop!(
681 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),765 TemplateModule::burn_item(origin1, 1, 1, 5),
682 Error::<Test>::TokenNotFound766 Error::<Test>::TokenNotFound
683 );767 );
684768
705 // burn item793 // burn item
706 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));794 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 5));
707 assert_noop!(795 assert_noop!(
708 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),796 TemplateModule::burn_item(origin1, 1, 1, 5),
709 Error::<Test>::TokenValueNotEnough797 Error::<Test>::TokenValueNotEnough
710 );798 );
711799
744 // burn item840 // burn item
745 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));841 assert_ok!(TemplateModule::burn_item(origin1.clone(), 1, 1, 1023));
746 assert_noop!(842 assert_noop!(
747 TemplateModule::burn_item(origin1.clone(), 1, 1, 1023),843 TemplateModule::burn_item(origin1, 1, 1, 1023),
748 Error::<Test>::TokenNotFound844 Error::<Test>::TokenNotFound
749 );845 );
750846
865 collection1_id,
866 account(2)
867 ));
768 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(3)));868 assert_ok!(TemplateModule::add_collection_admin(
869 origin1,
870 collection1_id,
871 account(3)
872 ));
769873
770 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)), true);874 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(2)),);
771 assert_eq!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)), true);875 assert!(TemplateModule::admin_list_collection(collection1_id).contains(&account(3)),);
772 });876 });
773}877}
774878
894 collection1_id,
895 account(2)
896 ));
789 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection1_id, account(3)));897 assert_ok!(TemplateModule::add_collection_admin(
898 origin1,
899 collection1_id,
900 account(3)
901 ));
790902
791 assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(2)), true);903 assert!(TemplateModule::admin_list_collection(1).contains(&account(2)),);
792 assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(3)), true);904 assert!(TemplateModule::admin_list_collection(1).contains(&account(3)),);
793905
794 // remove admin906 // remove admin
795 assert_ok!(TemplateModule::remove_collection_admin(907 assert_ok!(TemplateModule::remove_collection_admin(
796 origin2.clone(),908 origin2,
797 1,909 1,
798 account(3)910 account(3)
799 ));911 ));
800 assert_eq!(TemplateModule::admin_list_collection(1).contains(&account(3)), false);912 assert!(!TemplateModule::admin_list_collection(1).contains(&account(3)),);
801 });913 });
802}914}
803915
847 let origin1 = Origin::signed(1);979 let origin1 = Origin::signed(1);
848 980
849 // approve981 // approve
850 assert_ok!(TemplateModule::approve(origin1.clone(), account(2), 1, 1, 1));982 assert_ok!(TemplateModule::approve(origin1, account(2), 1, 1, 1));
851 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);983 assert_eq!(TemplateModule::approved(1, (1, 1, 2)), 1);
852 });984 });
853}985}
1026 1,
1027 account(2)
1028 ));
883 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), 1, account(3)));1029 assert_ok!(TemplateModule::add_to_white_list(origin1, 1, account(3)));
8841030
885 assert_ok!(TemplateModule::transfer_from(1031 assert_ok!(TemplateModule::transfer_from(
886 origin2.clone(),1032 origin2,
887 account(1),1033 account(1),
888 account(2),1034 account(2),
889 1,1035 1,
910 let collection_id = create_test_collection(&CollectionMode::NFT, 1);1056 let collection_id = create_test_collection(&CollectionMode::NFT, 1);
9111057
912 let origin1 = Origin::signed(1);1058 let origin1 = Origin::signed(1);
913 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1059 assert_ok!(TemplateModule::add_to_white_list(
1060 origin1,
1061 collection_id,
1062 account(2)
1063 ));
914 assert_eq!(TemplateModule::white_list(collection_id, 2), true);1064 assert!(TemplateModule::white_list(collection_id, 2));
915 });1065 });
916}1066}
9171067
924 let origin1 = Origin::signed(1);1074 let origin1 = Origin::signed(1);
925 let origin2 = Origin::signed(2);1075 let origin2 = Origin::signed(2);
9261076
927 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));1077 assert_ok!(TemplateModule::add_collection_admin(
1078 origin1,
1079 collection_id,
1080 account(2)
1081 ));
928 assert_ok!(TemplateModule::add_to_white_list(origin2.clone(), collection_id, account(3)));1082 assert_ok!(TemplateModule::add_to_white_list(
1083 origin2,
1084 collection_id,
1085 account(3)
1086 ));
929 assert_eq!(TemplateModule::white_list(collection_id, 3), true);1087 assert!(TemplateModule::white_list(collection_id, 3));
930 });1088 });
931}1089}
9321090
9391097
940 let origin2 = Origin::signed(2);1098 let origin2 = Origin::signed(2);
941 assert_noop!(1099 assert_noop!(
942 TemplateModule::add_to_white_list(origin2.clone(), collection_id, account(3)),1100 TemplateModule::add_to_white_list(origin2, collection_id, account(3)),
943 Error::<Test>::NoPermission1101 Error::<Test>::NoPermission
944 );1102 );
945 });1103 });
953 let origin1 = Origin::signed(1);1111 let origin1 = Origin::signed(1);
9541112
955 assert_noop!(1113 assert_noop!(
956 TemplateModule::add_to_white_list(origin1.clone(), 1, account(2)),1114 TemplateModule::add_to_white_list(origin1, 1, account(2)),
957 Error::<Test>::CollectionNotFound1115 Error::<Test>::CollectionNotFound
958 );1116 );
959 });1117 });
1130 collection_id
1131 ));
971 assert_noop!(1132 assert_noop!(
972 TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)),1133 TemplateModule::add_to_white_list(origin1, collection_id, account(2)),
973 Error::<Test>::CollectionNotFound1134 Error::<Test>::CollectionNotFound
974 );1135 );
975 });1136 });
1150 collection_id,
1151 account(2)
1152 ));
988 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1153 assert_ok!(TemplateModule::add_to_white_list(
1154 origin1,
1155 collection_id,
1156 account(2)
1157 ));
989 assert_eq!(TemplateModule::white_list(collection_id, 2), true);1158 assert!(TemplateModule::white_list(collection_id, 2));
990 });1159 });
991}1160}
9921161
1173 account(2)
1174 ));
1002 assert_ok!(TemplateModule::remove_from_white_list(1175 assert_ok!(TemplateModule::remove_from_white_list(
1003 origin1.clone(),1176 origin1,
1004 collection_id,1177 collection_id,
1005 account(2)1178 account(2)
1006 ));1179 ));
1007 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1180 assert!(!TemplateModule::white_list(collection_id, 2));
1008 });1181 });
1009}1182}
10101183
1196 account(2)
1197 ));
10211198
1022 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(3)));1199 assert_ok!(TemplateModule::add_to_white_list(
1200 origin1,
1201 collection_id,
1202 account(3)
1203 ));
1023 assert_ok!(TemplateModule::remove_from_white_list(1204 assert_ok!(TemplateModule::remove_from_white_list(
1024 origin2.clone(),1205 origin2,
1025 collection_id,1206 collection_id,
1026 account(3)1207 account(3)
1027 ));1208 ));
1028 assert_eq!(TemplateModule::white_list(collection_id, 3), false);1209 assert!(!TemplateModule::white_list(collection_id, 3));
1029 });1210 });
1030}1211}
10311212
1038 let origin1 = Origin::signed(1);1219 let origin1 = Origin::signed(1);
1039 let origin2 = Origin::signed(2);1220 let origin2 = Origin::signed(2);
10401221
1041 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1222 assert_ok!(TemplateModule::add_to_white_list(
1223 origin1,
1224 collection_id,
1225 account(2)
1226 ));
1042 assert_noop!(1227 assert_noop!(
1043 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, account(2)),1228 TemplateModule::remove_from_white_list(origin2, collection_id, account(2)),
1044 Error::<Test>::NoPermission1229 Error::<Test>::NoPermission
1045 );1230 );
1046 assert_eq!(TemplateModule::white_list(collection_id, 2), true);1231 assert!(TemplateModule::white_list(collection_id, 2));
1047 });1232 });
1048}1233}
10491234
1054 let origin1 = Origin::signed(1);1239 let origin1 = Origin::signed(1);
10551240
1056 assert_noop!(1241 assert_noop!(
1057 TemplateModule::remove_from_white_list(origin1.clone(), 1, account(2)),1242 TemplateModule::remove_from_white_list(origin1, 1, account(2)),
1058 Error::<Test>::CollectionNotFound1243 Error::<Test>::CollectionNotFound
1059 );1244 );
1060 });1245 });
1259 collection_id,
1260 account(2)
1261 ));
1073 assert_ok!(TemplateModule::destroy_collection(origin1.clone(), collection_id));1262 assert_ok!(TemplateModule::destroy_collection(origin1, collection_id));
1074 assert_noop!(1263 assert_noop!(
1075 TemplateModule::remove_from_white_list(origin2.clone(), collection_id, account(2)),1264 TemplateModule::remove_from_white_list(origin2, collection_id, account(2)),
1076 Error::<Test>::CollectionNotFound1265 Error::<Test>::CollectionNotFound
1077 );1266 );
1078 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1267 assert!(!TemplateModule::white_list(collection_id, 2));
1079 });1268 });
1080}1269}
10811270
1095 account(2)1288 account(2)
1096 ));1289 ));
1097 assert_ok!(TemplateModule::remove_from_white_list(1290 assert_ok!(TemplateModule::remove_from_white_list(
1098 origin1.clone(),1291 origin1,
1099 collection_id,1292 collection_id,
1100 account(2)1293 account(2)
1101 ));1294 ));
1102 assert_eq!(TemplateModule::white_list(collection_id, 2), false);1295 assert!(!TemplateModule::white_list(collection_id, 2));
1103 });1296 });
1104}1297}
11051298
1321 ));
11251322
1126 assert_noop!(1323 assert_noop!(
1127 TemplateModule::transfer(origin1.clone(), account(3), 1, 1, 1),1324 TemplateModule::transfer(origin1, account(3), 1, 1, 1),
1128 Error::<Test>::AddresNotInWhiteList1325 Error::<Test>::AddresNotInWhiteList
1129 );1326 );
1130 });1327 });
1160 ));1371 ));
11611372
1162 assert_noop!(1373 assert_noop!(
1163 TemplateModule::transfer_from(origin1.clone(), account(1), account(3), 1, 1, 1),1374 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
1164 Error::<Test>::AddresNotInWhiteList1375 Error::<Test>::AddresNotInWhiteList
1165 );1376 );
1166 });1377 });
1402 ));
11881403
1189 assert_noop!(1404 assert_noop!(
1190 TemplateModule::transfer(origin1.clone(), account(3), 1, 1, 1),1405 TemplateModule::transfer(origin1, account(3), 1, 1, 1),
1191 Error::<Test>::AddresNotInWhiteList1406 Error::<Test>::AddresNotInWhiteList
1192 );1407 );
1193 });1408 });
1224 ));1453 ));
12251454
1226 assert_noop!(1455 assert_noop!(
1227 TemplateModule::transfer_from(origin1.clone(), account(1), account(3), 1, 1, 1),1456 TemplateModule::transfer_from(origin1, account(1), account(3), 1, 1, 1),
1228 Error::<Test>::AddresNotInWhiteList1457 Error::<Test>::AddresNotInWhiteList
1229 );1458 );
1230 });1459 });
1249 AccessMode::WhiteList1478 AccessMode::WhiteList
1250 ));1479 ));
1251 assert_noop!(1480 assert_noop!(
1252 TemplateModule::burn_item(origin1.clone(), 1, 1, 5),1481 TemplateModule::burn_item(origin1, 1, 1, 5),
1253 Error::<Test>::AddresNotInWhiteList1482 Error::<Test>::AddresNotInWhiteList
1254 );1483 );
1255 });1484 });
12761505
1277 // do approve1506 // do approve
1278 assert_noop!(1507 assert_noop!(
1279 TemplateModule::approve(origin1.clone(), account(1), 1, 1, 5),1508 TemplateModule::approve(origin1, account(1), 1, 1, 5),
1280 Error::<Test>::AddresNotInWhiteList1509 Error::<Test>::AddresNotInWhiteList
1281 );1510 );
1282 });1511 });
1541 account(2)
1542 ));
13061543
1307 assert_ok!(TemplateModule::transfer(origin1.clone(), account(2), 1, 1, 1));1544 assert_ok!(TemplateModule::transfer(origin1, account(2), 1, 1, 1));
1308 });1545 });
1309}1546}
13101547
1333 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);1584 assert_eq!(TemplateModule::approved(1, (1, 1, 1)), 5);
13341585
1335 assert_ok!(TemplateModule::transfer_from(1586 assert_ok!(TemplateModule::transfer_from(
1336 origin1.clone(),1587 origin1,
1337 account(1),1588 account(1),
1338 account(2),1589 account(2),
1339 1,1590 1,
1358 AccessMode::WhiteList1609 AccessMode::WhiteList
1359 ));1610 ));
1360 assert_ok!(TemplateModule::set_mint_permission(1611 assert_ok!(TemplateModule::set_mint_permission(
1361 origin1.clone(),1612 origin1,
1362 collection_id,1613 collection_id,
1363 false1614 false
1364 ));1615 ));
1390 false1641 false
1391 ));1642 ));
13921643
1393 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));1644 assert_ok!(TemplateModule::add_collection_admin(
1645 origin1,
1646 collection_id,
1647 account(2)
1648 ));
13941649
1395 assert_ok!(TemplateModule::create_item(1650 assert_ok!(TemplateModule::create_item(
1396 origin2.clone(),1651 origin2,
1397 collection_id,1652 collection_id,
1398 account(2),1653 account(2),
1399 default_nft_data().into()1654 default_nft_data().into()
1422 collection_id,1677 collection_id,
1423 false1678 false
1424 ));1679 ));
1425 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1680 assert_ok!(TemplateModule::add_to_white_list(
1681 origin1,
1682 collection_id,
1683 account(2)
1684 ));
14261685
1427 assert_noop!(1686 assert_noop!(
1428 TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1687 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
1429 Error::<Test>::PublicMintingNotAllowed1688 Error::<Test>::PublicMintingNotAllowed
1430 );1689 );
1431 });1690 });
1448 AccessMode::WhiteList1707 AccessMode::WhiteList
1449 ));1708 ));
1450 assert_ok!(TemplateModule::set_mint_permission(1709 assert_ok!(TemplateModule::set_mint_permission(
1451 origin1.clone(),1710 origin1,
1452 collection_id,1711 collection_id,
1453 false1712 false
1454 ));1713 ));
14551714
1456 assert_noop!(1715 assert_noop!(
1457 TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1716 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
1458 Error::<Test>::PublicMintingNotAllowed1717 Error::<Test>::PublicMintingNotAllowed
1459 );1718 );
1460 });1719 });
1476 AccessMode::WhiteList1735 AccessMode::WhiteList
1477 ));1736 ));
1478 assert_ok!(TemplateModule::set_mint_permission(1737 assert_ok!(TemplateModule::set_mint_permission(
1479 origin1.clone(),1738 origin1,
1480 collection_id,1739 collection_id,
1481 true1740 true
1482 ));1741 ));
1508 true1767 true
1509 ));1768 ));
15101769
1511 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(2)));1770 assert_ok!(TemplateModule::add_collection_admin(
1771 origin1,
1772 collection_id,
1773 account(2)
1774 ));
15121775
1513 assert_ok!(TemplateModule::create_item(1776 assert_ok!(TemplateModule::create_item(
1514 origin2.clone(),1777 origin2,
1515 1,1778 1,
1516 account(2),1779 account(2),
1517 default_nft_data().into()1780 default_nft_data().into()
1536 AccessMode::WhiteList1799 AccessMode::WhiteList
1537 ));1800 ));
1538 assert_ok!(TemplateModule::set_mint_permission(1801 assert_ok!(TemplateModule::set_mint_permission(
1539 origin1.clone(),1802 origin1,
1540 collection_id,1803 collection_id,
1541 true1804 true
1542 ));1805 ));
15431806
1544 assert_noop!(1807 assert_noop!(
1545 TemplateModule::create_item(origin2.clone(), 1, account(2), default_nft_data().into()),1808 TemplateModule::create_item(origin2, 1, account(2), default_nft_data().into()),
1546 Error::<Test>::AddresNotInWhiteList1809 Error::<Test>::AddresNotInWhiteList
1547 );1810 );
1548 });1811 });
1569 collection_id,1832 collection_id,
1570 true1833 true
1571 ));1834 ));
1572 assert_ok!(TemplateModule::add_to_white_list(origin1.clone(), collection_id, account(2)));1835 assert_ok!(TemplateModule::add_to_white_list(
1836 origin1,
1837 collection_id,
1838 account(2)
1839 ));
15731840
1574 assert_ok!(TemplateModule::create_item(1841 assert_ok!(TemplateModule::create_item(
1575 origin2.clone(),1842 origin2,
1576 1,1843 1,
1577 account(2),1844 account(2),
1578 default_nft_data().into()1845 default_nft_data().into()
1609 // 11-th collection in chain. Expects error1876 // 11-th collection in chain. Expects error
1610 assert_noop!(TemplateModule::create_collection(1877 assert_noop!(
1878 TemplateModule::create_collection(
1611 origin1.clone(),1879 origin1,
1612 col_name1.clone(),1880 col_name1,
1613 col_desc1.clone(),1881 col_desc1,
1614 token_prefix1.clone(),1882 token_prefix1,
1615 CollectionMode::NFT1883 CollectionMode::NFT
1616 ), Error::<Test>::TotalCollectionsLimitExceeded);1884 ),
1885 Error::<Test>::TotalCollectionsLimitExceeded
1655 create_test_item(collection_id, &data.clone().into());1928 create_test_item(collection_id, &data.clone().into());
16561929
1657 assert_noop!(TemplateModule::create_item(1930 assert_noop!(
1658 origin1.clone(),1931 TemplateModule::create_item(origin1, 1, account(1), data.into()),
1659 1,
1660 account(1),
1661 data.into()
1963 collection_id,
1964 account(2)
1965 ));
1688 assert_ok!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(3)));1966 assert_ok!(TemplateModule::add_collection_admin(
1967 origin1,
1968 collection_id,
1969 account(3)
2000 collection_id,
2001 account(2)
2002 ));
1714 assert_noop!(TemplateModule::add_collection_admin(origin1.clone(), collection_id, account(3)), Error::<Test>::CollectionAdminsLimitExceeded);2003 assert_noop!(
2004 TemplateModule::add_collection_admin(origin1, collection_id, account(3)),
2005 Error::<Test>::CollectionAdminsLimitExceeded
2006 );
1737 let origin1 = Origin::signed(1);2032 let origin1 = Origin::signed(1);
1738 let too_big_const_data = CreateItemData::NFT(CreateNftData{2033 let too_big_const_data = CreateItemData::NFT(CreateNftData {
1739 const_data: vec![1, 2, 3, 4],2034 const_data: vec![1, 2, 3, 4],
1740 variable_data: vec![]2035 variable_data: vec![],
1741 });2036 });
17422037
1743 assert_noop!(TemplateModule::create_item(2038 assert_noop!(
1744 origin1.clone(),2039 TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
1745 collection_id,
1746 account(1),
1747 too_big_const_data
1771 let origin1 = Origin::signed(1);2067 let origin1 = Origin::signed(1);
1772 let too_big_const_data = CreateItemData::NFT(CreateNftData{2068 let too_big_const_data = CreateItemData::NFT(CreateNftData {
1773 const_data: vec![],2069 const_data: vec![],
1774 variable_data: vec![1, 2, 3, 4]2070 variable_data: vec![1, 2, 3, 4],
1775 });2071 });
17762072
1777 assert_noop!(TemplateModule::create_item(2073 assert_noop!(
1778 origin1.clone(),2074 TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
1779 collection_id,
1780 account(1),
1781 too_big_const_data
1805 let origin1 = Origin::signed(1);2102 let origin1 = Origin::signed(1);
1806 let too_big_const_data = CreateItemData::NFT(CreateNftData{2103 let too_big_const_data = CreateItemData::NFT(CreateNftData {
1807 const_data: vec![1, 2, 3, 4],2104 const_data: vec![1, 2, 3, 4],
1808 variable_data: vec![]2105 variable_data: vec![],
1809 });2106 });
18102107
1811 assert_noop!(TemplateModule::create_item(2108 assert_noop!(
1812 origin1.clone(),2109 TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
1813 collection_id,
1814 account(1),
1815 too_big_const_data
1839 let origin1 = Origin::signed(1);2137 let origin1 = Origin::signed(1);
1840 let too_big_const_data = CreateItemData::NFT(CreateNftData{2138 let too_big_const_data = CreateItemData::NFT(CreateNftData {
1841 const_data: vec![],2139 const_data: vec![],
1842 variable_data: vec![1, 2, 3, 4]2140 variable_data: vec![1, 2, 3, 4],
1843 });2141 });
18442142
1845 assert_noop!(TemplateModule::create_item(2143 assert_noop!(
1846 origin1.clone(),2144 TemplateModule::create_item(origin1, collection_id, account(1), too_big_const_data),
1847 collection_id,
1848 account(1),
1849 too_big_const_data
1934 create_test_item(1, &data.into());2277 create_test_item(1, &data.into());
19352278
1936 let variable_data = b"test set_variable_meta_data method.".to_vec();2279 let variable_data = b"test set_variable_meta_data method.".to_vec();
1937 assert_noop!(TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data.clone()), Error::<Test>::CantStoreMetadataInFungibleTokens);2280 assert_noop!(
2281 TemplateModule::set_variable_meta_data(origin1, collection_id, 1, variable_data),
2282 Error::<Test>::CantStoreMetadataInFungibleTokens
2283 );
modifiedpallets/scheduler/src/benchmarking.rsdiffbeforeafterboth

no syntactic changes

modifiedpallets/scheduler/src/lib.rsdiffbeforeafterboth
5050
51// Ensure we're `no_std` when compiling for Wasm.51// Ensure we're `no_std` when compiling for Wasm.
52#![cfg_attr(not(feature = "std"), no_std)]52#![cfg_attr(not(feature = "std"), no_std)]
53#![allow(clippy::type_complexity, clippy::boxed_local, clippy::unused_unit)]
5354
54mod benchmarking;55mod benchmarking;
55pub mod weights;56pub mod weights;
5657
57use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};58use sp_std::{prelude::*, marker::PhantomData, borrow::Borrow};
58use codec::{Encode, Decode, Codec};59use codec::{Encode, Decode, Codec};
59use sp_runtime::{RuntimeDebug, traits::{Zero, One, BadOrigin, Saturating}};60use sp_runtime::{
61 RuntimeDebug,
62 traits::{Zero, One, BadOrigin, Saturating},
63};
60use frame_support::{64use frame_support::{
61 decl_module, decl_storage, decl_event, decl_error, IterableStorageMap,65 decl_module, decl_storage, decl_event, decl_error, IterableStorageMap,
62 dispatch::{Dispatchable, DispatchError, DispatchResult, Parameter},66 dispatch::{Dispatchable, DispatchError, DispatchResult, Parameter},
63 traits::{Get, schedule::{self, DispatchTime}, OriginTrait, EnsureOrigin, IsType},67 traits::{
68 Get,
69 schedule::{self, DispatchTime},
70 OriginTrait, EnsureOrigin, IsType,
71 },
64 weights::{GetDispatchInfo, Weight},72 weights::{GetDispatchInfo, Weight},
65};73};
72/// should be added to our implied traits list.80/// should be added to our implied traits list.
73///81///
74/// `system::Config` should always be included in our implied traits.82/// `system::Config` should always be included in our implied traits.
75/// // 83/// //
76pub trait Config: system::Config84pub trait Config: system::Config {
77{
78
402 let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(412 let origin = <<T as Config>::Origin as From<T::PalletsOrigin>>::from(
403 s.origin.clone()413 s.origin.clone()
404 ).into();414 ).into();
405 let sender = ensure_signed(origin).unwrap_or(T::AccountId::default());415 let sender = ensure_signed(origin).unwrap_or_default();
406 let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &s.call).unwrap_or(sender);416 let who_will_pay = T::SponsorshipHandler::get_sponsor(&sender, &s.call).unwrap_or(sender);
407 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));417 let sponsor = T::PalletsOrigin::from(system::RawOrigin::Signed(who_will_pay));
408 let r = s.call.clone().dispatch(sponsor.into());418 let r = s.call.clone().dispatch(sponsor.into());
409 let maybe_id = s.maybe_id.clone();419 let maybe_id = s.maybe_id.clone();
410 if let &Some((period, count)) = &s.maybe_periodic {420 if let Some((period, count)) = s.maybe_periodic {
411 if count > 1 {421 if count > 1 {
412 s.maybe_periodic = Some((period, count - 1));422 s.maybe_periodic = Some((period, count - 1));
413 } else {423 } else {
420 Lookup::<T>::insert(id, (next, next_index as u32));430 Lookup::<T>::insert(id, (next, next_index as u32));
421 }431 }
422 Agenda::<T>::append(next, Some(s));432 Agenda::<T>::append(next, Some(s));
423 } else {433 } else if let Some(ref id) = s.maybe_id {
424 if let Some(ref id) = s.maybe_id {
425 Lookup::<T>::remove(id);434 Lookup::<T>::remove(id);
426 }435 }
427 }
428 Self::deposit_event(RawEvent::Dispatched(436 Self::deposit_event(RawEvent::Dispatched(
429 (now, index),437 (now, index),
430 maybe_id,438 maybe_id,
455463
456 Agenda::<T>::translate::<464 Agenda::<T>::translate::<
457 Vec<Option<ScheduledV1<<T as Config>::Call, T::BlockNumber>>>, _465 Vec<Option<ScheduledV1<<T as Config>::Call, T::BlockNumber>>>,
466 _,
458 >(|_, agenda| Some(467 >(|_, agenda| {
468 Some(
459 agenda469 agenda
460 .into_iter()470 .into_iter()
461 .map(|schedule| schedule.map(|schedule| ScheduledV2 {471 .map(|schedule| {
472 schedule.map(|schedule| ScheduledV2 {
462 maybe_id: schedule.maybe_id,473 maybe_id: schedule.maybe_id,
463 priority: schedule.priority,474 priority: schedule.priority,
466 origin: system::RawOrigin::Root.into(),477 origin: system::RawOrigin::Root.into(),
467 _phantom: Default::default(),478 _phantom: Default::default(),
468 }))479 })
480 })
469 .collect::<Vec<_>>()481 .collect::<Vec<_>>(),
470 ));482 )
483 });
471484
472 true485 true
473 } else {486 } else {
479 pub fn migrate_origin<OldOrigin: Into<T::PalletsOrigin> + codec::Decode>() {492 pub fn migrate_origin<OldOrigin: Into<T::PalletsOrigin> + codec::Decode>() {
480 Agenda::<T>::translate::<493 Agenda::<T>::translate::<
481 Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>, _494 Vec<Option<Scheduled<<T as Config>::Call, T::BlockNumber, OldOrigin, T::AccountId>>>,
495 _,
482 >(|_, agenda| Some(496 >(|_, agenda| {
497 Some(
483 agenda498 agenda
484 .into_iter()499 .into_iter()
485 .map(|schedule| schedule.map(|schedule| Scheduled {500 .map(|schedule| {
501 schedule.map(|schedule| Scheduled {
486 maybe_id: schedule.maybe_id,502 maybe_id: schedule.maybe_id,
487 priority: schedule.priority,503 priority: schedule.priority,
490 origin: schedule.origin.into(),506 origin: schedule.origin.into(),
491 _phantom: Default::default(),507 _phantom: Default::default(),
492 }))508 })
509 })
493 .collect::<Vec<_>>()510 .collect::<Vec<_>>(),
494 ));511 )
512 });
495 }513 }
496514
497 fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {515 fn resolve_time(when: DispatchTime<T::BlockNumber>) -> Result<T::BlockNumber, DispatchError> {
501 DispatchTime::At(x) => x,519 DispatchTime::At(x) => x,
502 // The current block has already completed it's scheduled tasks, so520 // The current block has already completed it's scheduled tasks, so
503 // Schedule the task at lest one block after this current block.521 // Schedule the task at lest one block after this current block.
504 DispatchTime::After(x) => now.saturating_add(x).saturating_add(One::one())522 DispatchTime::After(x) => now.saturating_add(x).saturating_add(One::one()),
505 };523 };
506524
507 if when <= now {525 if when <= now {
508 return Err(Error::<T>::TargetBlockNumberInPast.into())526 return Err(Error::<T>::TargetBlockNumberInPast.into());
509 }527 }
510528
511 Ok(when)529 Ok(when)
567 Self::deposit_event(RawEvent::Canceled(when, index));589 Self::deposit_event(RawEvent::Canceled(when, index));
568 Ok(())590 Ok(())
569 } else {591 } else {
570 Err(Error::<T>::NotFound)?592 Err(Error::<T>::NotFound.into())
571 }593 }
572 }594 }
573595
605 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {627 ) -> Result<TaskAddress<T::BlockNumber>, DispatchError> {
606 // ensure id it is unique628 // ensure id it is unique
607 if Lookup::<T>::contains_key(&id) {629 if Lookup::<T>::contains_key(&id) {
608 return Err(Error::<T>::FailedToSchedule)?630 return Err(Error::<T>::FailedToSchedule.into());
609 }631 }
610632
611 let when = Self::resolve_time(when)?;633 let when = Self::resolve_time(when)?;
644 call,
645 maybe_periodic,
646 origin,
647 _phantom: Default::default(),
621 };648 };
622 Agenda::<T>::append(when, Some(s));649 Agenda::<T>::append(when, Some(s));
623 let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;650 let index = Agenda::<T>::decode_len(when).unwrap_or(1) as u32 - 1;
653 Self::deposit_event(RawEvent::Canceled(when, index));680 Self::deposit_event(RawEvent::Canceled(when, index));
654 Ok(())681 Ok(())
655 } else {682 } else {
656 Err(Error::<T>::NotFound)?683 Err(Error::<T>::NotFound.into())
657 }684 }
658 })685 })
659 }686 }
750}789}
751790
752#[cfg(test)]791#[cfg(test)]
792#[allow(clippy::from_over_into)]
753mod tests {793mod tests {
754 use super::*;794 use super::*;
755795
1524 );
1525 }1759 }
15261760
1527 impl Into<OriginCaller> for u32 {1761 impl From<u32> for OriginCaller {
1528 fn into(self) -> OriginCaller {1762 fn from(value: u32) -> Self {
1529 match self {1763 match value {
1530 3u32 => system::RawOrigin::Root.into(),1764 3 => system::RawOrigin::Root.into(),
1531 2u32 => system::RawOrigin::None.into(),1765 2 => system::RawOrigin::None.into(),
1532 _ => unreachable!("test make no use of it"),1766 _ => unimplemented!(),
1533 }1767 }
1534 }1768 }
1535 }1769 }
modifiedpallets/scheduler/src/weights.rsdiffbeforeafterboth
4039
41use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}};40use frame_support::{
41 traits::Get,
42 weights::{Weight, constants::RocksDbWeight},
43};
42use sp_std::marker::PhantomData;44use sp_std::marker::PhantomData;
4345
54pub struct SubstrateWeight<T>(PhantomData<T>);55pub struct SubstrateWeight<T>(PhantomData<T>);
55impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {56impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> {
56 fn schedule(s: u32, ) -> Weight {57 fn schedule(s: u32) -> Weight {
57 (35_029_000 as Weight)58 35_029_000_u64
58 .saturating_add((77_000 as Weight).saturating_mul(s as Weight))59 .saturating_add(77_000_u64.saturating_mul(s as Weight))
59 .saturating_add(T::DbWeight::get().reads(1 as Weight))60 .saturating_add(T::DbWeight::get().reads(1_u64))
60 .saturating_add(T::DbWeight::get().writes(1 as Weight))61 .saturating_add(T::DbWeight::get().writes(1_u64))
61
62 }62 }
63 fn cancel(s: u32, ) -> Weight {63 fn cancel(s: u32) -> Weight {
64 (31_419_000 as Weight)64 31_419_000_u64
65 .saturating_add((4_015_000 as Weight).saturating_mul(s as Weight))65 .saturating_add(4_015_000_u64.saturating_mul(s as Weight))
66 .saturating_add(T::DbWeight::get().reads(1 as Weight))66 .saturating_add(T::DbWeight::get().reads(1_u64))
67 .saturating_add(T::DbWeight::get().writes(2 as Weight))67 .saturating_add(T::DbWeight::get().writes(2_u64))
68
69 }68 }
70 fn schedule_named(s: u32, ) -> Weight {69 fn schedule_named(s: u32) -> Weight {
71 (44_752_000 as Weight)70 44_752_000_u64
72 .saturating_add((123_000 as Weight).saturating_mul(s as Weight))71 .saturating_add(123_000_u64.saturating_mul(s as Weight))
73 .saturating_add(T::DbWeight::get().reads(2 as Weight))72 .saturating_add(T::DbWeight::get().reads(2_u64))
74 .saturating_add(T::DbWeight::get().writes(2 as Weight))73 .saturating_add(T::DbWeight::get().writes(2_u64))
75
76 }74 }
77 fn cancel_named(s: u32, ) -> Weight {75 fn cancel_named(s: u32) -> Weight {
78 (35_712_000 as Weight)76 35_712_000_u64
79 .saturating_add((4_008_000 as Weight).saturating_mul(s as Weight))77 .saturating_add(4_008_000_u64.saturating_mul(s as Weight))
80 .saturating_add(T::DbWeight::get().reads(2 as Weight))78 .saturating_add(T::DbWeight::get().reads(2_u64))
81 .saturating_add(T::DbWeight::get().writes(2 as Weight))79 .saturating_add(T::DbWeight::get().writes(2_u64))
82
83 }80 }
84
85}81}
8682
87// For backwards compatibility and tests83// For backwards compatibility and tests
88impl WeightInfo for () {84impl WeightInfo for () {
89 fn schedule(s: u32, ) -> Weight {85 fn schedule(s: u32) -> Weight {
90 (35_029_000 as Weight)86 35_029_000_u64
91 .saturating_add((77_000 as Weight).saturating_mul(s as Weight))87 .saturating_add(77_000_u64.saturating_mul(s as Weight))
92 .saturating_add(RocksDbWeight::get().reads(1 as Weight))88 .saturating_add(RocksDbWeight::get().reads(1_u64))
93 .saturating_add(RocksDbWeight::get().writes(1 as Weight))89 .saturating_add(RocksDbWeight::get().writes(1_u64))
94
95 }90 }
96 fn cancel(s: u32, ) -> Weight {91 fn cancel(s: u32) -> Weight {
97 (31_419_000 as Weight)92 31_419_000_u64
98 .saturating_add((4_015_000 as Weight).saturating_mul(s as Weight))93 .saturating_add(4_015_000_u64.saturating_mul(s as Weight))
99 .saturating_add(RocksDbWeight::get().reads(1 as Weight))94 .saturating_add(RocksDbWeight::get().reads(1_u64))
100 .saturating_add(RocksDbWeight::get().writes(2 as Weight))95 .saturating_add(RocksDbWeight::get().writes(2_u64))
101
102 }96 }
103 fn schedule_named(s: u32, ) -> Weight {97 fn schedule_named(s: u32) -> Weight {
104 (44_752_000 as Weight)98 44_752_000_u64
105 .saturating_add((123_000 as Weight).saturating_mul(s as Weight))99 .saturating_add(123_000_u64.saturating_mul(s as Weight))
106 .saturating_add(RocksDbWeight::get().reads(2 as Weight))100 .saturating_add(RocksDbWeight::get().reads(2_u64))
107 .saturating_add(RocksDbWeight::get().writes(2 as Weight))101 .saturating_add(RocksDbWeight::get().writes(2_u64))
108
109 }102 }
110 fn cancel_named(s: u32, ) -> Weight {103 fn cancel_named(s: u32) -> Weight {
111 (35_712_000 as Weight)104 35_712_000_u64
112 .saturating_add((4_008_000 as Weight).saturating_mul(s as Weight))105 .saturating_add(4_008_000_u64.saturating_mul(s as Weight))
113 .saturating_add(RocksDbWeight::get().reads(2 as Weight))106 .saturating_add(RocksDbWeight::get().reads(2_u64))
114 .saturating_add(RocksDbWeight::get().writes(2 as Weight))107 .saturating_add(RocksDbWeight::get().writes(2_u64))
115
116 }108 }
117
modifiedprimitives/nft/src/lib.rsdiffbeforeafterboth
32
4pub use serde::{Serialize, Deserialize};3pub use serde::{Serialize, Deserialize};
54
6use frame_system;
7use sp_runtime::sp_std::prelude::Vec;5use sp_runtime::sp_std::prelude::Vec;
8use codec::{Decode, Encode};6use codec::{Decode, Encode};
9pub use frame_support::{7pub use frame_support::{
48 }45 }
49}46}
5047
51impl Into<u8> for CollectionMode {48impl CollectionMode {
52 fn into(self) -> u8 {49 pub fn id(&self) -> u8 {
53 match self {50 match self {
54 CollectionMode::Invalid => 0,51 CollectionMode::Invalid => 0,
55 CollectionMode::NFT => 1,52 CollectionMode::NFT => 1,
146 pub offchain_schema: Vec<u8>,141 pub offchain_schema: Vec<u8>,
147 pub schema_version: SchemaVersion,142 pub schema_version: SchemaVersion,
148 pub sponsorship: SponsorshipState<T::AccountId>,143 pub sponsorship: SponsorshipState<T::AccountId>,
149 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions 144 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions
150 pub variable_on_chain_schema: Vec<u8>, //145 pub variable_on_chain_schema: Vec<u8>, //
151 pub const_on_chain_schema: Vec<u8>, //146 pub const_on_chain_schema: Vec<u8>, //
152}147}
180 pub account_token_ownership_limit: u32,174 pub account_token_ownership_limit: u32,
181 pub sponsored_data_size: u32,175 pub sponsored_data_size: u32,
182 /// None - setVariableMetadata is not sponsored176 /// None - setVariableMetadata is not sponsored
183 /// Some(v) - setVariableMetadata is sponsored 177 /// Some(v) - setVariableMetadata is sponsored
184 /// if there is v block between txs178 /// if there is v block between txs
185 pub sponsored_data_rate_limit: Option<BlockNumber>,179 pub sponsored_data_rate_limit: Option<BlockNumber>,
186 pub token_limit: u32,180 pub token_limit: u32,
200 sponsored_data_rate_limit: None,194 sponsored_data_rate_limit: None,
201 sponsor_transfer_timeout: 14400,195 sponsor_transfer_timeout: 14400,
202 owner_can_transfer: true,196 owner_can_transfer: true,
203 owner_can_destroy: true197 owner_can_destroy: true,
204 }198 }
205 }199 }
206}200}
255}248}
256249
257impl CreateItemData {250impl CreateItemData {
258 pub fn len(&self) -> usize {251 pub fn data_size(&self) -> usize {
259 let len = match self {252 match self {
260 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),253 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
261 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),254 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),
262 _ => 0255 _ => 0,
263 };256 }
264
265 return len;
266 }257 }
267}258}
268259
modifiedruntime/build.rsdiffbeforeafterboth

no syntactic changes

modifiedruntime/src/chain_extension.rsdiffbeforeafterboth
108108
109 pallet_nft::Module::<C>::submit_logs(collection)?;109 pallet_nft::Module::<C>::submit_logs(collection)?;
110 Ok(RetVal::Converging(0))110 Ok(RetVal::Converging(0))
111 },111 }
112 1 => {112 1 => {
113 // Create Item113 // Create Item
114 let mut env = env.buf_in_buf_out();114 let mut env = env.buf_in_buf_out();
115 let input: NFTExtCreateItem<E> = env.read_as()?;115 let input: NFTExtCreateItem<E> = env.read_as()?;
116 env.charge_weight(NftWeightInfoOf::<C>::create_item(input.data.len()))?;116 env.charge_weight(NftWeightInfoOf::<C>::create_item(input.data.data_size()))?;
117117
118 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;118 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
119119
126126
127 pallet_nft::Module::<C>::submit_logs(collection)?;127 pallet_nft::Module::<C>::submit_logs(collection)?;
128 Ok(RetVal::Converging(0))128 Ok(RetVal::Converging(0))
129 },129 }
130 2 => {130 2 => {
131 // Create multiple items131 // Create multiple items
132 let mut env = env.buf_in_buf_out();132 let mut env = env.buf_in_buf_out();
133 let input: NFTExtCreateMultipleItems<E> = env.read_as()?;133 let input: NFTExtCreateMultipleItems<E> = env.read_as()?;
134 env.charge_weight(NftWeightInfoOf::<C>::create_item(134 env.charge_weight(NftWeightInfoOf::<C>::create_item(
135 input.data.iter()135 input.data.iter().map(|i| i.data_size()).sum(),
136 .map(|i| i.len())
137 .sum()
138 ))?;136 ))?;
139137
148146
149 pallet_nft::Module::<C>::submit_logs(collection)?;147 pallet_nft::Module::<C>::submit_logs(collection)?;
150 Ok(RetVal::Converging(0))148 Ok(RetVal::Converging(0))
151 },149 }
152 3 => {150 3 => {
153 // Approve151 // Approve
154 let mut env = env.buf_in_buf_out();152 let mut env = env.buf_in_buf_out();
167165
168 pallet_nft::Module::<C>::submit_logs(collection)?;166 pallet_nft::Module::<C>::submit_logs(collection)?;
169 Ok(RetVal::Converging(0))167 Ok(RetVal::Converging(0))
170 },168 }
171 4 => {169 4 => {
172 // Transfer from170 // Transfer from
173 let mut env = env.buf_in_buf_out();171 let mut env = env.buf_in_buf_out();
187185
188 pallet_nft::Module::<C>::submit_logs(collection)?;186 pallet_nft::Module::<C>::submit_logs(collection)?;
189 Ok(RetVal::Converging(0))187 Ok(RetVal::Converging(0))
190 },188 }
191 5 => {189 5 => {
192 // Set variable metadata190 // Set variable metadata
193 let mut env = env.buf_in_buf_out();191 let mut env = env.buf_in_buf_out();
205203
206 pallet_nft::Module::<C>::submit_logs(collection)?;204 pallet_nft::Module::<C>::submit_logs(collection)?;
207 Ok(RetVal::Converging(0))205 Ok(RetVal::Converging(0))
208 },206 }
209 6 => {207 6 => {
210 // Toggle whitelist208 // Toggle whitelist
211 let mut env = env.buf_in_buf_out();209 let mut env = env.buf_in_buf_out();
224 pallet_nft::Module::<C>::submit_logs(collection)?;222 pallet_nft::Module::<C>::submit_logs(collection)?;
225 Ok(RetVal::Converging(0))223 Ok(RetVal::Converging(0))
226 }224 }
227 _ => {225 _ => Err(DispatchError::Other("unknown chain_extension func_id")),
228 Err(DispatchError::Other("unknown chain_extension func_id"))
229 }
230 }226 }
231 }227 }
232}228}
modifiedruntime/src/lib.rsdiffbeforeafterboth
8#![cfg_attr(not(feature = "std"), no_std)]8#![cfg_attr(not(feature = "std"), no_std)]
9// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.9// `construct_runtime!` does a lot of recursion and requires us to increase the limit to 256.
10#![recursion_limit = "1024"]10#![recursion_limit = "1024"]
1111#![allow(clippy::from_over_into, clippy::identity_op)]
12#![allow(clippy::fn_to_numeric_cast_with_truncation)]
12// Make the WASM binary available.13// Make the WASM binary available.
13#[cfg(feature = "std")]14#[cfg(feature = "std")]
14include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));15include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));
35use sp_version::NativeVersion;35use sp_version::NativeVersion;
36use sp_version::RuntimeVersion;36use sp_version::RuntimeVersion;
37pub use pallet_transaction_payment::{Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo};37pub use pallet_transaction_payment::{
38 Multiplier, TargetedFeeAdjustment, FeeDetails, RuntimeDispatchInfo,
39};
38// A few exports that help ease life for downstream crates.40// A few exports that help ease life for downstream crates.
39pub use pallet_balances::Call as BalancesCall;41pub use pallet_balances::Call as BalancesCall;
48 ConsensusEngineId,
49 traits::{47 traits::{
50 All, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier, OnUnbalanced, Randomness, FindAuthor48 All, Currency, ExistenceRequirement, Get, IsInVec, KeyOwnerProofSystem, LockIdentifier,
49 OnUnbalanced, Randomness, FindAuthor,
51 },50 },
52 weights::{51 weights::{
53 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},52 constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
54 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,53 DispatchClass, DispatchInfo, GetDispatchInfo, IdentityFee, Pays, PostDispatchInfo, Weight,
55 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients54 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients,
56 },55 },
57};56};
58use nft_data_structs::*;57use nft_data_structs::*;
64 limits::{BlockWeights, BlockLength},62 limits::{BlockWeights, BlockLength},
65};63};
66use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};64use sp_arithmetic::{
65 traits::{BaseArithmetic, Unsigned},
66};
67use smallvec::smallvec;67use smallvec::smallvec;
68use codec::{Encode, Decode};68use codec::{Encode, Decode};
69use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};69use pallet_evm::{Account as EVMAccount, FeeCalculator, OnMethodCall};
70use fp_rpc::TransactionStatus;70use fp_rpc::TransactionStatus;
71use sp_core::crypto::Public;71use sp_core::crypto::Public;
72use sp_runtime::{72use sp_runtime::{
73 traits::{ 73 traits::{Dispatchable},
74 Dispatchable,
75 },
76};74};
77use pallet_contracts::chain_extension::UncheckedFrom;75use pallet_contracts::chain_extension::UncheckedFrom;
272{
273 fn find_author<'a, I>(digests: I) -> Option<H160> where267 fn find_author<'a, I>(digests: I) -> Option<H160>
268 where
274 I: 'a + IntoIterator<Item=(ConsensusEngineId, &'a [u8])>269 I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
275 {270 {
276 if let Some(author_index) = F::find_author(digests) {271 if let Some(author_index) = F::find_author(digests) {
277 let authority_id = Aura::authorities()[author_index as usize].clone();272 let authority_id = Aura::authorities()[author_index as usize].clone();
439434
440impl<T> WeightToFeePolynomial for LinearFee<T> where435impl<T> WeightToFeePolynomial for LinearFee<T>
436where
441 T: BaseArithmetic + From<u32> + Copy + Unsigned437 T: BaseArithmetic + From<u32> + Copy + Unsigned,
442{438{
443 type Balance = T;439 type Balance = T;
444440
727 Call: IsSubType<pallet_nft::Call<Runtime>>, 722 Call: IsSubType<pallet_nft::Call<Runtime>>,
728 Call: IsSubType<pallet_contracts::Call<Runtime>>,723 Call: IsSubType<pallet_contracts::Call<Runtime>>,
729 AccountId: AsRef<[u8]>,724 AccountId: AsRef<[u8]>,
730 AccountId: UncheckedFrom<Hash>725 AccountId: UncheckedFrom<Hash>,
731 {726 {
732 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)727 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)
733 }728 }
979 gas_limit.low_u64(),982 gas_limit.low_u64(),
980 gas_price,983 gas_price,
981 nonce,984 nonce,
982 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),985 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
983 ).map_err(|err| err.into())986 ).map_err(|err| err.into())
984 }987 }
985988
1007 gas_limit.low_u64(),1010 gas_limit.low_u64(),
1008 gas_price,1011 gas_price,
1009 nonce,1012 nonce,
1010 config.as_ref().unwrap_or(<Runtime as pallet_evm::Config>::config()),1013 config.as_ref().unwrap_or_else(|| <Runtime as pallet_evm::Config>::config()),
1011 ).map_err(|err| err.into())1014 ).map_err(|err| err.into())
1012 }1015 }
10131016
modifiedruntime/src/nft_weights.rsdiffbeforeafterboth
8pub struct WeightInfo;8pub struct WeightInfo;
9impl pallet_nft::WeightInfo for WeightInfo {9impl pallet_nft::WeightInfo for WeightInfo {
10 fn create_collection() -> Weight {10 fn create_collection() -> Weight {
11 (70_000_000 as Weight)11 70_000_000_u64
12 .saturating_add(DbWeight::get().reads(7 as Weight))12 .saturating_add(DbWeight::get().reads(7_u64))
13 .saturating_add(DbWeight::get().writes(5 as Weight))13 .saturating_add(DbWeight::get().writes(5_u64))
14 }14 }
15 fn destroy_collection() -> Weight {15 fn destroy_collection() -> Weight {
16 (90_000_000 as Weight)16 90_000_000_u64
17 .saturating_add(DbWeight::get().reads(2 as Weight))17 .saturating_add(DbWeight::get().reads(2_u64))
18 .saturating_add(DbWeight::get().writes(5 as Weight))18 .saturating_add(DbWeight::get().writes(5_u64))
19 }19 }
20 fn add_to_white_list() -> Weight {20 fn add_to_white_list() -> Weight {
21 (30_000_000 as Weight)21 30_000_000_u64
22 .saturating_add(DbWeight::get().reads(3 as Weight))22 .saturating_add(DbWeight::get().reads(3_u64))
23 .saturating_add(DbWeight::get().writes(1 as Weight))23 .saturating_add(DbWeight::get().writes(1_u64))
24 }24 }
25 fn remove_from_white_list() -> Weight {25 fn remove_from_white_list() -> Weight {
26 (35_000_000 as Weight)26 35_000_000_u64
27 .saturating_add(DbWeight::get().reads(3 as Weight))27 .saturating_add(DbWeight::get().reads(3_u64))
28 .saturating_add(DbWeight::get().writes(1 as Weight))28 .saturating_add(DbWeight::get().writes(1_u64))
29 }29 }
30 fn set_public_access_mode() -> Weight {30 fn set_public_access_mode() -> Weight {
31 (27_000_000 as Weight)31 27_000_000_u64
32 .saturating_add(DbWeight::get().reads(1 as Weight))32 .saturating_add(DbWeight::get().reads(1_u64))
33 .saturating_add(DbWeight::get().writes(1 as Weight))33 .saturating_add(DbWeight::get().writes(1_u64))
34 }34 }
35 fn set_mint_permission() -> Weight {35 fn set_mint_permission() -> Weight {
36 (27_000_000 as Weight)36 27_000_000_u64
37 .saturating_add(DbWeight::get().reads(1 as Weight))37 .saturating_add(DbWeight::get().reads(1_u64))
38 .saturating_add(DbWeight::get().writes(1 as Weight))38 .saturating_add(DbWeight::get().writes(1_u64))
39 }39 }
40 fn change_collection_owner() -> Weight {40 fn change_collection_owner() -> Weight {
41 (27_000_000 as Weight)41 27_000_000_u64
42 .saturating_add(DbWeight::get().reads(1 as Weight))42 .saturating_add(DbWeight::get().reads(1_u64))
43 .saturating_add(DbWeight::get().writes(1 as Weight))43 .saturating_add(DbWeight::get().writes(1_u64))
44 }44 }
45 fn add_collection_admin() -> Weight {45 fn add_collection_admin() -> Weight {
46 (32_000_000 as Weight)46 32_000_000_u64
47 .saturating_add(DbWeight::get().reads(3 as Weight))47 .saturating_add(DbWeight::get().reads(3_u64))
48 .saturating_add(DbWeight::get().writes(1 as Weight))48 .saturating_add(DbWeight::get().writes(1_u64))
49 }49 }
50 fn remove_collection_admin() -> Weight {50 fn remove_collection_admin() -> Weight {
51 (50_000_000 as Weight)51 50_000_000_u64
52 .saturating_add(DbWeight::get().reads(2 as Weight))52 .saturating_add(DbWeight::get().reads(2_u64))
53 .saturating_add(DbWeight::get().writes(1 as Weight))53 .saturating_add(DbWeight::get().writes(1_u64))
54 }54 }
55 fn set_collection_sponsor() -> Weight {55 fn set_collection_sponsor() -> Weight {
56 (32_000_000 as Weight)56 32_000_000_u64
57 .saturating_add(DbWeight::get().reads(2 as Weight))57 .saturating_add(DbWeight::get().reads(2_u64))
58 .saturating_add(DbWeight::get().writes(1 as Weight))58 .saturating_add(DbWeight::get().writes(1_u64))
59 } 59 }
60 fn confirm_sponsorship() -> Weight {60 fn confirm_sponsorship() -> Weight {
61 (22_000_000 as Weight)61 22_000_000_u64
62 .saturating_add(DbWeight::get().reads(1 as Weight))62 .saturating_add(DbWeight::get().reads(1_u64))
63 .saturating_add(DbWeight::get().writes(1 as Weight))63 .saturating_add(DbWeight::get().writes(1_u64))
64 } 64 }
65 fn remove_collection_sponsor() -> Weight {65 fn remove_collection_sponsor() -> Weight {
66 (24_000_000 as Weight)66 24_000_000_u64
67 .saturating_add(DbWeight::get().reads(1 as Weight))67 .saturating_add(DbWeight::get().reads(1_u64))
68 .saturating_add(DbWeight::get().writes(1 as Weight))68 .saturating_add(DbWeight::get().writes(1_u64))
69 } 69 }
70 fn create_item(s: usize, ) -> Weight {70 fn create_item(s: usize) -> Weight {
71 (130_000_000 as Weight)71 130_000_000_u64
72 .saturating_add((2135 as Weight).saturating_mul(s as Weight).saturating_mul(500 as Weight)) // 500 is temparary multiplier, fee for storage72 .saturating_add(2135_u64.saturating_mul(s as Weight).saturating_mul(500_u64)) // 500 is temparary multiplier, fee for storage
73 .saturating_add(DbWeight::get().reads(10 as Weight))73 .saturating_add(DbWeight::get().reads(10_u64))
74 .saturating_add(DbWeight::get().writes(8 as Weight))74 .saturating_add(DbWeight::get().writes(8_u64))
75 } 75 }
76 fn burn_item() -> Weight {76 fn burn_item() -> Weight {
77 (170_000_000 as Weight)77 170_000_000_u64
78 .saturating_add(DbWeight::get().reads(9 as Weight))78 .saturating_add(DbWeight::get().reads(9_u64))
79 .saturating_add(DbWeight::get().writes(7 as Weight))79 .saturating_add(DbWeight::get().writes(7_u64))
80 } 80 }
81 fn transfer() -> Weight {81 fn transfer() -> Weight {
82 (125_000_000 as Weight)82 125_000_000_u64
83 .saturating_add(DbWeight::get().reads(7 as Weight))83 .saturating_add(DbWeight::get().reads(7_u64))
84 .saturating_add(DbWeight::get().writes(7 as Weight))84 .saturating_add(DbWeight::get().writes(7_u64))
85 } 85 }
86 fn approve() -> Weight {86 fn approve() -> Weight {
87 (45_000_000 as Weight)87 45_000_000_u64
88 .saturating_add(DbWeight::get().reads(3 as Weight))88 .saturating_add(DbWeight::get().reads(3_u64))
89 .saturating_add(DbWeight::get().writes(1 as Weight))89 .saturating_add(DbWeight::get().writes(1_u64))
90 }90 }
91 fn transfer_from() -> Weight {91 fn transfer_from() -> Weight {
92 (150_000_000 as Weight)92 150_000_000_u64
93 .saturating_add(DbWeight::get().reads(9 as Weight))93 .saturating_add(DbWeight::get().reads(9_u64))
94 .saturating_add(DbWeight::get().writes(8 as Weight))94 .saturating_add(DbWeight::get().writes(8_u64))
95 }95 }
96 fn set_offchain_schema() -> Weight {96 fn set_offchain_schema() -> Weight {
97 (33_000_000 as Weight)97 33_000_000_u64
98 .saturating_add(DbWeight::get().reads(2 as Weight))98 .saturating_add(DbWeight::get().reads(2_u64))
99 .saturating_add(DbWeight::get().writes(1 as Weight))99 .saturating_add(DbWeight::get().writes(1_u64))
100 }100 }
101 fn set_const_on_chain_schema() -> Weight {101 fn set_const_on_chain_schema() -> Weight {
102 (11_100_000 as Weight)102 11_100_000_u64
103 .saturating_add(DbWeight::get().reads(2 as Weight))103 .saturating_add(DbWeight::get().reads(2_u64))
104 .saturating_add(DbWeight::get().writes(1 as Weight))104 .saturating_add(DbWeight::get().writes(1_u64))
105 }105 }
106 fn set_variable_on_chain_schema() -> Weight {106 fn set_variable_on_chain_schema() -> Weight {
107 (11_100_000 as Weight)107 11_100_000_u64
108 .saturating_add(DbWeight::get().reads(2 as Weight))108 .saturating_add(DbWeight::get().reads(2_u64))
109 .saturating_add(DbWeight::get().writes(1 as Weight))109 .saturating_add(DbWeight::get().writes(1_u64))
110 }110 }
111 fn set_variable_meta_data() -> Weight {111 fn set_variable_meta_data() -> Weight {
112 (17_500_000 as Weight)112 17_500_000_u64
113 .saturating_add(DbWeight::get().reads(2 as Weight))113 .saturating_add(DbWeight::get().reads(2_u64))
114 .saturating_add(DbWeight::get().writes(1 as Weight))114 .saturating_add(DbWeight::get().writes(1_u64))
115 }115 }
116 fn enable_contract_sponsoring() -> Weight {116 fn enable_contract_sponsoring() -> Weight {
117 (13_000_000 as Weight)117 13_000_000_u64
118 .saturating_add(DbWeight::get().reads(1 as Weight))118 .saturating_add(DbWeight::get().reads(1_u64))
119 .saturating_add(DbWeight::get().writes(1 as Weight))119 .saturating_add(DbWeight::get().writes(1_u64))
120 }120 }
121 fn set_schema_version() -> Weight {121 fn set_schema_version() -> Weight {
122 (8_500_000 as Weight)122 8_500_000_u64
123 .saturating_add(DbWeight::get().reads(2 as Weight))123 .saturating_add(DbWeight::get().reads(2_u64))
124 .saturating_add(DbWeight::get().writes(1 as Weight))124 .saturating_add(DbWeight::get().writes(1_u64))
125 }125 }
126 fn set_chain_limits() -> Weight {126 fn set_chain_limits() -> Weight {
127 (1_300_000 as Weight)127 1_300_000_u64
128 .saturating_add(DbWeight::get().reads(0 as Weight))128 .saturating_add(DbWeight::get().reads(0_u64))
129 .saturating_add(DbWeight::get().writes(1 as Weight))129 .saturating_add(DbWeight::get().writes(1_u64))
130 }130 }
131 fn set_contract_sponsoring_rate_limit() -> Weight {131 fn set_contract_sponsoring_rate_limit() -> Weight {
132 (3_500_000 as Weight)132 3_500_000_u64
133 .saturating_add(DbWeight::get().reads(0 as Weight))133 .saturating_add(DbWeight::get().reads(0_u64))
134 .saturating_add(DbWeight::get().writes(2 as Weight))134 .saturating_add(DbWeight::get().writes(2_u64))
135 } 135 }
136 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {136 fn set_variable_meta_data_sponsoring_rate_limit() -> Weight {
137 (3_500_000 as Weight)137 3_500_000_u64
138 .saturating_add(DbWeight::get().reads(1 as Weight))138 .saturating_add(DbWeight::get().reads(1_u64))
139 .saturating_add(DbWeight::get().writes(2 as Weight))139 .saturating_add(DbWeight::get().writes(2_u64))
140 }140 }
141 fn toggle_contract_white_list() -> Weight {141 fn toggle_contract_white_list() -> Weight {
142 (3_000_000 as Weight)142 3_000_000_u64
143 .saturating_add(DbWeight::get().reads(0 as Weight))143 .saturating_add(DbWeight::get().reads(0_u64))
144 .saturating_add(DbWeight::get().writes(2 as Weight))144 .saturating_add(DbWeight::get().writes(2_u64))
145 } 145 }
146 fn add_to_contract_white_list() -> Weight {146 fn add_to_contract_white_list() -> Weight {
147 (3_000_000 as Weight)147 3_000_000_u64
148 .saturating_add(DbWeight::get().reads(0 as Weight))148 .saturating_add(DbWeight::get().reads(0_u64))
149 .saturating_add(DbWeight::get().writes(2 as Weight))149 .saturating_add(DbWeight::get().writes(2_u64))
150 } 150 }
151 fn remove_from_contract_white_list() -> Weight {151 fn remove_from_contract_white_list() -> Weight {
152 (3_200_000 as Weight)152 3_200_000_u64
153 .saturating_add(DbWeight::get().reads(0 as Weight))153 .saturating_add(DbWeight::get().reads(0_u64))
154 .saturating_add(DbWeight::get().writes(2 as Weight))154 .saturating_add(DbWeight::get().writes(2_u64))
155 }155 }
156 fn set_collection_limits() -> Weight {156 fn set_collection_limits() -> Weight {
157 (8_900_000 as Weight)157 8_900_000_u64
158 .saturating_add(DbWeight::get().reads(2 as Weight))158 .saturating_add(DbWeight::get().reads(2_u64))
159 .saturating_add(DbWeight::get().writes(1 as Weight))159 .saturating_add(DbWeight::get().writes(1_u64))
160 }160 }
161}161}
162162