git.delta.rocks / unique-network / refs/commits / e5c09cb43ca9

difftreelog

Merge branch 'develop' into feature/NFTPAR-373_chain_extensions

Greg Zaitsev2021-06-17parents: #0c23e05 #cbd9f34.patch.diff
in: master

27 files changed

modifiedCargo.lockdiffbeforeafterboth
3433 "pallet-proxy",3433 "pallet-proxy",
3434 "pallet-randomness-collective-flip",3434 "pallet-randomness-collective-flip",
3435 "pallet-recovery",3435 "pallet-recovery",
3436 "pallet-scheduler",3436 "pallet-scheduler 3.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3)",
3437 "pallet-session",3437 "pallet-session",
3438 "pallet-society",3438 "pallet-society",
3439 "pallet-staking",3439 "pallet-staking",
4517 "futures 0.3.14",4517 "futures 0.3.14",
4518 "jsonrpc-core",4518 "jsonrpc-core",
4519 "log",4519 "log",
4520 "nft-data-structs",
4520 "nft-runtime",4521 "nft-runtime",
4521 "pallet-contracts",4522 "pallet-contracts",
4522 "pallet-contracts-rpc",4523 "pallet-contracts-rpc",
4567 "substrate-prometheus-endpoint",4568 "substrate-prometheus-endpoint",
4568]4569]
4570
4571[[package]]
4572name = "nft-data-structs"
4573version = "0.9.0"
4574dependencies = [
4575 "frame-support",
4576 "frame-system",
4577 "pallet-contracts",
4578 "parity-scale-codec",
4579 "serde",
4580 "sp-core",
4581 "sp-runtime",
4582]
45694583
4570[[package]]4584[[package]]
4571name = "nft-runtime"4585name = "nft-runtime"
4585 "frame-system-benchmarking",4599 "frame-system-benchmarking",
4586 "frame-system-rpc-runtime-api",4600 "frame-system-rpc-runtime-api",
4587 "hex-literal",4601 "hex-literal",
4602 "nft-data-structs",
4588 "pallet-aura",4603 "pallet-aura",
4589 "pallet-balances",4604 "pallet-balances",
4590 "pallet-contracts",4605 "pallet-contracts",
4591 "pallet-contracts-primitives",4606 "pallet-contracts-primitives",
4592 "pallet-contracts-rpc-runtime-api",4607 "pallet-contracts-rpc-runtime-api",
4593 "pallet-inflation",4608 "pallet-inflation",
4594 "pallet-nft",4609 "pallet-nft",
4610 "pallet-nft-charge-transaction",
4611 "pallet-nft-transaction-payment",
4595 "pallet-randomness-collective-flip",4612 "pallet-randomness-collective-flip",
4613 "pallet-scheduler 3.0.0",
4596 "pallet-sudo",4614 "pallet-sudo",
4597 "pallet-timestamp",4615 "pallet-timestamp",
4598 "pallet-transaction-payment",4616 "pallet-transaction-payment",
5245 "frame-benchmarking",5263 "frame-benchmarking",
5246 "frame-support",5264 "frame-support",
5247 "frame-system",5265 "frame-system",
5266 "nft-data-structs",
5248 "pallet-balances",5267 "pallet-balances",
5249 "pallet-contracts",5268 "pallet-contracts",
5250 "pallet-randomness-collective-flip",5269 "pallet-randomness-collective-flip",
5258 "sp-std",5277 "sp-std",
5259]5278]
5279
5280[[package]]
5281name = "pallet-nft-charge-transaction"
5282version = "3.0.0"
5283dependencies = [
5284 "frame-benchmarking",
5285 "frame-support",
5286 "frame-system",
5287 "nft-data-structs",
5288 "pallet-balances",
5289 "pallet-contracts",
5290 "pallet-nft",
5291 "pallet-nft-transaction-payment",
5292 "pallet-randomness-collective-flip",
5293 "pallet-timestamp",
5294 "pallet-transaction-payment",
5295 "parity-scale-codec",
5296 "serde",
5297 "sp-core",
5298 "sp-io",
5299 "sp-runtime",
5300 "sp-std",
5301]
5302
5303[[package]]
5304name = "pallet-nft-transaction-payment"
5305version = "3.0.0"
5306dependencies = [
5307 "frame-benchmarking",
5308 "frame-support",
5309 "frame-system",
5310 "nft-data-structs",
5311 "pallet-balances",
5312 "pallet-contracts",
5313 "pallet-nft",
5314 "pallet-randomness-collective-flip",
5315 "pallet-timestamp",
5316 "pallet-transaction-payment",
5317 "parity-scale-codec",
5318 "serde",
5319 "sp-core",
5320 "sp-io",
5321 "sp-runtime",
5322 "sp-std",
5323]
52605324
5261[[package]]5325[[package]]
5262name = "pallet-nicks"5326name = "pallet-nicks"
5328 "sp-std",5392 "sp-std",
5329]5393]
5394
5395[[package]]
5396name = "pallet-scheduler"
5397version = "3.0.0"
5398dependencies = [
5399 "frame-benchmarking",
5400 "frame-support",
5401 "frame-system",
5402 "log",
5403 "nft-data-structs",
5404 "pallet-contracts",
5405 "pallet-nft",
5406 "pallet-nft-transaction-payment",
5407 "parity-scale-codec",
5408 "serde",
5409 "sp-core",
5410 "sp-io",
5411 "sp-runtime",
5412 "sp-std",
5413 "substrate-test-utils",
5414]
53305415
5331[[package]]5416[[package]]
5332name = "pallet-scheduler"5417name = "pallet-scheduler"
6639 "pallet-offences",6724 "pallet-offences",
6640 "pallet-proxy",6725 "pallet-proxy",
6641 "pallet-randomness-collective-flip",6726 "pallet-randomness-collective-flip",
6642 "pallet-scheduler",6727 "pallet-scheduler 3.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3)",
6643 "pallet-session",6728 "pallet-session",
6644 "pallet-staking",6729 "pallet-staking",
6645 "pallet-staking-reward-curve",6730 "pallet-staking-reward-curve",
10140 "sp-state-machine",10225 "sp-state-machine",
10141]10226]
10227
10228[[package]]
10229name = "substrate-test-utils"
10230version = "3.0.0"
10231source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3#c94e0cdfe5556680dca1996004751eeb114755d7"
10232dependencies = [
10233 "futures 0.3.14",
10234 "substrate-test-utils-derive",
10235 "tokio 0.2.25",
10236]
10237
10238[[package]]
10239name = "substrate-test-utils-derive"
10240version = "0.9.0"
10241source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3#c94e0cdfe5556680dca1996004751eeb114755d7"
10242dependencies = [
10243 "proc-macro-crate 1.0.0",
10244 "quote",
10245 "syn",
10246]
1014210247
10143[[package]]10248[[package]]
10144name = "substrate-wasm-builder"10249name = "substrate-wasm-builder"
10404 "pin-project-lite 0.1.12",10509 "pin-project-lite 0.1.12",
10405 "signal-hook-registry",10510 "signal-hook-registry",
10406 "slab",10511 "slab",
10512 "tokio-macros",
10407 "winapi 0.3.9",10513 "winapi 0.3.9",
10408]10514]
1040910515
10471 "log",10577 "log",
10472]10578]
10579
10580[[package]]
10581name = "tokio-macros"
10582version = "0.2.6"
10583source = "registry+https://github.com/rust-lang/crates.io-index"
10584checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a"
10585dependencies = [
10586 "proc-macro2",
10587 "quote",
10588 "syn",
10589]
1047310590
10474[[package]]10591[[package]]
10475name = "tokio-named-pipes"10592name = "tokio-named-pipes"
11476 "pallet-proxy",11593 "pallet-proxy",
11477 "pallet-randomness-collective-flip",11594 "pallet-randomness-collective-flip",
11478 "pallet-recovery",11595 "pallet-recovery",
11479 "pallet-scheduler",11596 "pallet-scheduler 3.0.0 (git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.3)",
11480 "pallet-session",11597 "pallet-session",
11481 "pallet-society",11598 "pallet-society",
11482 "pallet-staking",11599 "pallet-staking",
modifiedCargo.tomldiffbeforeafterboth
2members = [2members = [
3 'node',3 'node',
4 'pallets/*',4 'pallets/*',
5 'primitives',
5 'runtime',6 'runtime',
6]7]
7resolver = "2"8resolver = "2"
modifiednode/Cargo.tomldiffbeforeafterboth
283path = '../runtime'283path = '../runtime'
284version = '3.0.0'284version = '3.0.0'
285
286[dependencies.nft-data-structs]
287path="../primitives"
288default-features = false
285289
286################################################################################290################################################################################
287# Package 291# Package
modifiednode/src/chain_spec.rsdiffbeforeafterboth
55
6use cumulus_primitives_core::ParaId;6use cumulus_primitives_core::ParaId;
7use nft_runtime::*;7use nft_runtime::*;
8use nft_data_structs::*;
8use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};9use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
9use sc_service::ChainType;10use sc_service::ChainType;
10use sp_core::{sr25519, Pair, Public};11use sp_core::{sr25519, Pair, Public};
161 balances: endowed_accounts162 balances: endowed_accounts
162 .iter()163 .iter()
163 .cloned()164 .cloned()
164 .map(|k| (k, 1 << 100))165 .map(|k| (k, 1 << 70))
165 .collect(),166 .collect(),
166 },167 },
167 pallet_treasury: Default::default(),168 pallet_treasury: Default::default(),
addedpallets/nft-charge-transaction/Cargo.tomldiffbeforeafterboth

no changes

addedpallets/nft-charge-transaction/src/lib.rsdiffbeforeafterboth

no changes

addedpallets/nft-transaction-payment/Cargo.tomldiffbeforeafterboth

no changes

addedpallets/nft-transaction-payment/README.mddiffbeforeafterboth

no changes

addedpallets/nft-transaction-payment/src/benchmarking.rsdiffbeforeafterboth

no changes

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

no changes

addedpallets/nft-transaction-payment/src/tests.rsdiffbeforeafterboth

no changes

modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
27 'pallet-contracts/std',27 'pallet-contracts/std',
28 'pallet-randomness-collective-flip/std',28 'pallet-randomness-collective-flip/std',
29 'pallet-transaction-payment/std',29 'pallet-transaction-payment/std',
30 'nft-data-structs/std',
30 'sp-std/std',31 'sp-std/std',
31 'sp-runtime/std',32 'sp-runtime/std',
32 'frame-benchmarking/std',33 'frame-benchmarking/std',
118branch = 'polkadot-v0.9.3'119branch = 'polkadot-v0.9.3'
119version = '3.0.0'120version = '3.0.0'
120121
121122################################################################################
123# Local Dependencies
124
125[dependencies.nft-data-structs]
126default-features = false
127path = '../../primitives'
128version = '0.9.0'
modifiedpallets/nft/src/lib.rsdiffbeforeafterboth
13#[cfg(feature = "std")]13#[cfg(feature = "std")]
14pub use serde::*;14pub use serde::*;
1515
16use core::ops::{Deref, DerefMut};
17use codec::{Decode, Encode};
18pub use frame_support::{16pub use frame_support::{
19 construct_runtime, decl_event, decl_module, decl_storage, decl_error,17 construct_runtime, decl_event, decl_module, decl_storage, decl_error,
20 dispatch::DispatchResult,18 dispatch::DispatchResult,
3432
35use frame_system::{self as system, ensure_signed, ensure_root};33use frame_system::{self as system, ensure_signed, ensure_root};
36use sp_runtime::sp_std::prelude::Vec;34use sp_runtime::sp_std::prelude::Vec;
35use core::ops::{Deref, DerefMut};
37use sp_runtime::{36use nft_data_structs::{
38 traits::{
39 Hash, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, Saturating, SaturatedConversion, SignedExtension, Zero,37 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,
40 },38 AccessMode, ChainLimits, Collection, CreateItemData, CollectionLimits,
41 transaction_validity::{
42 TransactionPriority, InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,39 CollectionId, CollectionMode, TokenId,
43 },40 SchemaVersion, SponsorshipState, Ownership,
44 FixedPointOperand, FixedU128,41 NftItemType, FungibleItemType, ReFungibleItemType
45};42};
46use sp_runtime::traits::StaticLookup;
47use pallet_contracts::chain_extension::UncheckedFrom;
48use pallet_transaction_payment::OnChargeTransaction;
4943
50#[cfg(test)]44#[cfg(test)]
51mod mock;45mod mock;
5549
56mod default_weights;50mod default_weights;
57
58pub const MAX_DECIMAL_POINTS: DecimalPoints = 30;
59pub const MAX_REFUNGIBLE_PIECES: u128 = 1_000_000_000_000_000_000_000;
60pub const MAX_SPONSOR_TIMEOUT: u32 = 10_368_000;
61pub const MAX_TOKEN_OWNERSHIP: u32 = 10_000_000;
62
63// Structs
64// #region
65
66pub type CollectionId = u32;
67pub type TokenId = u32;
68pub type DecimalPoints = u8;
69
70#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
71#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
72pub enum CollectionMode {
73 Invalid,
74 NFT,
75 // decimal points
76 Fungible(DecimalPoints),
77 ReFungible,
78}
79
80impl Default for CollectionMode {
81 fn default() -> Self {
82 Self::Invalid
83 }
84}
85
86impl Into<u8> for CollectionMode {
87 fn into(self) -> u8 {
88 match self {
89 CollectionMode::Invalid => 0,
90 CollectionMode::NFT => 1,
91 CollectionMode::Fungible(_) => 2,
92 CollectionMode::ReFungible => 3,
93 }
94 }
95}
96
97#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
98#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
99pub enum AccessMode {
100 Normal,
101 WhiteList,
102}
103impl Default for AccessMode {
104 fn default() -> Self {
105 Self::Normal
106 }
107}
108
109#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]
110#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
111pub enum SchemaVersion {
112 ImageURL,
113 Unique,
114}
115impl Default for SchemaVersion {
116 fn default() -> Self {
117 Self::ImageURL
118 }
119}
120
121#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
122#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
123pub struct Ownership<AccountId> {
124 pub owner: AccountId,
125 pub fraction: u128,
126}
127
128#[derive(Encode, Decode, Debug, Clone, PartialEq)]
129#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
130pub enum SponsorshipState<AccountId> {
131 /// The fees are applied to the transaction sender
132 Disabled,
133 Unconfirmed(AccountId),
134 /// Transactions are sponsored by specified account
135 Confirmed(AccountId),
136}
137
138impl<AccountId> SponsorshipState<AccountId> {
139 fn sponsor(&self) -> Option<&AccountId> {
140 match self {
141 Self::Confirmed(sponsor) => Some(sponsor),
142 _ => None,
143 }
144 }
145
146 fn pending_sponsor(&self) -> Option<&AccountId> {
147 match self {
148 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),
149 _ => None,
150 }
151 }
152
153 fn confirmed(&self) -> bool {
154 matches!(self, Self::Confirmed(_))
155 }
156}
157
158impl<T> Default for SponsorshipState<T> {
159 fn default() -> Self {
160 Self::Disabled
161 }
162}
16351
164#[derive(Encode, Decode, Clone, PartialEq)]52#[cfg(feature = "runtime-benchmarks")]
165#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]53mod benchmarking;
166pub struct Collection<T: Config> {
167 pub owner: T::AccountId,
168 pub mode: CollectionMode,
169 pub access: AccessMode,
170 pub decimal_points: DecimalPoints,
171 pub name: Vec<u16>, // 64 include null escape char
172 pub description: Vec<u16>, // 256 include null escape char
173 pub token_prefix: Vec<u8>, // 16 include null escape char
174 pub mint_mode: bool,
175 pub offchain_schema: Vec<u8>,
176 pub schema_version: SchemaVersion,
177 pub sponsorship: SponsorshipState<T::AccountId>,
178 pub limits: CollectionLimits<T::BlockNumber>, // Collection private restrictions
179 pub variable_on_chain_schema: Vec<u8>, //
180 pub const_on_chain_schema: Vec<u8>, //
181}
182
183pub struct CollectionHandle<T: Config> {
184 pub id: CollectionId,
185 collection: Collection<T>,
186}
187
188impl<T: Config> Deref for CollectionHandle<T> {
189 type Target = Collection<T>;
190
191 fn deref(&self) -> &Self::Target {
192 &self.collection
193 }
194}
195
196impl<T: Config> DerefMut for CollectionHandle<T> {
197 fn deref_mut(&mut self) -> &mut Self::Target {
198 &mut self.collection
199 }
200}
201
202#[derive(Encode, Decode, Debug, Clone, PartialEq)]
203#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
204pub struct NftItemType<AccountId> {
205 pub owner: AccountId,
206 pub const_data: Vec<u8>,
207 pub variable_data: Vec<u8>,
208}
209
210#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
211#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
212pub struct FungibleItemType {
213 pub value: u128,
214}
215
216#[derive(Encode, Decode, Debug, Clone, PartialEq)]
217#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
218pub struct ReFungibleItemType<AccountId> {
219 pub owner: Vec<Ownership<AccountId>>,
220 pub const_data: Vec<u8>,
221 pub variable_data: Vec<u8>,
222}
223
224// #[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
225// #[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
226// pub struct VestingItem<AccountId, Moment> {
227// pub sender: AccountId,
228// pub recipient: AccountId,
229// pub collection_id: CollectionId,
230// pub item_id: TokenId,
231// pub amount: u64,
232// pub vesting_date: Moment,
233// }
234
235#[derive(Encode, Decode, Debug, Clone, PartialEq)]
236#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
237pub struct CollectionLimits<BlockNumber: Encode + Decode> {
238 pub account_token_ownership_limit: u32,
239 pub sponsored_data_size: u32,
240 /// None - setVariableMetadata is not sponsored
241 /// Some(v) - setVariableMetadata is sponsored
242 /// if there is v block between txs
243 pub sponsored_data_rate_limit: Option<BlockNumber>,
244 pub token_limit: u32,
245
246 // Timeouts for item types in passed blocks
247 pub sponsor_transfer_timeout: u32,
248 pub owner_can_transfer: bool,
249 pub owner_can_destroy: bool,
250}
251
252impl<BlockNumber: Encode + Decode> Default for CollectionLimits<BlockNumber> {
253 fn default() -> Self {
254 Self {
255 account_token_ownership_limit: 10_000_000,
256 token_limit: u32::max_value(),
257 sponsored_data_size: u32::MAX,
258 sponsored_data_rate_limit: None,
259 sponsor_transfer_timeout: 14400,
260 owner_can_transfer: true,
261 owner_can_destroy: true
262 }
263 }
264}
265
266#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
267#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
268pub struct ChainLimits {
269 pub collection_numbers_limit: u32,
270 pub account_token_ownership_limit: u32,
271 pub collections_admins_limit: u64,
272 pub custom_data_limit: u32,
273
274 // Timeouts for item types in passed blocks
275 pub nft_sponsor_transfer_timeout: u32,
276 pub fungible_sponsor_transfer_timeout: u32,
277 pub refungible_sponsor_transfer_timeout: u32,
278
279 // Schema limits
280 pub offchain_schema_limit: u32,
281 pub variable_on_chain_schema_limit: u32,
282 pub const_on_chain_schema_limit: u32,
283}
28454
285pub trait WeightInfo {55pub trait WeightInfo {
286 fn create_collection() -> Weight;56 fn create_collection() -> Weight;
315 fn set_collection_limits() -> Weight;85 fn set_collection_limits() -> Weight;
316}86}
317
318#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
319#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
320pub struct CreateNftData {
321 pub const_data: Vec<u8>,
322 pub variable_data: Vec<u8>,
323}
324
325#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
326#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
327pub struct CreateFungibleData {
328 pub value: u128,
329}
330
331#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]
332#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
333pub struct CreateReFungibleData {
334 pub const_data: Vec<u8>,
335 pub variable_data: Vec<u8>,
336 pub pieces: u128,
337}
338
339#[derive(Encode, Decode, Debug, Clone, PartialEq)]
340#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
341pub enum CreateItemData {
342 NFT(CreateNftData),
343 Fungible(CreateFungibleData),
344 ReFungible(CreateReFungibleData),
345}
346
347impl CreateItemData {
348 pub fn len(&self) -> usize {
349 let len = match self {
350 CreateItemData::NFT(data) => data.variable_data.len() + data.const_data.len(),
351 CreateItemData::ReFungible(data) => data.variable_data.len() + data.const_data.len(),
352 _ => 0
353 };
354
355 return len;
356 }
357}
358
359impl From<CreateNftData> for CreateItemData {
360 fn from(item: CreateNftData) -> Self {
361 CreateItemData::NFT(item)
362 }
363}
364
365impl From<CreateReFungibleData> for CreateItemData {
366 fn from(item: CreateReFungibleData) -> Self {
367 CreateItemData::ReFungible(item)
368 }
369}
370
371impl From<CreateFungibleData> for CreateItemData {
372 fn from(item: CreateFungibleData) -> Self {
373 CreateItemData::Fungible(item)
374 }
375}
376
37787
378decl_error! {88decl_error! {
455 }165 }
456}166}
167
168pub struct CollectionHandle<T: system::Config> {
169 pub id: CollectionId,
170 pub collection: Collection<T>,
171}
172
173impl<T: frame_system::Config> Deref for CollectionHandle<T> {
174 type Target = Collection<T>;
175
176 fn deref(&self) -> &Self::Target {
177 &self.collection
178 }
179}
180
181impl<T: frame_system::Config> DerefMut for CollectionHandle<T> {
182 fn deref_mut(&mut self) -> &mut Self::Target {
183 &mut self.collection
184 }
185}
457186
458pub trait Config: system::Config + Sized + pallet_transaction_payment::Config + pallet_contracts::Config {187pub trait Config: system::Config + Sized {
459 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;188 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;
460189
461 /// Weight information for extrinsics in this pallet.190 /// Weight information for extrinsics in this pallet.
466 type TreasuryAccountId: Get<Self::AccountId>;195 type TreasuryAccountId: Get<Self::AccountId>;
467}196}
468
469#[cfg(feature = "runtime-benchmarks")]
470mod benchmarking;
471
472// #endregion
473197
474// # Used definitions198// # Used definitions
475//199//
2575 }2299 }
2576}2300}
25772301
2578////////////////////////////////////////////////////////////////////////////////////////////////////
2579// Economic models
2580// #region
2581
2582/// Fee multiplier.
2583pub type Multiplier = FixedU128;
2584
2585type BalanceOf<T> = <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::Balance;
2586
2587/// Require the transactor pay for themselves and maybe include a tip to gain additional priority
2588/// in the queue.
2589#[derive(Encode, Decode, Clone, Eq, PartialEq)]
2590pub struct ChargeTransactionPayment<T: Config>(#[codec(compact)] BalanceOf<T>);
2591
2592impl<T: Config + Send + Sync> sp_std::fmt::Debug
2593 for ChargeTransactionPayment<T>
2594{
2595 #[cfg(feature = "std")]
2596 fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
2597 write!(f, "ChargeTransactionPayment<{:?}>", self.0)
2598 }
2599 #[cfg(not(feature = "std"))]
2600 fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
2601 Ok(())
2602 }
2603}
2604
2605impl<T: Config> ChargeTransactionPayment<T>
2606where
2607 T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo> + IsSubType<Call<T>> + IsSubType<pallet_contracts::Call<T>>,
2608 BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,
2609 T::AccountId: AsRef<[u8]>,
2610 T::AccountId: UncheckedFrom<T::Hash>,
2611{
2612 fn traditional_fee(
2613 len: usize,
2614 info: &DispatchInfoOf<T::Call>,
2615 tip: BalanceOf<T>,
2616 ) -> BalanceOf<T>
2617 where
2618 T::Call: Dispatchable<Info = DispatchInfo>,
2619 {
2620 <pallet_transaction_payment::Module<T>>::compute_fee(len as u32, info, tip)
2621 }
2622
2623 fn get_priority(len: usize, info: &DispatchInfoOf<T::Call>, final_fee: BalanceOf<T>) -> TransactionPriority {
2624 let weight_saturation = T::BlockWeights::get().max_block / info.weight.max(1);
2625 let max_block_length = *T::BlockLength::get().max.get(DispatchClass::Normal);
2626 let len_saturation = max_block_length as u64 / (len as u64).max(1);
2627 let coefficient: BalanceOf<T> = weight_saturation
2628 .min(len_saturation)
2629 .saturated_into::<BalanceOf<T>>();
2630 final_fee
2631 .saturating_mul(coefficient)
2632 .saturated_into::<TransactionPriority>()
2633 }
2634
2635 fn withdraw_fee(
2636 &self,
2637 who: &T::AccountId,
2638 call: &T::Call,
2639 info: &DispatchInfoOf<T::Call>,
2640 len: usize,
2641 ) -> Result<
2642 (
2643 BalanceOf<T>,
2644 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,
2645 ),
2646 TransactionValidityError,
2647 > {
2648 let tip = self.0;
2649
2650 let fee = Self::traditional_fee(len, info, tip);
2651
2652 // Only mess with balances if fee is not zero.
2653 if fee.is_zero() {
2654 return <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(who, call, info, fee, tip)
2655 .map(|i| (fee, i));
2656 }
2657
2658 // Determine who is paying transaction fee based on ecnomic model
2659 // Parse call to extract collection ID and access collection sponsor
2660 let mut sponsor: Option<T::AccountId> = (|| match IsSubType::<Call<T>>::is_sub_type(call) {
2661 Some(Call::create_item(collection_id, _owner, _properties)) => {
2662 let collection = <CollectionById<T>>::get(collection_id)?;
2663
2664 // sponsor timeout
2665 let block_number = <system::Pallet<T>>::block_number() as T::BlockNumber;
2666
2667 let limit = collection.limits.sponsor_transfer_timeout;
2668 if <CreateItemBasket<T>>::contains_key((collection_id, &who)) {
2669 let last_tx_block = <CreateItemBasket<T>>::get((collection_id, &who));
2670 let limit_time = last_tx_block + limit.into();
2671 if block_number <= limit_time {
2672 return None;
2673 }
2674 }
2675 <CreateItemBasket<T>>::insert((collection_id, who.clone()), block_number);
2676
2677 // check free create limit
2678 if collection.limits.sponsored_data_size >= (_properties.len() as u32) {
2679 collection.sponsorship.sponsor()
2680 .cloned()
2681 } else {
2682 None
2683 }
2684 }
2685 Some(Call::transfer(_new_owner, collection_id, item_id, _value)) => {
2686 let collection = <CollectionById<T>>::get(collection_id)?;
2687
2688 let mut sponsor_transfer = false;
2689 if collection.sponsorship.confirmed() {
2690
2691 let collection_limits = collection.limits;
2692 let collection_mode = collection.mode;
2693
2694 // sponsor timeout
2695 let block_number = <system::Pallet<T>>::block_number() as T::BlockNumber;
2696 sponsor_transfer = match collection_mode {
2697 CollectionMode::NFT => {
2698
2699 // get correct limit
2700 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
2701 collection_limits.sponsor_transfer_timeout
2702 } else {
2703 ChainLimit::get().nft_sponsor_transfer_timeout
2704 };
2705
2706 let mut sponsored = true;
2707 if <NftTransferBasket<T>>::contains_key(collection_id, item_id) {
2708 let last_tx_block = <NftTransferBasket<T>>::get(collection_id, item_id);
2709 let limit_time = last_tx_block + limit.into();
2710 if block_number <= limit_time {
2711 sponsored = false;
2712 }
2713 }
2714 if sponsored {
2715 <NftTransferBasket<T>>::insert(collection_id, item_id, block_number);
2716 }
2717
2718 sponsored
2719 }
2720 CollectionMode::Fungible(_) => {
2721
2722 // get correct limit
2723 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
2724 collection_limits.sponsor_transfer_timeout
2725 } else {
2726 ChainLimit::get().fungible_sponsor_transfer_timeout
2727 };
2728
2729 let block_number = <system::Pallet<T>>::block_number() as T::BlockNumber;
2730 let mut sponsored = true;
2731 if <FungibleTransferBasket<T>>::contains_key(collection_id, who) {
2732 let last_tx_block = <FungibleTransferBasket<T>>::get(collection_id, who);
2733 let limit_time = last_tx_block + limit.into();
2734 if block_number <= limit_time {
2735 sponsored = false;
2736 }
2737 }
2738 if sponsored {
2739 <FungibleTransferBasket<T>>::insert(collection_id, who, block_number);
2740 }
2741
2742 sponsored
2743 }
2744 CollectionMode::ReFungible => {
2745
2746 // get correct limit
2747 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {
2748 collection_limits.sponsor_transfer_timeout
2749 } else {
2750 ChainLimit::get().refungible_sponsor_transfer_timeout
2751 };
2752
2753 let mut sponsored = true;
2754 if <ReFungibleTransferBasket<T>>::contains_key(collection_id, item_id) {
2755 let last_tx_block = <ReFungibleTransferBasket<T>>::get(collection_id, item_id);
2756 let limit_time = last_tx_block + limit.into();
2757 if block_number <= limit_time {
2758 sponsored = false;
2759 }
2760 }
2761 if sponsored {
2762 <ReFungibleTransferBasket<T>>::insert(collection_id, item_id, block_number);
2763 }
2764
2765 sponsored
2766 }
2767 _ => {
2768 false
2769 },
2770 };
2771 }
2772
2773 if !sponsor_transfer {
2774 None
2775 } else {
2776 collection.sponsorship.sponsor()
2777 .cloned()
2778 }
2779 }
2780
2781 Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {
2782 let mut sponsor_metadata_changes = false;
2783
2784 let collection = <CollectionById<T>>::get(collection_id)?;
2785
2786 if
2787 collection.sponsorship.confirmed() &&
2788 // Can't sponsor fungible collection, this tx will be rejected
2789 // as invalid
2790 !matches!(collection.mode, CollectionMode::Fungible(_)) &&
2791 data.len() <= collection.limits.sponsored_data_size as usize
2792 {
2793 if let Some(rate_limit) = collection.limits.sponsored_data_rate_limit {
2794 let block_number = <system::Pallet<T>>::block_number() as T::BlockNumber;
2795
2796 if <VariableMetaDataBasket<T>>::get(collection_id, item_id)
2797 .map(|last_block| block_number - last_block > rate_limit)
2798 .unwrap_or(true)
2799 {
2800 sponsor_metadata_changes = true;
2801 <VariableMetaDataBasket<T>>::insert(collection_id, item_id, block_number);
2802 }
2803 }
2804 }
2805
2806 if !sponsor_metadata_changes {
2807 None
2808 } else {
2809 collection.sponsorship.sponsor().cloned()
2810 }
2811 }
2812
2813 _ => None,
2814 })();
2815
2816 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {
2817 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {
2818
2819 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());
2820
2821 let owned_contract = <ContractOwner<T>>::get(called_contract.clone()).as_ref() == Some(who);
2822 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone());
2823
2824 if !owned_contract && white_list_enabled {
2825 if !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {
2826 return Err(InvalidTransaction::Call.into());
2827 }
2828 }
2829 },
2830 _ => {},
2831 }
2832
2833 // Sponsor smart contracts
2834 sponsor = sponsor.or_else(|| match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {
2835
2836 // On instantiation: set the contract owner
2837 Some(pallet_contracts::Call::instantiate(_endowment, _gas_limit, code_hash, _data, salt)) => {
2838
2839 let new_contract_address = <pallet_contracts::Pallet<T>>::contract_address(
2840 &who,
2841 code_hash,
2842 salt,
2843 );
2844 <ContractOwner<T>>::insert(new_contract_address.clone(), who.clone());
2845
2846 None
2847 },
2848
2849 // On instantiation with code: set the contract owner
2850 Some(pallet_contracts::Call::instantiate_with_code(_endowment, _gas_limit, _code, _data, _salt)) => {
2851
2852 let new_contract_address = <pallet_contracts::Pallet<T>>::contract_address(
2853 &who,
2854 &T::Hashing::hash(&_code),
2855 _salt,
2856 );
2857
2858 <ContractOwner<T>>::insert(new_contract_address.clone(), who.clone());
2859
2860 None
2861 }
2862
2863 // When the contract is called, check if the sponsoring is enabled and pay fees from contract endowment if it is
2864 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {
2865
2866 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());
2867
2868 let mut sponsor_transfer = false;
2869 if <ContractSponsoringRateLimit<T>>::contains_key(called_contract.clone()) {
2870 let last_tx_block = <ContractSponsorBasket<T>>::get((&called_contract, &who));
2871 let block_number = <system::Pallet<T>>::block_number() as T::BlockNumber;
2872 let rate_limit = <ContractSponsoringRateLimit<T>>::get(&called_contract);
2873 let limit_time = last_tx_block + rate_limit;
2874
2875 if block_number >= limit_time {
2876 <ContractSponsorBasket<T>>::insert((called_contract.clone(), who.clone()), block_number);
2877 sponsor_transfer = true;
2878 }
2879 } else {
2880 sponsor_transfer = false;
2881 }
2882
2883 if sponsor_transfer {
2884 if <ContractSelfSponsoring<T>>::contains_key(called_contract.clone()) {
2885 if <ContractSelfSponsoring<T>>::get(called_contract.clone()) {
2886 return Some(called_contract);
2887 }
2888 }
2889 }
2890
2891 None
2892 },
2893
2894 _ => None,
2895 });
2896
2897 let who_pays_fee = sponsor.unwrap_or_else(|| who.clone());
2898
2899 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(&who_pays_fee, call, info, fee, tip)
2900 .map(|i| (fee, i))
2901 }
2902}
2903
2904
2905impl<T: Config + Send + Sync> SignedExtension
2906 for ChargeTransactionPayment<T>
2907where
2908 BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,
2909 T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo> + IsSubType<Call<T>> + IsSubType<pallet_contracts::Call<T>>,
2910 T::AccountId: AsRef<[u8]>,
2911 T::AccountId: UncheckedFrom<T::Hash>,
2912{
2913 const IDENTIFIER: &'static str = "ChargeTransactionPayment";
2914 type AccountId = T::AccountId;
2915 type Call = T::Call;
2916 type AdditionalSigned = ();
2917 type Pre = (
2918 // tip
2919 BalanceOf<T>,
2920 // who pays fee
2921 Self::AccountId,
2922 // imbalance resulting from withdrawing the fee
2923 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,
2924 );
2925 fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {
2926 Ok(())
2927 }
2928
2929 fn validate(
2930 &self,
2931 who: &Self::AccountId,
2932 call: &Self::Call,
2933 info: &DispatchInfoOf<Self::Call>,
2934 len: usize,
2935 ) -> TransactionValidity {
2936 let (fee, _) = self.withdraw_fee(who, call, info, len)?;
2937 Ok(ValidTransaction {
2938 priority: Self::get_priority(len, info, fee),
2939 ..Default::default()
2940 })
2941 }
2942
2943 fn pre_dispatch(
2944 self,
2945 who: &Self::AccountId,
2946 call: &Self::Call,
2947 info: &DispatchInfoOf<Self::Call>,
2948 len: usize,
2949 ) -> Result<Self::Pre, TransactionValidityError> {
2950 let (_fee, imbalance) = self.withdraw_fee(who, call, info, len)?;
2951 Ok((self.0, who.clone(), imbalance))
2952 }
2953
2954 fn post_dispatch(
2955 pre: Self::Pre,
2956 info: &DispatchInfoOf<Self::Call>,
2957 post_info: &PostDispatchInfoOf<Self::Call>,
2958 len: usize,
2959 _result: &DispatchResult,
2960 ) -> Result<(), TransactionValidityError> {
2961 let (tip, who, imbalance) = pre;
2962 let actual_fee = pallet_transaction_payment::Module::<T>::compute_actual_fee(
2963 len as u32,
2964 info,
2965 post_info,
2966 tip,
2967 );
2968 <T as pallet_transaction_payment::Config>::OnChargeTransaction::correct_and_deposit_fee(&who, info, post_info, actual_fee, tip, imbalance)?;
2969 Ok(())
2970 }
2971}
2972
2973// #endregion
deletedpallets/nft/src/types.rsdiffbeforeafterboth

no changes

addedpallets/scheduler/Cargo.tomldiffbeforeafterboth

no changes

addedpallets/scheduler/README.mddiffbeforeafterboth

no changes

addedpallets/scheduler/src/benchmarking.rsdiffbeforeafterboth

no changes

addedpallets/scheduler/src/lib.rsdiffbeforeafterboth

no changes

addedpallets/scheduler/src/weights.rsdiffbeforeafterboth

no changes

addedprimitives/Cargo.tomldiffbeforeafterboth

no changes

addedprimitives/src/lib.rsdiffbeforeafterboth

no changes

modifiedruntime/Cargo.tomldiffbeforeafterboth
55 'pallet-vesting/std',55 'pallet-vesting/std',
56 'parachain-info/std',56 'parachain-info/std',
57 'serde',57 'serde',
58 'pallet-inflation/std',
59 'pallet-nft/std',
60 'pallet-scheduler/std',
61 'pallet-nft-charge-transaction/std',
62 'pallet-nft-transaction-payment/std',
63 'nft-data-structs/std',
58 'sp-api/std',64 'sp-api/std',
59 'sp-block-builder/std',65 'sp-block-builder/std',
60 "sp-consensus-aura/std",66 "sp-consensus-aura/std",
71 'xcm-builder/std',77 'xcm-builder/std',
72 'xcm-executor/std',78 'xcm-executor/std',
73
74 'pallet-inflation/std',
75 'pallet-nft/std',
76]79]
7780
78################################################################################81################################################################################
365[dependencies]368[dependencies]
366pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }369pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }
367pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }370pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }
371nft-data-structs = { path = '../primitives', default-features = false, version = '0.9.0' }
372pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }
373pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }
374pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }
368375
369################################################################################376################################################################################
370# Build Dependencies377# Build Dependencies
modifiedruntime/src/chain_extension.rsdiffbeforeafterboth
1717
18extern crate pallet_nft;18extern crate pallet_nft;
19pub use pallet_nft::*;19pub use pallet_nft::*;
20use nft_data_structs::*;
2021
21use crate::Vec;22use crate::Vec;
2223
8081
81pub type NftWeightInfoOf<C> = <C as pallet_nft::Config>::WeightInfo;82pub type NftWeightInfoOf<C> = <C as pallet_nft::Config>::WeightInfo;
8283
83impl<C: Config> ChainExtension<C> for NFTExtension {84impl<C: Config + pallet_contracts::Config> ChainExtension<C> for NFTExtension {
84 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>85 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>
85 where86 where
86 E: Ext<T = C>,87 E: Ext<T = C>,
modifiedruntime/src/lib.rsdiffbeforeafterboth
77
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 = "256"]10#![recursion_limit = "1024"]
1111
12// Make the WASM binary available.12// Make the WASM binary available.
13#[cfg(feature = "std")]13#[cfg(feature = "std")]
17use sp_core::{ crypto::KeyTypeId, OpaqueMetadata };17use sp_core::{ crypto::KeyTypeId, OpaqueMetadata };
18// #[cfg(any(feature = "std", test))]18// #[cfg(any(feature = "std", test))]
19// pub use sp_runtime::BuildStorage;19// pub use sp_runtime::BuildStorage;
20use sp_runtime::traits::{20
21 AccountIdLookup, AccountIdConversion, BlakeTwo256, Block as BlockT, ConvertInto, IdentifyAccount, Verify,
22};
23use sp_runtime::{21use sp_runtime::{
24 Permill, Perbill, Percent,22 Permill, Perbill, Percent,
25 create_runtime_str, generic, impl_opaque_keys,23 create_runtime_str, generic, impl_opaque_keys,
24 traits::{
25 AccountIdLookup, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount,
26 Verify, AccountIdConversion,
27 },
26 transaction_validity::{TransactionSource, TransactionValidity},28 transaction_validity::{TransactionSource, TransactionValidity},
27 ApplyExtrinsicResult, MultiSignature,29 ApplyExtrinsicResult, MultiSignature,
28};30};
51 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients53 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients
52 },54 },
53};55};
56use nft_data_structs::*;
54use pallet_contracts::weights::WeightInfo;57use pallet_contracts::weights::WeightInfo;
55// #[cfg(any(feature = "std", test))]58// #[cfg(any(feature = "std", test))]
56use frame_system::{59use frame_system::{
57 self as system,60 self as system,
58 EnsureRoot, 61 EnsureRoot, EnsureSigned,
59 limits::{BlockWeights, BlockLength},62 limits::{BlockWeights, BlockLength},
60};63};
61use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};64use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};
62use smallvec::smallvec;65use smallvec::smallvec;
66
67use sp_runtime::{
68 traits::{
69 Dispatchable,
70 },
71};
72use pallet_contracts::chain_extension::UncheckedFrom;
73
6374
64pub use pallet_timestamp::Call as TimestampCall;75pub use pallet_timestamp::Call as TimestampCall;
193 }204 }
194}205}
195
196// impl OnUnbalanced<NegativeImbalance> for DealWithFees {
197// fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item=NegativeImbalance>) {
198// if let Some(fees) = fees_then_tips.next() {
199// // for fees, 100% to treasury
200// let mut split = fees.ration(100, 0);
201// if let Some(tips) = fees_then_tips.next() {
202// // for tips, if any, 100% to treasury
203// tips.ration_merge_into(100, 0, &mut split);
204// }
205// Treasury::on_unbalanced(split.0);
206// // Author::on_unbalanced(split.1);
207// }
208// }
209// }
210206
211/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.207/// We assume that ~10% of the block weight is consumed by `on_initalize` handlers.
212/// This is used to limit the maximal weight of a single extrinsic.208/// This is used to limit the maximal weight of a single extrinsic.
657 type InflationBlockInterval = InflationBlockInterval;653 type InflationBlockInterval = InflationBlockInterval;
658}654}
655
656parameter_types! {
657 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *
658 RuntimeBlockWeights::get().max_block;
659 pub const MaxScheduledPerBlock: u32 = 50;
660}
661
662pub struct Sponsoring;
663impl SponsoringResolve<AccountId, Call> for Sponsoring {
664
665 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId>
666 where
667 Call: Dispatchable<Info=DispatchInfo>,
668 Call: IsSubType<pallet_nft::Call<Runtime>>,
669 Call: IsSubType<pallet_contracts::Call<Runtime>>,
670 AccountId: AsRef<[u8]>,
671 AccountId: UncheckedFrom<Hash>
672 {
673 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)
674 }
675}
676
677impl pallet_scheduler::Config for Runtime {
678 type Event = Event;
679 type Origin = Origin;
680 type PalletsOrigin = OriginCaller;
681 type Call = Call;
682 type MaximumWeight = MaximumSchedulerWeight;
683 type ScheduleOrigin = EnsureSigned<AccountId>;
684 type MaxScheduledPerBlock = MaxScheduledPerBlock;
685 type Sponsoring = Sponsoring;
686 type WeightInfo = ();
687}
688
689impl pallet_nft_transaction_payment::Config for Runtime {
690}
691
692impl pallet_nft_charge_transaction::Config for Runtime {
693}
659694
660construct_runtime!(695construct_runtime!(
661 pub enum Runtime where696 pub enum Runtime where
689 // Unique Pallets724 // Unique Pallets
690 Inflation: pallet_inflation::{Pallet, Call, Storage},725 Inflation: pallet_inflation::{Pallet, Call, Storage},
691 Nft: pallet_nft::{Pallet, Call, Config<T>, Storage, Event<T>},726 Nft: pallet_nft::{Pallet, Call, Config<T>, Storage, Event<T>},
727 Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
728 NftPayment: pallet_nft_transaction_payment::{Pallet, Call, Storage},
729 Charging: pallet_nft_charge_transaction::{Pallet, Call, Storage },
692 }730 }
693);731);
694732
710 system::CheckEra<Runtime>,748 system::CheckEra<Runtime>,
711 system::CheckNonce<Runtime>,749 system::CheckNonce<Runtime>,
712 system::CheckWeight<Runtime>,750 system::CheckWeight<Runtime>,
713 pallet_nft::ChargeTransactionPayment<Runtime>,751 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,
714);752);
715/// Unchecked extrinsic type as expected by this runtime.753/// Unchecked extrinsic type as expected by this runtime.
716pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;754pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;
modifiedtests/src/pallet-presence.test.tsdiffbeforeafterboth
1313
14// Pallets that must always be present14// Pallets that must always be present
15const requiredPallets = [15const requiredPallets = [
16 'nft', 'inflation', 'balances', 'contracts', 'randomnesscollectiveflip', 'system', 'timestamp', 'transactionpayment', 'treasury', 'vesting'16 'nft', 'inflation', 'balances', 'contracts', 'randomnesscollectiveflip', 'system', 'timestamp', 'transactionpayment', 'treasury', 'vesting',
17 'scheduler', 'nftpayment', 'charging'
17];18];
1819
19// Pallets that depend on consensus and governance configuration20// Pallets that depend on consensus and governance configuration
addedtests/src/scheduler.test.tsdiffbeforeafterboth

no changes

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
55
6import { ApiPromise, Keyring } from '@polkadot/api';6import { ApiPromise, Keyring } from '@polkadot/api';
7import { Enum, Struct } from '@polkadot/types/codec';7import { Enum, Struct } from '@polkadot/types/codec';
8import type { AccountId, EventRecord } from '@polkadot/types/interfaces';8import type { AccountId, BlockNumber, Call, EventRecord } from '@polkadot/types/interfaces';
9import { u128 } from '@polkadot/types/primitive';9import { u128 } from '@polkadot/types/primitive';
10import { IKeyringPair } from '@polkadot/types/types';10import { IKeyringPair } from '@polkadot/types/types';
11import { BigNumber } from 'bignumber.js';11import { BigNumber } from 'bignumber.js';
17import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';17import { default as usingApi, submitTransactionAsync, submitTransactionExpectFailAsync } from '../substrate/substrate-api';
18import { ICollectionInterface } from '../types';18import { ICollectionInterface } from '../types';
19import { hexToStr, strToUTF16, utf16ToStr } from './util';19import { hexToStr, strToUTF16, utf16ToStr } from './util';
20import { Compact, Option, Raw, Vec } from '@polkadot/types/codec';
21// import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicSignatureV1, ExtrinsicSignatureV2, ExtrinsicSignatureV3, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, Moment, MortalEra, MultiSignature, Origin, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, SignerPayload, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
2022
21chai.use(chaiAsPromised);23chai.use(chaiAsPromised);
22const expect = chai.expect;24const expect = chai.expect;
706 });708 });
707}709}
710
711async function getBlockNumber(api: ApiPromise): Promise<number> {
712 return new Promise<number>(async (resolve, reject) => {
713 const unsubscribe = await api.rpc.chain.subscribeNewHeads((head) => {
714 unsubscribe();
715 resolve(head.number.toNumber());
716 });
717 });
718}
719
720export async function
721scheduleTransferExpectSuccess(collectionId: number,
722 tokenId: number,
723 sender: IKeyringPair,
724 recipient: IKeyringPair,
725 value: number | bigint = 1,
726 type: string = 'NFT') {
727 await usingApi(async (api: ApiPromise) => {
728 let balanceBefore = new BN(0);
729
730
731 let blockNumber: number | undefined = await getBlockNumber(api);
732 let expectedBlockNumber = blockNumber + 2;
733
734 expect(blockNumber).to.be.greaterThan(0);
735 const transferTx = await api.tx.nft.transfer(recipient.address, collectionId, tokenId, value);
736 const scheduleTx = await api.tx.scheduler.schedule(expectedBlockNumber, null, 0, transferTx);
737
738 const events = await submitTransactionAsync(sender, scheduleTx);
739
740 const sponsorBalanceBefore = new BigNumber((await api.query.system.account(sender.address)).data.free.toString());
741 const recipientBalanceBefore = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
742
743 const nftItemDataBefore = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
744 expect(nftItemDataBefore.Owner.toString()).to.be.equal(sender.address);
745
746 // sleep for 2 blocks
747 await new Promise(resolve => setTimeout(resolve, 6000 * 2));
748
749 const sponsorBalanceAfter = new BigNumber((await api.query.system.account(sender.address)).data.free.toString());
750 const recipientBalanceAfter = new BigNumber((await api.query.system.account(recipient.address)).data.free.toString());
751
752 const nftItemData = (await api.query.nft.nftItemList(collectionId, tokenId)).toJSON() as unknown as ITokenDataType;
753 expect(nftItemData.Owner.toString()).to.be.equal(recipient.address);
754 expect(recipientBalanceAfter.toNumber()).to.be.equal(recipientBalanceBefore.toNumber());
755 });
756}
757
708758
709export async function759export async function