git.delta.rocks / unique-network / refs/commits / 6cd8e0c2387a

difftreelog

Merge pull request #220 from UniqueNetwork/feature/core-195

Greg Zaitsev2021-11-02parents: #4ad4a0e #3f9a772.patch.diff
in: master
CORE-195. Sponsoring

13 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5090,10 +5090,10 @@
  "pallet-evm-transaction-payment",
  "pallet-inflation",
  "pallet-nft",
- "pallet-nft-charge-transaction",
  "pallet-nft-transaction-payment",
  "pallet-randomness-collective-flip",
  "pallet-sudo",
+ "pallet-template-charge-transaction",
  "pallet-timestamp",
  "pallet-transaction-payment",
  "pallet-transaction-payment-rpc-runtime-api",
@@ -6010,25 +6010,6 @@
  "sp-runtime",
  "sp-std",
  "up-sponsorship",
-]
-
-[[package]]
-name = "pallet-nft-charge-transaction"
-version = "3.0.0"
-dependencies = [
- "frame-benchmarking",
- "frame-support",
- "frame-system",
- "pallet-balances",
- "pallet-nft-transaction-payment",
- "pallet-transaction-payment",
- "parity-scale-codec",
- "scale-info",
- "serde",
- "sp-core",
- "sp-io",
- "sp-runtime",
- "sp-std",
 ]
 
 [[package]]
@@ -6271,6 +6252,26 @@
 ]
 
 [[package]]
+name = "pallet-template-charge-transaction"
+version = "3.0.0"
+source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#e5d3354ab68face1b2ef709dc7f629803f56598d"
+dependencies = [
+ "frame-benchmarking",
+ "frame-support",
+ "frame-system",
+ "pallet-balances",
+ "pallet-transaction-payment",
+ "parity-scale-codec",
+ "scale-info",
+ "serde",
+ "sp-core",
+ "sp-io",
+ "sp-runtime",
+ "sp-std",
+ "up-sponsorship",
+]
+
+[[package]]
 name = "pallet-timestamp"
 version = "4.0.0-dev"
 source = "git+https://github.com/paritytech/substrate.git?branch=polkadot-v0.9.12#d76f39995315ec36980908e4b99709bd14927044"
@@ -11597,7 +11598,7 @@
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "1f559b464de2e2bdabcac6a210d12e9b5a5973c251e102c44c585c71d51bd78e"
 dependencies = [
- "cfg-if 1.0.0",
+ "cfg-if 0.1.10",
  "rand 0.8.4",
  "static_assertions",
 ]
@@ -11717,6 +11718,7 @@
 [[package]]
 name = "up-sponsorship"
 version = "0.1.0"
+source = "git+https://github.com/UniqueNetwork/pallet-sponsoring#e5d3354ab68face1b2ef709dc7f629803f56598d"
 dependencies = [
  "impl-trait-for-tuples 0.2.1",
 ]
modifiedpallets/contract-helpers/Cargo.tomldiffbeforeafterboth
--- a/pallets/contract-helpers/Cargo.toml
+++ b/pallets/contract-helpers/Cargo.toml
@@ -9,11 +9,6 @@
 package = 'parity-scale-codec'
 version = '2.3.0'
 
-[dependencies.up-sponsorship]
-default-features = false
-path = '../../primitives/sponsorship'
-version = '0.1.0'
-
 [dependencies]
 scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
 frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
@@ -21,6 +16,7 @@
 pallet-contracts = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
 
 [features]
 default = ["std"]
modifiedpallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth
--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -13,7 +13,7 @@
 evm-coder = { default-features = false, path = '../../crates/evm-coder' }
 pallet-evm-coder-substrate = { default-features = false, path = '../../pallets/evm-coder-substrate' }
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-up-sponsorship = { default-features = false, path = '../../primitives/sponsorship' }
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
 log = "0.4.14"
 
 [dependencies.codec]
modifiedpallets/evm-transaction-payment/Cargo.tomldiffbeforeafterboth
--- a/pallets/evm-transaction-payment/Cargo.toml
+++ b/pallets/evm-transaction-payment/Cargo.toml
@@ -14,7 +14,7 @@
 pallet-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
 fp-evm = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
 pallet-ethereum = { default-features = false, git = "https://github.com/uniquenetwork/frontier.git", branch = "unique-polkadot-v0.9.12" }
-up-sponsorship = { default-features = false, path = '../../primitives/sponsorship' }
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
 
 [dependencies.codec]
 default-features = false
deletedpallets/nft-charge-transaction/Cargo.tomldiffbeforeafterboth
--- a/pallets/nft-charge-transaction/Cargo.toml
+++ /dev/null
@@ -1,50 +0,0 @@
-[package]
-authors = ['Substrate DevHub <https://github.com/substrate-developer-hub>']
-description = 'Unqiue pallet nft specific transaction payment'
-edition = '2018'
-homepage = 'https://substrate.io'
-license = 'Unlicense'
-name = 'pallet-nft-charge-transaction'
-repository = 'https://github.com/usetech-llc/nft_private/'
-version = '3.0.0'
-
-[package.metadata.docs.rs]
-targets = ['x86_64-unknown-linux-gnu']
-
-# alias "parity-scale-code" to "codec"
-[dependencies.codec]
-default-features = false
-features = ['derive']
-package = 'parity-scale-codec'
-version = '2.3.0'
-
-[dependencies]
-scale-info = { version = "1.0.0", default-features = false, features = ["derive"] }
-serde = { version = "1.0.130", default-features = false }
-frame-support = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-frame-system = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-pallet-balances = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-pallet-transaction-payment = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-sp-std = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-sp-core = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
-
-pallet-nft-transaction-payment = { default-features = false, path = "../nft-transaction-payment" }
-
-[features]
-default = ['std']
-std = [
-    'codec/std',
-    'serde/std',
-    'frame-support/std',
-    'frame-system/std',
-    'pallet-balances/std',
-    'pallet-transaction-payment/std',
-    'pallet-nft-transaction-payment/std',
-    'sp-std/std',
-    'sp-runtime/std',
-    'frame-benchmarking/std',
-]
-runtime-benchmarks = ["frame-benchmarking"]
deletedpallets/nft-charge-transaction/src/lib.rsdiffbeforeafterboth
before · pallets/nft-charge-transaction/src/lib.rs
1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56#![cfg_attr(not(feature = "std"), no_std)]78#[cfg(feature = "std")]9pub use std::*;1011use scale_info::TypeInfo;12#[cfg(feature = "std")]13pub use serde::*;1415use codec::{Decode, Encode};16use frame_support::traits::Get;17use frame_support::{18	decl_module, decl_storage,19	weights::{DispatchInfo, PostDispatchInfo, DispatchClass},20};21use sp_runtime::{22	traits::{23		DispatchInfoOf, Dispatchable, PostDispatchInfoOf, Saturating, SaturatedConversion,24		SignedExtension, Zero,25	},26	transaction_validity::{27		TransactionPriority, TransactionValidity, TransactionValidityError, ValidTransaction,28	},29	FixedPointOperand, DispatchResult,30};31use pallet_transaction_payment::OnChargeTransaction;32use sp_std::prelude::*;3334pub trait Config: frame_system::Config + pallet_nft_transaction_payment::Config + TypeInfo {}3536decl_storage! {37	trait Store for Module<T: Config> as NftTransactionPayment38	{}39}4041decl_module! {4243	pub struct Module<T: Config> for enum Call44	where45		origin: T::Origin,46	{}47}4849type BalanceOf<T> = <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::Balance;5051/// Require the transactor pay for themselves and maybe include a tip to gain additional priority52/// in the queue.53#[derive(Encode, Decode, Clone, Eq, PartialEq, scale_info::TypeInfo)]54pub struct ChargeTransactionPayment<T: Config>(#[codec(compact)] BalanceOf<T>);5556impl<T: Config + Send + Sync> sp_std::fmt::Debug for ChargeTransactionPayment<T> {57	#[cfg(feature = "std")]58	fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {59		write!(f, "ChargeTransactionPayment<{:?}>", self.0)60	}61	#[cfg(not(feature = "std"))]62	fn fmt(&self, _: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {63		Ok(())64	}65}6667impl<T: Config> ChargeTransactionPayment<T>68where69	T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,70	BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,71{72	fn traditional_fee(73		len: usize,74		info: &DispatchInfoOf<T::Call>,75		tip: BalanceOf<T>,76	) -> BalanceOf<T>77	where78		T::Call: Dispatchable<Info = DispatchInfo>,79	{80		<pallet_transaction_payment::Pallet<T>>::compute_fee(len as u32, info, tip)81	}8283	fn get_priority(84		len: usize,85		info: &DispatchInfoOf<T::Call>,86		final_fee: BalanceOf<T>,87	) -> TransactionPriority {88		let weight_saturation = T::BlockWeights::get().max_block / info.weight.max(1);89		let max_block_length = *T::BlockLength::get().max.get(DispatchClass::Normal);90		let len_saturation = max_block_length as u64 / (len as u64).max(1);91		let coefficient: BalanceOf<T> = weight_saturation92			.min(len_saturation)93			.saturated_into::<BalanceOf<T>>();94		final_fee95			.saturating_mul(coefficient)96			.saturated_into::<TransactionPriority>()97	}9899	#[allow(clippy::type_complexity)]100    fn withdraw_fee(101        &self,102        who: &T::AccountId,103        call: &T::Call,104        info: &DispatchInfoOf<T::Call>,105        len: usize,106	) -> Result<107		(108			BalanceOf<T>,109			<<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,110		),111		TransactionValidityError,112	>{113		let tip = self.0;114115		let fee = Self::traditional_fee(len, info, tip);116117		// Only mess with balances if fee is not zero.118		if fee.is_zero() {119			return <<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(who, call, info, fee, tip)120			.map(|i| (fee, i));121		}122123		// Determine who is paying transaction fee based on ecnomic model124		// Parse call to extract collection ID and access collection sponsor125		let sponsor = <pallet_nft_transaction_payment::Module<T>>::withdraw_type(who, call);126127		let who_pays_fee = sponsor.unwrap_or_else(|| who.clone());128129		<<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::withdraw_fee(&who_pays_fee, call, info, fee, tip)130			.map(|i| (fee, i))131	}132}133134impl<T: Config + Send + Sync> SignedExtension for ChargeTransactionPayment<T>135where136	BalanceOf<T>: Send + Sync + From<u64> + FixedPointOperand,137	T::Call: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,138{139	const IDENTIFIER: &'static str = "ChargeTransactionPayment";140	type AccountId = T::AccountId;141	type Call = T::Call;142	type AdditionalSigned = ();143	type Pre = (144        // tip145        BalanceOf<T>,146        // who pays fee147        Self::AccountId,148		// imbalance resulting from withdrawing the fee149		<<T as pallet_transaction_payment::Config>::OnChargeTransaction as pallet_transaction_payment::OnChargeTransaction<T>>::LiquidityInfo,150    );151	fn additional_signed(&self) -> sp_std::result::Result<(), TransactionValidityError> {152		Ok(())153	}154155	fn validate(156		&self,157		who: &Self::AccountId,158		call: &Self::Call,159		info: &DispatchInfoOf<Self::Call>,160		len: usize,161	) -> TransactionValidity {162		let (fee, _) = self.withdraw_fee(who, call, info, len)?;163		Ok(ValidTransaction {164			priority: Self::get_priority(len, info, fee),165			..Default::default()166		})167	}168169	fn pre_dispatch(170		self,171		who: &Self::AccountId,172		call: &Self::Call,173		info: &DispatchInfoOf<Self::Call>,174		len: usize,175	) -> Result<Self::Pre, TransactionValidityError> {176		let (_fee, imbalance) = self.withdraw_fee(who, call, info, len)?;177		Ok((self.0, who.clone(), imbalance))178	}179180	fn post_dispatch(181		pre: Self::Pre,182		info: &DispatchInfoOf<Self::Call>,183		post_info: &PostDispatchInfoOf<Self::Call>,184		len: usize,185		_result: &DispatchResult,186	) -> Result<(), TransactionValidityError> {187		let (tip, who, imbalance) = pre;188		let actual_fee = pallet_transaction_payment::Pallet::<T>::compute_actual_fee(189			len as u32, info, post_info, tip,190		);191		<T as pallet_transaction_payment::Config>::OnChargeTransaction::correct_and_deposit_fee(192			&who, info, post_info, actual_fee, tip, imbalance,193		)?;194		Ok(())195	}196}
modifiedpallets/nft-transaction-payment/Cargo.tomldiffbeforeafterboth
--- a/pallets/nft-transaction-payment/Cargo.toml
+++ b/pallets/nft-transaction-payment/Cargo.toml
@@ -30,7 +30,7 @@
 sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 sp-runtime = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 
-up-sponsorship = { default-features = false, path = "../../primitives/sponsorship", version = "0.1.0" }
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
 
 [features]
 default = ['std']
modifiedpallets/nft/Cargo.tomldiffbeforeafterboth
--- a/pallets/nft/Cargo.toml
+++ b/pallets/nft/Cargo.toml
@@ -126,12 +126,6 @@
 path = '../../primitives/nft'
 version = '0.9.0'
 
-[dependencies.up-sponsorship]
-default-features = false
-path = '../../primitives/sponsorship'
-version = '0.1.0'
-
-
 [dependencies]
 scale-info = { version = "1.0.0", default-features = false, features = [
     "derive",
@@ -140,6 +134,8 @@
 rlp = { default-features = false, version = "0.5.0" }
 sp-api = { default-features = false, git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v0.9.12" }
 
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
+
 evm-coder = { default-features = false, path = "../../crates/evm-coder" }
 pallet-evm-coder-substrate = { default-features = false, path = "../../pallets/evm-coder-substrate" }
 primitive-types = { version = "0.10.1", default-features = false, features = [
modifiedpallets/scheduler/Cargo.tomldiffbeforeafterboth
--- a/pallets/scheduler/Cargo.toml
+++ b/pallets/scheduler/Cargo.toml
@@ -20,7 +20,7 @@
 sp-io = { default-features = false, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 frame-benchmarking = { default-features = false, optional = true, git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.12' }
 
-up-sponsorship = { default-features = false, path = "../../primitives/sponsorship", version = "0.1.0" }
+up-sponsorship = { version = "0.1.0", default-features = false, git = "https://github.com/UniqueNetwork/pallet-sponsoring" } 
 log = { version = "0.4.14", default-features = false }
 
 [dev-dependencies]
deletedprimitives/sponsorship/Cargo.tomldiffbeforeafterboth
--- a/primitives/sponsorship/Cargo.toml
+++ /dev/null
@@ -1,11 +0,0 @@
-[package]
-name = "up-sponsorship"
-version = "0.1.0"
-edition = "2018"
-
-[dependencies]
-impl-trait-for-tuples = "0.2.1"
-
-[features]
-default = ["std"]
-std = []
\ No newline at end of file
deletedprimitives/sponsorship/src/lib.rsdiffbeforeafterboth
--- a/primitives/sponsorship/src/lib.rs
+++ /dev/null
@@ -1,42 +0,0 @@
-#![no_std]
-
-pub trait SponsorshipHandler<AccountId, Call> {
-	fn get_sponsor(who: &AccountId, call: &Call) -> Option<AccountId>;
-}
-
-impl<A, C> SponsorshipHandler<A, C> for () {
-	fn get_sponsor(_who: &A, _call: &C) -> Option<A> {
-		None
-	}
-}
-
-macro_rules! impl_tuples {
-	($($ident:ident)+) => {
-		impl<AccountId, Call, $($ident),+> SponsorshipHandler<AccountId, Call> for ($($ident,)+)
-		where
-			$(
-				$ident: SponsorshipHandler<AccountId, Call>
-			),+
-		{
-			fn get_sponsor(who: &AccountId, call: &Call) -> Option<AccountId> {
-				$(
-					if let Some(account) = $ident::get_sponsor(who, call) {
-						return Some(account);
-					}
-				)+
-				None
-			}
-		}
-	}
-}
-
-impl_tuples! {A}
-impl_tuples! {A B}
-impl_tuples! {A B C}
-impl_tuples! {A B C D}
-impl_tuples! {A B C D E}
-impl_tuples! {A B C D E F}
-impl_tuples! {A B C D E F G}
-impl_tuples! {A B C D E F G H}
-impl_tuples! {A B C D E F G H I}
-impl_tuples! {A B C D E F G H I J}
modifiedruntime/Cargo.tomldiffbeforeafterboth
--- a/runtime/Cargo.toml
+++ b/runtime/Cargo.toml
@@ -379,7 +379,7 @@
 pallet-unq-scheduler = { path = '../pallets/scheduler', default-features = false, version = '3.0.0' }
 # pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }
 pallet-nft-transaction-payment = { path = '../pallets/nft-transaction-payment', default-features = false, version = '3.0.0' }
-pallet-nft-charge-transaction = { path = '../pallets/nft-charge-transaction', default-features = false, version = '3.0.0' }
+pallet-nft-charge-transaction = {git = "https://github.com/UniqueNetwork/pallet-sponsoring", package = "pallet-template-transaction-payment", default-features = false, version = '3.0.0' }
 pallet-evm-migration = { path = '../pallets/evm-migration', default-features = false }
 pallet-evm-contract-helpers = { path = '../pallets/evm-contract-helpers', default-features = false }
 pallet-evm-transaction-payment = { path = '../pallets/evm-transaction-payment', default-features = false }
modifiedruntime/src/lib.rsdiffbeforeafterboth
--- a/runtime/src/lib.rs
+++ b/runtime/src/lib.rs
@@ -802,7 +802,9 @@
 	type Currency = Balances;
 }
 
-impl pallet_nft_charge_transaction::Config for Runtime {}
+impl pallet_nft_charge_transaction::Config for Runtime {
+	type SponsorshipHandler = pallet_nft::NftSponsorshipHandler<Runtime>;
+}
 
 // impl pallet_contract_helpers::Config for Runtime {
 //	 type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;