git.delta.rocks / unique-network / refs/commits / 60ea0ef4a6b1

difftreelog

feat evm contract helpers pallet

Yaroslav Bolyukin2021-07-27parent: #026f1bb.patch.diff
in: master

5 files changed

addedpallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth
--- /dev/null
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -0,0 +1,36 @@
+[package]
+name = "pallet-evm-contract-helpers"
+version = "0.1.0"
+edition = "2018"
+
+[dependencies]
+frame-support = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+frame-system = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-runtime = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-std = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+sp-core = { default-features = false, version = '3.0.0', git = 'https://github.com/paritytech/substrate.git', branch = 'polkadot-v0.9.8' }
+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, version = "5.0.0-dev", git = "https://github.com/uniquenetwork/frontier.git", branch = "injected-transactions-parachain" }
+up-sponsorship = { default-features = false, path = '../../primitives/sponsorship' }
+log = "0.4.14"
+
+[dependencies.codec]
+default-features = false
+features = ['derive']
+package = 'parity-scale-codec'
+version = '2.0.0'
+
+[features]
+default = ["std"]
+std = [
+    "frame-support/std",
+    "frame-system/std",
+    "sp-runtime/std",
+    "sp-std/std",
+    "sp-core/std",
+    "evm-coder/std",
+    "pallet-evm-coder-substrate/std",
+    "pallet-evm/std",
+    "up-sponsorship/std",
+]
addedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth

no changes

addedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- /dev/null
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -0,0 +1,92 @@
+#![cfg_attr(not(feature = "std"), no_std)]
+
+pub use pallet::*;
+pub use eth::*;
+pub mod eth;
+
+#[frame_support::pallet]
+pub mod pallet {
+	use evm_coder::execution::Result;
+	use frame_support::pallet_prelude::*;
+	use pallet_evm::RawEvent;
+	use sp_core::H160;
+
+	#[pallet::config]
+	pub trait Config: frame_system::Config + pallet_evm_coder_substrate::Config {
+		type Event: From<Event<Self>> + IsType<<Self as frame_system::Config>::Event>;
+
+		type ContractAddress: Get<H160>;
+	}
+
+	#[pallet::error]
+	pub enum Error<T> {
+		/// This method is only executable by owner
+		NoPermission,
+	}
+
+	#[pallet::pallet]
+	#[pallet::generate_store(pub(super) trait Store)]
+	pub struct Pallet<T>(_);
+
+	#[pallet::storage]
+	pub(super) type Owner<T: Config> =
+		StorageMap<Hasher = Twox128, Key = H160, Value = H160, QueryKind = ValueQuery>;
+
+	#[pallet::storage]
+	pub(super) type SelfSponsoring<T: Config> =
+		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;
+
+	#[pallet::storage]
+	pub(super) type SponsoringRateLimit<T: Config> =
+		StorageMap<Hasher = Twox128, Key = H160, Value = T::BlockNumber, QueryKind = ValueQuery>;
+
+	#[pallet::storage]
+	pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<
+		Hasher1 = Twox128,
+		Key1 = H160,
+		Hasher2 = Twox128,
+		Key2 = H160,
+		Value = T::BlockNumber,
+		QueryKind = OptionQuery,
+	>;
+
+	#[pallet::storage]
+	pub(super) type AllowlistEnabled<T: Config> =
+		StorageMap<Hasher = Twox128, Key = H160, Value = bool, QueryKind = ValueQuery>;
+
+	#[pallet::storage]
+	pub(super) type Allowlist<T: Config> = StorageDoubleMap<
+		Hasher1 = Twox128,
+		Key1 = H160,
+		Hasher2 = Twox128,
+		Key2 = H160,
+		Value = bool,
+		QueryKind = ValueQuery,
+	>;
+
+	impl<T: Config> Pallet<T> {
+		pub fn toggle_sponsoring(contract: H160, enabled: bool) {
+			<SelfSponsoring<T>>::insert(contract, enabled);
+		}
+
+		pub fn allowed(contract: H160, user: H160) -> bool {
+			if !<AllowlistEnabled<T>>::get(contract) {
+				return true;
+			}
+			<Allowlist<T>>::get(&contract, &user) || <Owner<T>>::get(&contract) == user
+		}
+
+		pub fn toggle_allowlist(contract: H160, enabled: bool) {
+			<AllowlistEnabled<T>>::insert(contract, enabled)
+		}
+
+		pub fn toggle_allowed(contract: H160, user: H160, allowed: bool) {
+			<Allowlist<T>>::insert(contract, user, allowed);
+		}
+
+		pub fn ensure_owner(contract: H160, user: H160) -> Result<()> {
+			ensure!(<Owner<T>>::get(&contract) == user, "no permission");
+			Ok(())
+		}
+	}
+}
addedpallets/evm-contract-helpers/src/stubs/ContractHelpers.bindiffbeforeafterboth

binary blob — no preview

addedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
--- /dev/null
+++ b/pallets/evm-contract-helpers/src/stubs/ContractHelpers.sol
@@ -0,0 +1,40 @@
+contract ContractHelpers {
+    uint8 _dummmy = 0;
+    address _dummy_addr = 0x0000000000000000000000000000000000000000;
+	string stub_error = "this contract does not exists, contract helpers are implemented on substrate chain side";
+
+    function contractOwner(address contract_address) public view returns (address) {
+        require(false, stub_error);
+        contract_address;
+        return _dummy_addr;
+    }
+    
+    function sponsoringEnabled(address contract_address) public view returns (bool) {
+        require(false, stub_error);
+        contract_address;
+        _dummmy;
+        return false;
+    }
+    
+    function toggleSponsoring(address contract_address, bool enabled) public {
+        require(false, stub_error);
+        contract_address;
+        enabled;
+        _dummmy = 0;
+    }
+    
+    function toggleAllowlist(address contract_address, bool enabled) public {
+        require(false, stub_error);
+        contract_address;
+        enabled;
+        _dummmy = 0;
+    }
+    
+    function toggleAllowed(address contract_address, address user, bool allowed) public {
+        require(false, stub_error);
+        contract_address;
+        user;
+        allowed;
+        _dummmy = 0;
+    }
+}
\ No newline at end of file