difftreelog
feat Add events for set contract sponsoring.
in: master
7 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5735,6 +5735,7 @@
name = "pallet-evm-contract-helpers"
version = "0.2.0"
dependencies = [
+ "ethereum",
"evm-coder",
"fp-evm-mapping",
"frame-support",
pallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth--- a/pallets/evm-contract-helpers/Cargo.toml
+++ b/pallets/evm-contract-helpers/Cargo.toml
@@ -9,6 +9,7 @@
"derive",
] }
log = { default-features = false, version = "0.4.14" }
+ethereum = { version = "0.12.0", default-features = false }
# Substrate
frame-support = { default-features = false, git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.27" }
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -17,7 +17,9 @@
//! Implementation of magic contract
use core::marker::PhantomData;
-use evm_coder::{abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*};
+use evm_coder::{
+ abi::AbiWriter, execution::Result, generate_stubgen, solidity_interface, types::*, ToLog,
+};
use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder, dispatch_to_evm};
use pallet_evm::{
ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure, PrecompileHandle,
@@ -33,6 +35,37 @@
use up_sponsorship::SponsorshipHandler;
use sp_std::vec::Vec;
+/// Pallet events.
+#[derive(ToLog)]
+pub enum ContractHelpersEvents {
+ /// Contract sponsor was set.
+ ContractSponsorSet {
+ /// Contract address of the affected collection.
+ #[indexed]
+ contract: address,
+ /// New sponsor address.
+ #[indexed]
+ sponsor: address,
+ },
+
+ /// New sponsor was confirm.
+ ContractSponsorshipConfirmed {
+ /// Contract address of the affected collection.
+ #[indexed]
+ contract: address,
+ /// New sponsor address.
+ #[indexed]
+ sponsor: address,
+ },
+
+ /// Collection sponsor was removed.
+ ContractSponsorRemoved {
+ /// Contract address of the affected collection.
+ #[indexed]
+ contract: address,
+ },
+}
+
/// See [`ContractHelpersCall`]
pub struct ContractHelpers<T: Config>(SubstrateRecorder<T>);
impl<T: Config> WithRecorder<T> for ContractHelpers<T> {
@@ -46,7 +79,7 @@
}
/// @title Magic contract, which allows users to reconfigure other contracts
-#[solidity_interface(name = ContractHelpers)]
+#[solidity_interface(name = ContractHelpers, events(ContractHelpersEvents))]
impl<T: Config> ContractHelpers<T>
where
T::AccountId: AsRef<[u8; 32]>,
@@ -91,7 +124,7 @@
self.recorder().consume_sload()?;
self.recorder().consume_sstore()?;
- Pallet::<T>::self_sponsored_enable(&T::CrossAccountId::from_eth(caller), contract_address)
+ Pallet::<T>::force_set_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)
.map_err(dispatch_to_evm::<T>)?;
Ok(())
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -16,7 +16,7 @@
#![doc = include_str!("../README.md")]
#![cfg_attr(not(feature = "std"), no_std)]
-#![deny(missing_docs)]
+#![warn(missing_docs)]
use codec::{Decode, Encode, MaxEncodedLen};
pub use pallet::*;
@@ -27,18 +27,24 @@
#[frame_support::pallet]
pub mod pallet {
pub use super::*;
+ use crate::eth::ContractHelpersEvents;
use frame_support::pallet_prelude::*;
use pallet_evm_coder_substrate::DispatchResult;
use sp_core::H160;
- use pallet_evm::account::CrossAccountId;
+ use pallet_evm::{account::CrossAccountId, Pallet as PalletEvm};
use up_data_structs::SponsorshipState;
+ use evm_coder::ToLog;
#[pallet::config]
pub trait Config:
frame_system::Config + pallet_evm_coder_substrate::Config + pallet_evm::account::Config
{
+ /// Overarching event type.
+ type Event: IsType<<Self as frame_system::Config>::Event> + From<Event<Self>>;
+
/// Address, under which magic contract will be available
type ContractAddress: Get<H160>;
+
/// In case of enabled sponsoring, but no sponsoring rate limit set,
/// this value will be used implicitly
type DefaultSponsoringRateLimit: Get<Self::BlockNumber>;
@@ -150,6 +156,32 @@
QueryKind = ValueQuery,
>;
+ #[pallet::event]
+ #[pallet::generate_deposit(pub fn deposit_event)]
+ pub enum Event<T: Config> {
+ /// Contract sponsor was set.
+ ContractSponsorSet(
+ /// Contract address of the affected collection.
+ H160,
+ /// New sponsor address.
+ T::AccountId,
+ ),
+
+ /// New sponsor was confirm.
+ ContractSponsorshipConfirmed(
+ /// Contract address of the affected collection.
+ H160,
+ /// New sponsor address.
+ T::AccountId,
+ ),
+
+ /// Collection sponsor was removed.
+ ContractSponsorRemoved(
+ /// Contract address of the affected collection.
+ H160,
+ ),
+ }
+
impl<T: Config> Pallet<T> {
/// Get contract owner.
pub fn contract_owner(contract: H160) -> H160 {
@@ -169,13 +201,25 @@
contract,
SponsorshipState::<T::CrossAccountId>::Unconfirmed(sponsor.clone()),
);
+
+ <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorSet(
+ contract,
+ sponsor.as_sub().clone(),
+ ));
+ <PalletEvm<T>>::deposit_log(
+ ContractHelpersEvents::ContractSponsorSet {
+ contract,
+ sponsor: *sponsor.as_eth(),
+ }
+ .to_log(contract),
+ );
Ok(())
}
- /// Set `contract` as self sponsored.
+ /// Set sponsor as already confirmed.
///
/// `sender` must be owner of contract.
- pub fn self_sponsored_enable(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
+ pub fn force_set_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
Sponsoring::<T>::insert(
contract,
@@ -192,6 +236,12 @@
pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;
Sponsoring::<T>::remove(contract);
+
+ <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorRemoved(contract));
+ <PalletEvm<T>>::deposit_log(
+ ContractHelpersEvents::ContractSponsorRemoved { contract }.to_log(contract),
+ );
+
Ok(())
}
@@ -202,10 +252,25 @@
match Sponsoring::<T>::get(contract) {
SponsorshipState::Unconfirmed(sponsor) => {
ensure!(sponsor == *sender, Error::<T>::NoPermission);
+ let eth_sponsor = *sponsor.as_eth();
+ let sub_sponsor = sponsor.as_sub().clone();
Sponsoring::<T>::insert(
contract,
SponsorshipState::<T::CrossAccountId>::Confirmed(sponsor),
);
+
+ <Pallet<T>>::deposit_event(Event::<T>::ContractSponsorshipConfirmed(
+ contract,
+ sub_sponsor,
+ ));
+ <PalletEvm<T>>::deposit_log(
+ ContractHelpersEvents::ContractSponsorshipConfirmed {
+ contract,
+ sponsor: eth_sponsor,
+ }
+ .to_log(contract),
+ );
+
Ok(())
}
SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => {
runtime/common/config/ethereum.rsdiffbeforeafterboth--- a/runtime/common/config/ethereum.rs
+++ b/runtime/common/config/ethereum.rs
@@ -112,6 +112,7 @@
}
impl pallet_evm_contract_helpers::Config for Runtime {
+ type Event = Event;
type ContractAddress = HelpersContractAddress;
type DefaultSponsoringRateLimit = DefaultSponsoringRateLimit;
}
runtime/common/config/pallets/app_promotion.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/app_promotion.rs
+++ b/runtime/common/config/pallets/app_promotion.rs
@@ -22,7 +22,7 @@
use frame_support::{parameter_types, PalletId};
use sp_arithmetic::Perbill;
use up_common::{
- constants::{ UNIQUE, RELAY_DAYS},
+ constants::{UNIQUE, RELAY_DAYS},
types::Balance,
};
runtime/common/construct_runtime/mod.rsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617mod util;1819#[macro_export]20macro_rules! construct_runtime {21 ($select_runtime:ident) => {22 $crate::construct_runtime_impl! {23 select_runtime($select_runtime);2425 pub enum Runtime where26 Block = Block,27 NodeBlock = opaque::Block,28 UncheckedExtrinsic = UncheckedExtrinsic29 {30 System: frame_system = 0,3132 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,33 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,3435 Aura: pallet_aura::{Pallet, Config<T>} = 22,36 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,3738 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,39 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,40 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,41 TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 33,42 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,43 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,44 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,45 // Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,46 // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,4748 // XCM helpers.49 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,50 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,51 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,52 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,5354 // Unique Pallets55 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,56 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,5758 #[runtimes(opal)]59 Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,6061 Configuration: pallet_configuration::{Pallet, Call, Storage} = 63,6263 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,64 // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,65 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,66 Fungible: pallet_fungible::{Pallet, Storage} = 67,6768 #[runtimes(opal)]69 Refungible: pallet_refungible::{Pallet, Storage} = 68,7071 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,72 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,7374 #[runtimes(opal)]75 RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,7677 #[runtimes(opal)]78 RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,7980 #[runtimes(opal)]81 AppPromotion: pallet_app_promotion::{Pallet, Call, Storage, Event<T>} = 73,8283 // Frontier84 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,85 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,8687 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,88 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage} = 151,89 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,90 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,91 }92 }93 }94}1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617mod util;1819#[macro_export]20macro_rules! construct_runtime {21 ($select_runtime:ident) => {22 $crate::construct_runtime_impl! {23 select_runtime($select_runtime);2425 pub enum Runtime where26 Block = Block,27 NodeBlock = opaque::Block,28 UncheckedExtrinsic = UncheckedExtrinsic29 {30 System: frame_system = 0,3132 ParachainSystem: cumulus_pallet_parachain_system::{Pallet, Call, Config, Storage, Inherent, Event<T>, ValidateUnsigned} = 20,33 ParachainInfo: parachain_info::{Pallet, Storage, Config} = 21,3435 Aura: pallet_aura::{Pallet, Config<T>} = 22,36 AuraExt: cumulus_pallet_aura_ext::{Pallet, Config} = 23,3738 Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>} = 30,39 RandomnessCollectiveFlip: pallet_randomness_collective_flip::{Pallet, Storage} = 31,40 Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent} = 32,41 TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>} = 33,42 Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>} = 34,43 Sudo: pallet_sudo::{Pallet, Call, Storage, Config<T>, Event<T>} = 35,44 Vesting: orml_vesting::{Pallet, Storage, Call, Event<T>, Config<T>} = 37,45 // Vesting: pallet_vesting::{Pallet, Call, Config<T>, Storage, Event<T>} = 37,46 // Contracts: pallet_contracts::{Pallet, Call, Storage, Event<T>} = 38,4748 // XCM helpers.49 XcmpQueue: cumulus_pallet_xcmp_queue::{Pallet, Call, Storage, Event<T>} = 50,50 PolkadotXcm: pallet_xcm::{Pallet, Call, Event<T>, Origin} = 51,51 CumulusXcm: cumulus_pallet_xcm::{Pallet, Call, Event<T>, Origin} = 52,52 DmpQueue: cumulus_pallet_dmp_queue::{Pallet, Call, Storage, Event<T>} = 53,5354 // Unique Pallets55 Inflation: pallet_inflation::{Pallet, Call, Storage} = 60,56 Unique: pallet_unique::{Pallet, Call, Storage, Event<T>} = 61,5758 #[runtimes(opal)]59 Scheduler: pallet_unique_scheduler::{Pallet, Call, Storage, Event<T>} = 62,6061 Configuration: pallet_configuration::{Pallet, Call, Storage} = 63,6263 Charging: pallet_charge_transaction::{Pallet, Call, Storage } = 64,64 // ContractHelpers: pallet_contract_helpers::{Pallet, Call, Storage} = 65,65 Common: pallet_common::{Pallet, Storage, Event<T>} = 66,66 Fungible: pallet_fungible::{Pallet, Storage} = 67,6768 #[runtimes(opal)]69 Refungible: pallet_refungible::{Pallet, Storage} = 68,7071 Nonfungible: pallet_nonfungible::{Pallet, Storage} = 69,72 Structure: pallet_structure::{Pallet, Call, Storage, Event<T>} = 70,7374 #[runtimes(opal)]75 RmrkCore: pallet_proxy_rmrk_core::{Pallet, Call, Storage, Event<T>} = 71,7677 #[runtimes(opal)]78 RmrkEquip: pallet_proxy_rmrk_equip::{Pallet, Call, Storage, Event<T>} = 72,7980 #[runtimes(opal)]81 AppPromotion: pallet_app_promotion::{Pallet, Call, Storage, Event<T>} = 73,8283 // Frontier84 EVM: pallet_evm::{Pallet, Config, Call, Storage, Event<T>} = 100,85 Ethereum: pallet_ethereum::{Pallet, Config, Call, Storage, Event, Origin} = 101,8687 EvmCoderSubstrate: pallet_evm_coder_substrate::{Pallet, Storage} = 150,88 EvmContractHelpers: pallet_evm_contract_helpers::{Pallet, Storage, Event<T>} = 151,89 EvmTransactionPayment: pallet_evm_transaction_payment::{Pallet} = 152,90 EvmMigration: pallet_evm_migration::{Pallet, Call, Storage} = 153,91 }92 }93 }94}