difftreelog
feat implement sponsoring primitive for contract helpers
in: master
2 files changed
pallets/contract-helpers/Cargo.tomldiffbeforeafterboth--- /dev/null
+++ b/pallets/contract-helpers/Cargo.toml
@@ -0,0 +1,32 @@
+[package]
+name = "pallet-contract-helpers"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '2.0.0'
+
+[dependencies.up-sponsorship]
+default-features = false
+path = '../../primitives/sponsorship'
+version = '0.1.0'
+
+[dependencies]
+frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.3' }
+frame-system = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.3' }
+pallet-contracts = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.3' }
+sp-runtime = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.3' }
+sp-std = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.3' }
+
+[features]
+default = ["std"]
+std = [
+ "frame-support/std",
+ "frame-system/std",
+ "pallet-contracts/std",
+ "sp-runtime/std",
+ "sp-std/std",
+]
\ No newline at end of file
pallets/contract-helpers/src/lib.rsdiffbeforeafterboth227 }227 }228 }228 }229229230 pub struct ContractSponsorshipHandler<T>(PhantomData<T>);231 impl<T, C> SponsorshipHandler<T::AccountId, C> for ContractSponsorshipHandler<T>232 where233 T: Config,234 C: IsSubType<pallet_contracts::Call<T>>,235 T::AccountId: UncheckedFrom<T::Hash>,236 T::AccountId: AsRef<[u8]>,237 {238 fn get_sponsor(who: &T::AccountId, call: &C) -> Option<T::AccountId> {239 match IsSubType::<pallet_contracts::Call<T>>::is_sub_type(call) {240 Some(pallet_contracts::Call::call(dest, _value, _gas_limit, _data)) => {241 let called_contract: T::AccountId =242 T::Lookup::lookup((*dest).clone()).unwrap_or_default();243 if <SelfSponsoring<T>>::get(&called_contract) {244 let last_tx_block = SponsorBasket::<T>::get(&called_contract, &who);245 let block_number =246 <frame_system::Pallet<T>>::block_number() as T::BlockNumber;247 let rate_limit = SponsoringRateLimit::<T>::get(&called_contract);248 let limit_time = last_tx_block + rate_limit;249250 if block_number >= limit_time {251 SponsorBasket::<T>::insert(&called_contract, who, block_number);252 return Some(called_contract);253 }254 }255 }256 _ => {}257 }258 None259 }260 }230}261}231262