difftreelog
Scheduler
in: master
22 files changed
Cargo.lockdiffbeforeafterboth3556 "futures 0.3.12",3556 "futures 0.3.12",3557 "jsonrpc-core",3557 "jsonrpc-core",3558 "log",3558 "log",3559 "nft-data-structs",3559 "nft-runtime",3560 "nft-runtime",3560 "pallet-contracts-rpc",3561 "pallet-contracts-rpc",3561 "pallet-transaction-payment-rpc",3562 "pallet-transaction-payment-rpc",3591 "substrate-frame-rpc-system",3592 "substrate-frame-rpc-system",3592]3593]35943595[[package]]3596name = "nft-data-structs"3597version = "0.9.0"3598dependencies = [3599 "frame-support",3600 "frame-system",3601 "pallet-contracts",3602 "parity-scale-codec",3603 "serde",3604 "sp-core",3605 "sp-runtime",3606]359336073594[[package]]3608[[package]]3595name = "nft-runtime"3609name = "nft-runtime"3602 "frame-system-benchmarking",3616 "frame-system-benchmarking",3603 "frame-system-rpc-runtime-api",3617 "frame-system-rpc-runtime-api",3604 "hex-literal",3618 "hex-literal",3619 "nft-data-structs",3605 "pallet-aura",3620 "pallet-aura",3606 "pallet-balances",3621 "pallet-balances",3607 "pallet-contracts",3622 "pallet-contracts",3610 "pallet-grandpa",3625 "pallet-grandpa",3611 "pallet-inflation",3626 "pallet-inflation",3612 "pallet-nft",3627 "pallet-nft",3628 "pallet-nft-charge-transaction",3629 "pallet-nft-transaction-payment",3613 "pallet-randomness-collective-flip",3630 "pallet-randomness-collective-flip",3631 "pallet-scheduler",3614 "pallet-sudo",3632 "pallet-sudo",3615 "pallet-timestamp",3633 "pallet-timestamp",3616 "pallet-transaction-payment",3634 "pallet-transaction-payment",3947 "frame-benchmarking",3965 "frame-benchmarking",3948 "frame-support",3966 "frame-support",3949 "frame-system",3967 "frame-system",3968 "nft-data-structs",3950 "pallet-balances",3969 "pallet-balances",3951 "pallet-contracts",3970 "pallet-contracts",3952 "pallet-randomness-collective-flip",3971 "pallet-randomness-collective-flip",3960 "sp-std",3979 "sp-std",3961]3980]39813982[[package]]3983name = "pallet-nft-charge-transaction"3984version = "3.0.0"3985dependencies = [3986 "frame-benchmarking",3987 "frame-support",3988 "frame-system",3989 "nft-data-structs",3990 "pallet-balances",3991 "pallet-contracts",3992 "pallet-nft",3993 "pallet-nft-transaction-payment",3994 "pallet-randomness-collective-flip",3995 "pallet-timestamp",3996 "pallet-transaction-payment",3997 "parity-scale-codec",3998 "serde",3999 "sp-core",4000 "sp-io",4001 "sp-runtime",4002 "sp-std",4003]40044005[[package]]4006name = "pallet-nft-transaction-payment"4007version = "3.0.0"4008dependencies = [4009 "frame-benchmarking",4010 "frame-support",4011 "frame-system",4012 "nft-data-structs",4013 "pallet-balances",4014 "pallet-contracts",4015 "pallet-nft",4016 "pallet-randomness-collective-flip",4017 "pallet-timestamp",4018 "pallet-transaction-payment",4019 "parity-scale-codec",4020 "serde",4021 "sp-core",4022 "sp-io",4023 "sp-runtime",4024 "sp-std",4025]396240263963[[package]]4027[[package]]3964name = "pallet-randomness-collective-flip"4028name = "pallet-randomness-collective-flip"3974 "sp-std",4038 "sp-std",3975]4039]40404041[[package]]4042name = "pallet-scheduler"4043version = "3.0.0"4044dependencies = [4045 "frame-benchmarking",4046 "frame-support",4047 "frame-system",4048 "log",4049 "nft-data-structs",4050 "pallet-contracts",4051 "pallet-nft",4052 "pallet-nft-transaction-payment",4053 "parity-scale-codec",4054 "serde",4055 "sp-core",4056 "sp-io",4057 "sp-runtime",4058 "sp-std",4059 "substrate-test-utils",4060]397640613977[[package]]4062[[package]]3978name = "pallet-session"4063name = "pallet-session"7315 "tokio 0.2.25",7400 "tokio 0.2.25",7316]7401]74027403[[package]]7404name = "substrate-test-utils"7405version = "3.0.0"7406source = "registry+https://github.com/rust-lang/crates.io-index"7407checksum = "6f46809281d923956cdfdb2f95e07fa2437884f2a18096c4371a3fa48f8d082a"7408dependencies = [7409 "futures 0.3.12",7410 "substrate-test-utils-derive",7411 "tokio 0.2.25",7412]74137414[[package]]7415name = "substrate-test-utils-derive"7416version = "0.9.0"7417source = "registry+https://github.com/rust-lang/crates.io-index"7418checksum = "988016ca49cfc763fecf97dfa9dee7dbbff1a2145b003d07681278dddefd1a0e"7419dependencies = [7420 "proc-macro-crate",7421 "quote",7422 "syn",7423]731774247318[[package]]7425[[package]]7319name = "substrate-wasm-builder"7426name = "substrate-wasm-builder"7550 "pin-project-lite 0.1.11",7657 "pin-project-lite 0.1.11",7551 "signal-hook-registry",7658 "signal-hook-registry",7552 "slab",7659 "slab",7660 "tokio-macros",7553 "winapi 0.3.9",7661 "winapi 0.3.9",7554]7662]755576637617 "log",7725 "log",7618]7726]77277728[[package]]7729name = "tokio-macros"7730version = "0.2.6"7731source = "registry+https://github.com/rust-lang/crates.io-index"7732checksum = "e44da00bfc73a25f814cd8d7e57a68a5c31b74b3152a0a1d1f590c97ed06265a"7733dependencies = [7734 "proc-macro2",7735 "quote",7736 "syn",7737]761977387620[[package]]7739[[package]]7621name = "tokio-named-pipes"7740name = "tokio-named-pipes"Cargo.tomldiffbeforeafterboth2members = [2members = [3 'node',3 'node',4 'pallets/nft',4 'pallets/nft',5 'pallets/nft-transaction-payment',6 'primitives',5 'runtime',7 'runtime',6]8]7[profile.release]9[profile.release]node/Cargo.tomldiffbeforeafterboth282829# Substrate dependencies29# Substrate dependencies30nft-runtime = { path = '../runtime', version = '3.0.0' }30nft-runtime = { path = '../runtime', version = '3.0.0' }31nft-data-structs = { default-features = false, path="../primitives" }31frame-benchmarking = '3.0.0'32frame-benchmarking = '3.0.0'32frame-benchmarking-cli = '3.0.0'33frame-benchmarking-cli = '3.0.0'33pallet-transaction-payment-rpc = '3.0.0'34pallet-transaction-payment-rpc = '3.0.0'node/src/chain_spec.rsdiffbeforeafterboth3// file 'LICENSE', which is part of this source code package.3// file 'LICENSE', which is part of this source code package.4//4//556// use nft_runtime::{7// AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,8// SystemConfig, WASM_BINARY,9// };10// use nft_runtime::{ContractsConfig, ContractsSchedule, NftConfig, CollectionType};11use nft_runtime::*;6use nft_runtime::*;7use nft_data_structs::*;12use sc_service::ChainType;8use sc_service::ChainType;13use sp_consensus_aura::sr25519::AuthorityId as AuraId;9use sp_consensus_aura::sr25519::AuthorityId as AuraId;14use sp_core::{sr25519, Pair, Public};10use sp_core::{sr25519, Pair, Public};15use sp_finality_grandpa::AuthorityId as GrandpaId;11use sp_finality_grandpa::AuthorityId as GrandpaId;16use sp_runtime::traits::{IdentifyAccount, Verify};12use sp_runtime::traits::{IdentifyAccount, Verify};17use serde_json::map::Map;13use serde_json::map::Map;18// use crate::chain_spec::api::chain_extension::*;191420// Note this is the URL for the telemetry server15// Note this is the URL for the telemetry server21//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";16//const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";158 balances: endowed_accounts153 balances: endowed_accounts159 .iter()154 .iter()160 .cloned()155 .cloned()161 .map(|k| (k, 1 << 100))156 .map(|k| (k, 1 << 70))162 .collect(),157 .collect(),163 }),158 }),164 pallet_aura: Some(AuraConfig {159 pallet_aura: Some(AuraConfig {pallets/nft-charge-transaction/Cargo.tomldiffbeforeafterbothno changes
pallets/nft-charge-transaction/src/lib.rsdiffbeforeafterbothno changes
pallets/nft-transaction-payment/Cargo.tomldiffbeforeafterbothno changes
pallets/nft-transaction-payment/src/benchmarking.rsdiffbeforeafterbothno changes
pallets/nft-transaction-payment/src/lib.rsdiffbeforeafterbothno changes
pallets/nft-transaction-payment/src/tests.rsdiffbeforeafterbothno changes
pallets/nft/Cargo.tomldiffbeforeafterboth32sp-runtime = { default-features = false, version = '3.0.0' }32sp-runtime = { default-features = false, version = '3.0.0' }33pallet-contracts = { default-features = false, version = '3.0.0' }33pallet-contracts = { default-features = false, version = '3.0.0' }34pallet-transaction-payment = { default-features = false, version = "3.0.0" }34pallet-transaction-payment = { default-features = false, version = "3.0.0" }35nft-data-structs = { default-features = false, path="../../primitives" }36353736[features]38[features]45 'pallet-contracts/std',47 'pallet-contracts/std',46 'pallet-randomness-collective-flip/std',48 'pallet-randomness-collective-flip/std',47 'pallet-transaction-payment/std',49 'pallet-transaction-payment/std',50 'nft-data-structs/std',48 'sp-std/std',51 'sp-std/std',49 'sp-runtime/std',52 'sp-runtime/std',50 'frame-benchmarking/std',53 'frame-benchmarking/std',pallets/nft/src/lib.rsdiffbeforeafterboth13#[cfg(feature = "std")]13#[cfg(feature = "std")]14pub use serde::*;14pub use serde::*;151516use 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,343235use 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;37use sp_runtime::{35use nft_data_structs::{38 traits::{39 Hash, DispatchInfoOf, Dispatchable, PostDispatchInfoOf, Saturating, SaturatedConversion, SignedExtension, Zero,36 MAX_DECIMAL_POINTS, MAX_SPONSOR_TIMEOUT, MAX_TOKEN_OWNERSHIP, MAX_REFUNGIBLE_PIECES,40 },37 AccessMode, ChainLimits, Collection, CreateItemData, CollectionLimits,41 transaction_validity::{42 TransactionPriority, InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransaction,38 CollectionId, CollectionMode, CollectionHandle, TokenId, 43 },39 SchemaVersion, SponsorshipState, Ownership,44 FixedPointOperand, FixedU128,40 NftItemType, FungibleItemType, ReFungibleItemType45};41};46use sp_runtime::traits::StaticLookup;47use pallet_contracts::chain_extension::UncheckedFrom;48use pallet_transaction_payment::OnChargeTransaction;494250#[cfg(test)]43#[cfg(test)]51mod mock;44mod mock;554856mod default_weights;49mod default_weights;5758pub 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;6263// Structs64// #region6566pub type CollectionId = u32;67pub type TokenId = u32;68pub type DecimalPoints = u8;6970#[derive(Encode, Decode, Eq, Debug, Clone, PartialEq)]71#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]72pub enum CollectionMode {73 Invalid,74 NFT,75 // decimal points76 Fungible(DecimalPoints),77 ReFungible,78}7980impl Default for CollectionMode {81 fn default() -> Self {82 Self::Invalid83 }84}8586impl 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}9697#[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::Normal106 }107}108109#[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::ImageURL118 }119}120121#[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}127128#[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 sender132 Disabled,133 Unconfirmed(AccountId),134 /// Transactions are sponsored by specified account135 Confirmed(AccountId),136}137138impl<AccountId> SponsorshipState<AccountId> {139 fn sponsor(&self) -> Option<&AccountId> {140 match self {141 Self::Confirmed(sponsor) => Some(sponsor),142 _ => None,143 }144 }145146 fn pending_sponsor(&self) -> Option<&AccountId> {147 match self {148 Self::Unconfirmed(sponsor) | Self::Confirmed(sponsor) => Some(sponsor),149 _ => None,150 }151 }152153 fn confirmed(&self) -> bool {154 matches!(self, Self::Confirmed(_))155 }156}157158impl<T> Default for SponsorshipState<T> {159 fn default() -> Self {160 Self::Disabled161 }162}16350164#[derive(Encode, Decode, Clone, PartialEq)]51#[cfg(feature = "runtime-benchmarks")]165#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]52mod 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 char172 pub description: Vec<u16>, // 256 include null escape char173 pub token_prefix: Vec<u8>, // 16 include null escape char174 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}182183pub struct CollectionHandle<T: Config> {184 pub id: CollectionId,185 collection: Collection<T>,186}187188impl<T: Config> Deref for CollectionHandle<T> {189 type Target = Collection<T>;190191 fn deref(&self) -> &Self::Target {192 &self.collection193 }194}195196impl<T: Config> DerefMut for CollectionHandle<T> {197 fn deref_mut(&mut self) -> &mut Self::Target {198 &mut self.collection199 }200}201202#[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}209210#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]211#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]212pub struct FungibleItemType {213 pub value: u128,214}215216#[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}223224// #[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// }234235#[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 sponsored241 /// Some(v) - setVariableMetadata is sponsored 242 /// if there is v block between txs243 pub sponsored_data_rate_limit: Option<BlockNumber>,244 pub token_limit: u32,245246 // Timeouts for item types in passed blocks247 pub sponsor_transfer_timeout: u32,248 pub owner_can_transfer: bool,249 pub owner_can_destroy: bool,250}251252impl<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: true262 }263 }264}265266#[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,273274 // Timeouts for item types in passed blocks275 pub nft_sponsor_transfer_timeout: u32,276 pub fungible_sponsor_transfer_timeout: u32,277 pub refungible_sponsor_transfer_timeout: u32,278279 // Schema limits280 pub offchain_schema_limit: u32,281 pub variable_on_chain_schema_limit: u32,282 pub const_on_chain_schema_limit: u32,283}28453285pub trait WeightInfo {54pub trait WeightInfo {286 fn create_collection() -> Weight;55 fn create_collection() -> Weight;315 fn set_collection_limits() -> Weight;84 fn set_collection_limits() -> Weight;316}85}317318#[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}324325#[derive(Encode, Decode, Default, Debug, Clone, PartialEq)]326#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]327pub struct CreateFungibleData {328 pub value: u128,329}330331#[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}338339#[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}346347impl 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 _ => 0353 };354 355 return len;356 }357}358359impl From<CreateNftData> for CreateItemData {360 fn from(item: CreateNftData) -> Self {361 CreateItemData::NFT(item)362 }363}364365impl From<CreateReFungibleData> for CreateItemData {366 fn from(item: CreateReFungibleData) -> Self {367 CreateItemData::ReFungible(item)368 }369}370371impl From<CreateFungibleData> for CreateItemData {372 fn from(item: CreateFungibleData) -> Self {373 CreateItemData::Fungible(item)374 }375}37637786378decl_error! {87decl_error! {455 }164 }456}165}166167// + pallet_transaction_payment::Config + pallet_nft_transaction_payment::Config + pallet_contracts::Config168457169458pub trait Config: system::Config + Sized + pallet_transaction_payment::Config + pallet_contracts::Config {170pub trait Config: system::Config + Sized {459 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;171 type Event: From<Event<Self>> + Into<<Self as system::Config>::Event>;460172461 /// Weight information for extrinsics in this pallet.173 /// Weight information for extrinsics in this pallet.466 type TreasuryAccountId: Get<Self::AccountId>;178 type TreasuryAccountId: Get<Self::AccountId>;467}179}468469#[cfg(feature = "runtime-benchmarks")]470mod benchmarking;471472// #endregion473180474// # Used definitions181// # Used definitions475//182//677 fn deposit_event() = default;384 fn deposit_event() = default;678 type Error = Error<T>;385 type Error = Error<T>;679386680 fn on_initialize(now: T::BlockNumber) -> Weight {387 fn on_initialize(_now: T::BlockNumber) -> Weight {681 0388 0682 }389 }6833902488 }2195 }2489}2196}249021972491////////////////////////////////////////////////////////////////////////////////////////////////////2492// Economic models2493// #region24942495/// Fee multiplier.2496pub type Multiplier = FixedU128;24972498type BalanceOf<T> = <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::Balance;24992500/// Require the transactor pay for themselves and maybe include a tip to gain additional priority2501/// in the queue.2502#[derive(Encode, Decode, Clone, Eq, PartialEq)]2503pub struct ChargeTransactionPayment<T: Config>(#[codec(compact)] BalanceOf<T>);25042505impl<T: Config + Send + Sync> sp_std::fmt::Debug 2506 for ChargeTransactionPayment<T>2507{2508 #[cfg(feature = "std")]2509 fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {2510 write!(f, "ChargeTransactionPayment<{:?}>", self.0)2511 }2512 #[cfg(not(feature = "std"))]2513 fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {2514 Ok(())2515 }2516}25172518impl<T: Config> ChargeTransactionPayment<T>2519where2520 T::Call: Dispatchable<Info=DispatchInfo, PostInfo=PostDispatchInfo> + IsSubType<Call<T>> + IsSubType<pallet_contracts::Call<T>>,2521 BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,2522 T::AccountId: AsRef<[u8]>,2523 T::AccountId: UncheckedFrom<T::Hash>,2524{2525 fn traditional_fee(2526 len: usize,2527 info: &DispatchInfoOf<T::Call>,2528 tip: BalanceOf<T>,2529 ) -> BalanceOf<T>2530 where2531 T::Call: Dispatchable<Info = DispatchInfo>,2532 {2533 <pallet_transaction_payment::Module<T>>::compute_fee(len as u32, info, tip)2534 }25352536 fn get_priority(len: usize, info: &DispatchInfoOf<T::Call>, final_fee: BalanceOf<T>) -> TransactionPriority {2537 let weight_saturation = T::BlockWeights::get().max_block / info.weight.max(1);2538 let max_block_length = *T::BlockLength::get().max.get(DispatchClass::Normal);2539 let len_saturation = max_block_length as u64 / (len as u64).max(1);2540 let coefficient: BalanceOf<T> = weight_saturation2541 .min(len_saturation)2542 .saturated_into::<BalanceOf<T>>();2543 final_fee2544 .saturating_mul(coefficient)2545 .saturated_into::<TransactionPriority>()2546 }25472548 fn withdraw_fee(2549 &self,2550 who: &T::AccountId,2551 call: &T::Call,2552 info: &DispatchInfoOf<T::Call>,2553 len: usize,2554 ) -> Result<2555 (2556 BalanceOf<T>,2557 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,2558 ),2559 TransactionValidityError,2560 > {2561 let tip = self.0;25622563 let fee = Self::traditional_fee(len, info, tip);25642565 // Only mess with balances if fee is not zero.2566 if fee.is_zero() {2567 return <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(who, call, info, fee, tip)2568 .map(|i| (fee, i));2569 }25702571 // Determine who is paying transaction fee based on ecnomic model2572 // Parse call to extract collection ID and access collection sponsor2573 let mut sponsor: Option<T::AccountId> = (|| match IsSubType::<Call<T>>::is_sub_type(call) {2574 Some(Call::create_item(collection_id, _owner, _properties)) => {2575 let collection = <CollectionById<T>>::get(collection_id)?;25762577 // sponsor timeout2578 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;25792580 let limit = collection.limits.sponsor_transfer_timeout;2581 if <CreateItemBasket<T>>::contains_key((collection_id, &who)) {2582 let last_tx_block = <CreateItemBasket<T>>::get((collection_id, &who));2583 let limit_time = last_tx_block + limit.into();2584 if block_number <= limit_time {2585 return None;2586 }2587 }2588 <CreateItemBasket<T>>::insert((collection_id, who.clone()), block_number);25892590 // check free create limit2591 if collection.limits.sponsored_data_size >= (_properties.len() as u32) {2592 collection.sponsorship.sponsor()2593 .cloned()2594 } else {2595 None2596 }2597 }2598 Some(Call::transfer(_new_owner, collection_id, item_id, _value)) => {2599 let collection = <CollectionById<T>>::get(collection_id)?;2600 2601 let mut sponsor_transfer = false;2602 if collection.sponsorship.confirmed() {26032604 let collection_limits = collection.limits;2605 let collection_mode = collection.mode;2606 2607 // sponsor timeout2608 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2609 sponsor_transfer = match collection_mode {2610 CollectionMode::NFT => {2611 2612 // get correct limit2613 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {2614 collection_limits.sponsor_transfer_timeout2615 } else {2616 ChainLimit::get().nft_sponsor_transfer_timeout2617 };2618 2619 let mut sponsored = true;2620 if <NftTransferBasket<T>>::contains_key(collection_id, item_id) {2621 let last_tx_block = <NftTransferBasket<T>>::get(collection_id, item_id);2622 let limit_time = last_tx_block + limit.into();2623 if block_number <= limit_time {2624 sponsored = false;2625 }2626 }2627 if sponsored {2628 <NftTransferBasket<T>>::insert(collection_id, item_id, block_number);2629 }26302631 sponsored2632 }2633 CollectionMode::Fungible(_) => {2634 2635 // get correct limit2636 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {2637 collection_limits.sponsor_transfer_timeout2638 } else {2639 ChainLimit::get().fungible_sponsor_transfer_timeout2640 };2641 2642 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2643 let mut sponsored = true;2644 if <FungibleTransferBasket<T>>::contains_key(collection_id, who) {2645 let last_tx_block = <FungibleTransferBasket<T>>::get(collection_id, who);2646 let limit_time = last_tx_block + limit.into();2647 if block_number <= limit_time {2648 sponsored = false;2649 }2650 }2651 if sponsored {2652 <FungibleTransferBasket<T>>::insert(collection_id, who, block_number);2653 }26542655 sponsored2656 }2657 CollectionMode::ReFungible => {2658 2659 // get correct limit2660 let limit: u32 = if collection_limits.sponsor_transfer_timeout > 0 {2661 collection_limits.sponsor_transfer_timeout2662 } else {2663 ChainLimit::get().refungible_sponsor_transfer_timeout2664 };2665 2666 let mut sponsored = true;2667 if <ReFungibleTransferBasket<T>>::contains_key(collection_id, item_id) {2668 let last_tx_block = <ReFungibleTransferBasket<T>>::get(collection_id, item_id);2669 let limit_time = last_tx_block + limit.into();2670 if block_number <= limit_time {2671 sponsored = false;2672 }2673 }2674 if sponsored {2675 <ReFungibleTransferBasket<T>>::insert(collection_id, item_id, block_number);2676 }26772678 sponsored2679 }2680 _ => {2681 false2682 },2683 };2684 }26852686 if !sponsor_transfer {2687 None2688 } else {2689 collection.sponsorship.sponsor()2690 .cloned()2691 }2692 }26932694 Some(Call::set_variable_meta_data(collection_id, item_id, data)) => {2695 let mut sponsor_metadata_changes = false;26962697 let collection = <CollectionById<T>>::get(collection_id)?;26982699 if2700 collection.sponsorship.confirmed() &&2701 // Can't sponsor fungible collection, this tx will be rejected2702 // as invalid2703 !matches!(collection.mode, CollectionMode::Fungible(_)) &&2704 data.len() <= collection.limits.sponsored_data_size as usize2705 {2706 if let Some(rate_limit) = collection.limits.sponsored_data_rate_limit {2707 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;27082709 if <VariableMetaDataBasket<T>>::get(collection_id, item_id)2710 .map(|last_block| block_number - last_block > rate_limit)2711 .unwrap_or(true) 2712 {2713 sponsor_metadata_changes = true;2714 <VariableMetaDataBasket<T>>::insert(collection_id, item_id, block_number);2715 }2716 }2717 }27182719 if !sponsor_metadata_changes {2720 None2721 } else {2722 collection.sponsorship.sponsor().cloned()2723 }2724 }27252726 _ => None,2727 })();27282729 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {2730 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {27312732 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());27332734 let owned_contract = <ContractOwner<T>>::get(called_contract.clone()).as_ref() == Some(who);2735 let white_list_enabled = <ContractWhiteListEnabled<T>>::contains_key(called_contract.clone());2736 2737 if !owned_contract && white_list_enabled {2738 if !<ContractWhiteList<T>>::contains_key(called_contract.clone(), who) {2739 return Err(InvalidTransaction::Call.into());2740 }2741 }2742 },2743 _ => {},2744 }27452746 // Sponsor smart contracts2747 sponsor = sponsor.or_else(|| match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {27482749 // On instantiation: set the contract owner2750 Some(pallet_contracts::Call::instantiate(_endowment, _gas_limit, code_hash, _data, salt)) => {27512752 let new_contract_address = <pallet_contracts::Module<T>>::contract_address(2753 &who,2754 code_hash,2755 salt,2756 );2757 <ContractOwner<T>>::insert(new_contract_address.clone(), who.clone());27582759 None2760 },27612762 // On instantiation with code: set the contract owner2763 Some(pallet_contracts::Call::instantiate_with_code(_endowment, _gas_limit, _code, _data, _salt)) => {27642765 let new_contract_address = <pallet_contracts::Module<T>>::contract_address(2766 &who,2767 &T::Hashing::hash(&_code),2768 _salt,2769 );27702771 <ContractOwner<T>>::insert(new_contract_address.clone(), who.clone());27722773 None2774 }27752776 // When the contract is called, check if the sponsoring is enabled and pay fees from contract endowment if it is2777 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {27782779 let called_contract: T::AccountId = T::Lookup::lookup((*dest).clone()).unwrap_or(T::AccountId::default());27802781 let mut sponsor_transfer = false;2782 if <ContractSponsoringRateLimit<T>>::contains_key(called_contract.clone()) {2783 let last_tx_block = <ContractSponsorBasket<T>>::get((&called_contract, &who));2784 let block_number = <system::Module<T>>::block_number() as T::BlockNumber;2785 let rate_limit = <ContractSponsoringRateLimit<T>>::get(&called_contract);2786 let limit_time = last_tx_block + rate_limit;27872788 if block_number >= limit_time {2789 <ContractSponsorBasket<T>>::insert((called_contract.clone(), who.clone()), block_number);2790 sponsor_transfer = true;2791 }2792 } else {2793 sponsor_transfer = false;2794 }2795 2796 if sponsor_transfer {2797 if <ContractSelfSponsoring<T>>::contains_key(called_contract.clone()) {2798 if <ContractSelfSponsoring<T>>::get(called_contract.clone()) {2799 return Some(called_contract);2800 }2801 }2802 }28032804 None2805 },28062807 _ => None,2808 });28092810 let who_pays_fee = sponsor.unwrap_or_else(|| who.clone());28112812 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(&who_pays_fee, call, info, fee, tip)2813 .map(|i| (fee, i))2814 }2815}281628172818impl<T: Config + Send + Sync> SignedExtension2819 for ChargeTransactionPayment<T>2820where2821 BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,2822 T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo> + IsSubType<Call<T>> + IsSubType<pallet_contracts::Call<T>>,2823 T::AccountId: AsRef<[u8]>,2824 T::AccountId: UncheckedFrom<T::Hash>,2825{2826 const IDENTIFIER: &'static str = "ChargeTransactionPayment";2827 type AccountId = T::AccountId;2828 type Call = T::Call;2829 type AdditionalSigned = ();2830 type Pre = (2831 // tip2832 BalanceOf<T>,2833 // who pays fee2834 Self::AccountId,2835 // imbalance resulting from withdrawing the fee2836 <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,2837 );2838 fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {2839 Ok(())2840 }28412842 fn validate(2843 &self,2844 who: &Self::AccountId,2845 call: &Self::Call,2846 info: &DispatchInfoOf<Self::Call>,2847 len: usize,2848 ) -> TransactionValidity {2849 let (fee, _) = self.withdraw_fee(who, call, info, len)?;2850 Ok(ValidTransaction {2851 priority: Self::get_priority(len, info, fee),2852 ..Default::default()2853 })2854 }28552856 fn pre_dispatch(2857 self,2858 who: &Self::AccountId,2859 call: &Self::Call,2860 info: &DispatchInfoOf<Self::Call>,2861 len: usize,2862 ) -> Result<Self::Pre, TransactionValidityError> {2863 let (_fee, imbalance) = self.withdraw_fee(who, call, info, len)?;2864 Ok((self.0, who.clone(), imbalance))2865 }28662867 fn post_dispatch(2868 pre: Self::Pre,2869 info: &DispatchInfoOf<Self::Call>,2870 post_info: &PostDispatchInfoOf<Self::Call>,2871 len: usize,2872 _result: &DispatchResult,2873 ) -> Result<(), TransactionValidityError> {2874 let (tip, who, imbalance) = pre;2875 let actual_fee = pallet_transaction_payment::Module::<T>::compute_actual_fee(2876 len as u32,2877 info,2878 post_info,2879 tip,2880 );2881 <T as pallet_transaction_payment::Config>::OnChargeTransaction::correct_and_deposit_fee(&who, info, post_info, actual_fee, tip, imbalance)?;2882 Ok(())2883 }2884}28852886// #endregionpallets/scheduler/Cargo.tomldiffbeforeafterbothno changes
pallets/scheduler/README.mddiffbeforeafterbothno changes
pallets/scheduler/src/benchmarking.rsdiffbeforeafterbothno changes
pallets/scheduler/src/lib.rsdiffbeforeafterbothno changes
pallets/scheduler/src/weights.rsdiffbeforeafterbothno changes
primitives/Cargo.tomldiffbeforeafterbothno changes
primitives/src/lib.rsdiffbeforeafterbothno changes
runtime/Cargo.tomldiffbeforeafterboth262627# local dependencies27# local dependencies28pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }28pallet-nft = { path = '../pallets/nft', default-features = false, version = '3.0.0' }29nft-data-structs = { path = '../primitives', default-features = false }29pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }30pallet-inflation = { path = '../pallets/inflation', default-features = false, version = '3.0.0' }31pallet-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }32pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }33pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }303431# Substrate dependencies35# Substrate dependencies32frame-benchmarking = { default-features = false, optional = true, version = '3.0.0' }36frame-benchmarking = { default-features = false, optional = true, version = '3.0.0' }99100 'pallet-inflation/std',103 'pallet-inflation/std',101 'pallet-nft/std',104 'pallet-nft/std',105 'pallet-scheduler/std',106 'pallet-nft-charge-transaction/std',107 'pallet-nft-transaction-payment/std', 108 'nft-data-structs/std',102 'sp-api/std',109 'sp-api/std',103 'sp-block-builder/std',110 'sp-block-builder/std',104 'sp-consensus-aura/std',111 'sp-consensus-aura/std',runtime/src/chain_extension.rsdiffbeforeafterboth171718extern crate pallet_nft;18extern crate pallet_nft;19pub use pallet_nft::*;19pub use pallet_nft::*;20use crate::Runtime;20use nft_data_structs::*;21// use crate::Runtime;21use sp_runtime::AccountId32;22use sp_runtime::AccountId32;22use crate::Vec;23use crate::Vec;232441/// The chain Extension of NFT pallet42/// The chain Extension of NFT pallet42pub struct NFTExtension;43pub struct NFTExtension;434444impl<C: Config> ChainExtension<C> for NFTExtension {45impl<C: Config + pallet_contracts::Config> ChainExtension<C> for NFTExtension {45 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>46 fn call<E: Ext>(func_id: u32, env: Environment<E, InitState>) -> Result<RetVal, DispatchError>46 where47 where47 E: Ext<T = C>,48 E: Ext<T = C>,runtime/src/lib.rsdiffbeforeafterboth51 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients51 WeightToFeePolynomial, WeightToFeeCoefficient, WeightToFeeCoefficients52 },52 },53};53};54use pallet_nft_transaction_payment::*;55use pallet_nft_charge_transaction::*;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_std::{prelude::*, marker::PhantomData};64use sp_std::{prelude::*, marker::PhantomData};62use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};65use sp_arithmetic::{traits::{BaseArithmetic, Unsigned}};63use smallvec::smallvec;66use smallvec::smallvec;6768use sp_runtime::{69 traits::{ 70 Dispatchable,71 },72};73use pallet_contracts::chain_extension::UncheckedFrom;74647565pub use pallet_timestamp::Call as TimestampCall;76pub use pallet_timestamp::Call as TimestampCall;175 }186 }176}187}177178/// Provides a membership set with only the configured aura users179pub struct ValiudatorsOnly<Runtime: pallet_aura::Config>(PhantomData<Runtime>);180impl frame_support::traits::Contains<AccountId> for ValiudatorsOnly<Runtime> {181 fn contains(t: &AccountId) -> bool {182 let arr: [u8; 32] = *t.as_ref();183 let raw_key: Vec<u8> = Vec::from(arr);184185 match pallet_aura::Module::<Runtime>::authorities().iter().find(|auth| auth.to_raw_vec() == raw_key) {186 Some(_) => true,187 None => false,188 } 189 }190 fn sorted_members() -> Vec<AccountId> {191 let mut members: Vec<AccountId> = Vec::new();192 for auth in pallet_aura::Module::<Runtime>::authorities() {193 let mut arr: [u8; 32] = Default::default(); 194 let bor_arr = auth.clone().to_raw_vec();195 let slice = bor_arr.as_slice();196 arr.copy_from_slice(slice);197 members.push(AccountId::from(arr));198 }199 members 200 }201 fn count() -> usize {202 pallet_aura::Module::<Runtime>::authorities().len()203 }204}205206impl frame_support::traits::ContainsLengthBound for ValiudatorsOnly<Runtime> {207 fn min_len() -> usize {208 1209 }210 fn max_len() -> usize {211 100212 }213}214188215type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;189type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;216190230 }204 }231}205}232233// impl OnUnbalanced<NegativeImbalance> for DealWithFees {234// fn on_unbalanceds<B>(mut fees_then_tips: impl Iterator<Item=NegativeImbalance>) {235// if let Some(fees) = fees_then_tips.next() {236// // for fees, 100% to treasury237// let mut split = fees.ration(100, 0);238// if let Some(tips) = fees_then_tips.next() {239// // for tips, if any, 100% to treasury240// tips.ration_merge_into(100, 0, &mut split);241// }242// Treasury::on_unbalanced(split.0);243// // Author::on_unbalanced(split.1);244// }245// }246// }247206248/// 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.249/// 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.550}509}510511512parameter_types! {513 pub MaximumSchedulerWeight: Weight = Perbill::from_percent(50) *514 RuntimeBlockWeights::get().max_block;515 pub const MaxScheduledPerBlock: u32 = 50;516}517518pub struct Sponsoring;519impl SponsoringResolve<AccountId, Call> for Sponsoring {520521 fn resolve(who: &AccountId, call: &Call) -> Option<AccountId> 522 where 523 Call: Dispatchable<Info=DispatchInfo>,524 Call: IsSubType<pallet_nft::Call<Runtime>>, 525 Call: IsSubType<pallet_contracts::Call<Runtime>>,526 AccountId: AsRef<[u8]>,527 AccountId: UncheckedFrom<Hash>528 {529 pallet_nft_transaction_payment::Module::<Runtime>::withdraw_type(who, call)530 }531}532533impl pallet_scheduler::Config for Runtime {534 type Event = Event;535 type Origin = Origin;536 type PalletsOrigin = OriginCaller;537 type Call = Call;538 type MaximumWeight = MaximumSchedulerWeight;539 type ScheduleOrigin = EnsureSigned<AccountId>;540 type MaxScheduledPerBlock = MaxScheduledPerBlock;541 type Sponsoring = Sponsoring;542 type WeightInfo = ();543}544545impl pallet_nft_transaction_payment::Config for Runtime {546}547548impl pallet_nft_charge_transaction::Config for Runtime {549}551550552construct_runtime!(551construct_runtime!(553 pub enum Runtime where552 pub enum Runtime where565 TransactionPayment: pallet_transaction_payment::{Module, Storage},564 TransactionPayment: pallet_transaction_payment::{Module, Storage},566 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},565 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},567 Inflation: pallet_inflation::{Module, Call, Storage},566 Inflation: pallet_inflation::{Module, Call, Storage},567 Scheduler: pallet_scheduler::{Module, Call, Storage, Event<T>},568 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},568 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},569 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},569 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},570 Vesting: pallet_vesting::{Module, Call, Config<T>, Storage, Event<T>},570 Vesting: pallet_vesting::{Module, Call, Config<T>, Storage, Event<T>},571 NftPayment: pallet_nft_transaction_payment::{Module, Call, Storage},572 Charging: pallet_nft_charge_transaction::{Module, Call, Storage },571 }573 }572);574);573575589 system::CheckEra<Runtime>,591 system::CheckEra<Runtime>,590 system::CheckNonce<Runtime>,592 system::CheckNonce<Runtime>,591 system::CheckWeight<Runtime>,593 system::CheckWeight<Runtime>,592 pallet_nft::ChargeTransactionPayment<Runtime>,594 pallet_nft_charge_transaction::ChargeTransactionPayment<Runtime>,593);595);594/// Unchecked extrinsic type as expected by this runtime.596/// Unchecked extrinsic type as expected by this runtime.595pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;597pub type UncheckedExtrinsic = generic::UncheckedExtrinsic<Address, Call, Signature, SignedExtra>;