difftreelog
path: Add 'self_sponsored_enable' and 'remove_sponsor'.
in: master
2 files changed
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -24,7 +24,8 @@
use sp_core::H160;
use up_data_structs::SponsorshipState;
use crate::{
- AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT, Sponsoring,
+ AllowlistEnabled, Config, Owner, Pallet, SponsorBasket, SponsoringRateLimit, SponsoringModeT,
+ Sponsoring,
};
use frame_support::traits::Get;
use up_sponsorship::SponsorshipHandler;
@@ -47,7 +48,7 @@
T::AccountId: AsRef<[u8]>,
{
/// Get contract ovner
- ///
+ ///
/// @param Contract_address contract for which the owner is being determined.
/// @return Contract owner.
fn contract_owner(&self, contract_address: address) -> Result<address> {
@@ -55,7 +56,7 @@
}
/// Set sponsor.
- ///
+ ///
/// @param contract_address Contract for which a sponsor is being established.
/// @param sponsor User address who set as pending sponsor.
fn set_sponsor(
@@ -73,10 +74,28 @@
Ok(())
}
+ /// Set contract as self sponsored.
+ ///
+ /// @param contract_address Contract for which a self sponsoring is being enabled.
+ fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {
+ Pallet::<T>::self_sponsored_enable(&T::CrossAccountId::from_eth(caller), contract_address)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(())
+ }
+
+ /// Remove sponsor.
+ ///
+ /// @param contract_address Contract for which a sponsorship is being removed.
+ fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {
+ Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)
+ .map_err(dispatch_to_evm::<T>)?;
+ Ok(())
+ }
+
/// Confirm sponsorship.
- ///
+ ///
/// @dev Caller must be same that set via [`set_sponsor`].
- ///
+ ///
/// @param contract_address Сontract for which need to confirm sponsorship.
fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {
Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)
@@ -85,7 +104,7 @@
}
/// Get current sponsor.
- ///
+ ///
/// @param contract_address The contract for which a sponsor is requested.
/// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {
@@ -96,7 +115,7 @@
}
/// Check tat contract has confirmed sponsor.
- ///
+ ///
/// @param contract_address The contract for which the presence of a confirmed sponsor is checked.
/// @return **true** if contract has confirmed sponsor.
fn has_sponsor(&self, contract_address: address) -> Result<bool> {
@@ -104,7 +123,7 @@
}
/// Check tat contract has pending sponsor.
- ///
+ ///
/// @param contract_address The contract for which the presence of a pending sponsor is checked.
/// @return **true** if contract has pending sponsor.
fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {
pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth49 NoPendingSponsor,49 NoPendingSponsor,50 }50 }5152 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);535154 #[pallet::pallet]52 #[pallet::pallet]55 #[pallet::storage_version(STORAGE_VERSION)]56 #[pallet::generate_store(pub(super) trait Store)]53 #[pallet::generate_store(pub(super) trait Store)]57 pub struct Pallet<T>(_);54 pub struct Pallet<T>(_);5855102 >;99 >;103100104 /// Storage for last sponsored block.101 /// Storage for last sponsored block.105 /// 102 ///106 /// * **Key1** - contract address.103 /// * **Key1** - contract address.107 /// * **Key2** - sponsored user address.104 /// * **Key2** - sponsored user address.108 /// * **Value** - last sponsored block number.105 /// * **Value** - last sponsored block number.145 QueryKind = ValueQuery,142 QueryKind = ValueQuery,146 >;143 >;147148 #[pallet::hooks]149 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {150 fn on_runtime_upgrade() -> Weight {151 let storage_version = StorageVersion::get::<Pallet<T>>();152 if storage_version < StorageVersion::new(1) {}153154 0155 }156 }157144158 impl<T: Config> Pallet<T> {145 impl<T: Config> Pallet<T> {159 /// Get contract owner.146 /// Get contract owner.160 pub fn contract_owner(contract: H160) -> H160 {147 pub fn contract_owner(contract: H160) -> H160 {161 <Owner<T>>::get(contract)148 <Owner<T>>::get(contract)162 }149 }163 150164 /// Set `sponsor` for `contract`. 151 /// Set `sponsor` for `contract`.165 /// 152 ///166 /// `sender` must be owner of contract.153 /// `sender` must be owner of contract.167 pub fn set_sponsor(154 pub fn set_sponsor(168 sender: &T::CrossAccountId,155 sender: &T::CrossAccountId,177 Ok(())164 Ok(())178 }165 }166167 /// Set `contract` as self sponsored.168 ///169 /// `sender` must be owner of contract.170 pub fn self_sponsored_enable(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {171 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;172 Sponsoring::<T>::insert(173 contract,174 SponsorshipState::<T::CrossAccountId>::Confirmed(T::CrossAccountId::from_eth(175 contract,176 )),177 );178 Ok(())179 }180181 /// Remove sponsor for `contract`.182 ///183 /// `sender` must be owner of contract.184 pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {185 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;186 Sponsoring::<T>::remove(contract);187 Ok(())188 }179189180 /// Confirm sponsorship.190 /// Confirm sponsorship.181 /// 191 ///182 /// `sender` must be same that set via [`set_sponsor`].192 /// `sender` must be same that set via [`set_sponsor`].183 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {193 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {184 match Sponsoring::<T>::get(contract) {194 match Sponsoring::<T>::get(contract) {