--- 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
{
@@ -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 {
+ Pallet::::self_sponsored_enable(&T::CrossAccountId::from_eth(caller), contract_address)
+ .map_err(dispatch_to_evm::)?;
+ 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 {
+ Pallet::::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)
+ .map_err(dispatch_to_evm::)?;
+ 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 {
Pallet::::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 {
@@ -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 {
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -49,10 +49,7 @@
NoPendingSponsor,
}
- const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
-
#[pallet::pallet]
- #[pallet::storage_version(STORAGE_VERSION)]
#[pallet::generate_store(pub(super) trait Store)]
pub struct Pallet(_);
@@ -102,7 +99,7 @@
>;
/// Storage for last sponsored block.
- ///
+ ///
/// * **Key1** - contract address.
/// * **Key2** - sponsored user address.
/// * **Value** - last sponsored block number.
@@ -144,25 +141,15 @@
Value = bool,
QueryKind = ValueQuery,
>;
-
- #[pallet::hooks]
- impl Hooks> for Pallet {
- fn on_runtime_upgrade() -> Weight {
- let storage_version = StorageVersion::get::>();
- if storage_version < StorageVersion::new(1) {}
- 0
- }
- }
-
impl Pallet {
/// Get contract owner.
pub fn contract_owner(contract: H160) -> H160 {
>::get(contract)
}
-
- /// Set `sponsor` for `contract`.
- ///
+
+ /// Set `sponsor` for `contract`.
+ ///
/// `sender` must be owner of contract.
pub fn set_sponsor(
sender: &T::CrossAccountId,
@@ -177,8 +164,31 @@
Ok(())
}
+ /// Set `contract` as self sponsored.
+ ///
+ /// `sender` must be owner of contract.
+ pub fn self_sponsored_enable(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
+ Pallet::::ensure_owner(contract, *sender.as_eth())?;
+ Sponsoring::::insert(
+ contract,
+ SponsorshipState::::Confirmed(T::CrossAccountId::from_eth(
+ contract,
+ )),
+ );
+ Ok(())
+ }
+
+ /// Remove sponsor for `contract`.
+ ///
+ /// `sender` must be owner of contract.
+ pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
+ Pallet::::ensure_owner(contract, *sender.as_eth())?;
+ Sponsoring::::remove(contract);
+ Ok(())
+ }
+
/// Confirm sponsorship.
- ///
+ ///
/// `sender` must be same that set via [`set_sponsor`].
pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
match Sponsoring::::get(contract) {