--- a/pallets/evm-contract-helpers/src/eth.rs
+++ b/pallets/evm-contract-helpers/src/eth.rs
@@ -46,10 +46,18 @@
where
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
{
Ok(>::get(contract_address))
}
+ /// 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(
&mut self,
caller: caller,
@@ -65,12 +73,21 @@
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)
.map_err(dispatch_to_evm::)?;
Ok(())
}
+ /// 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)> {
let sponsor =
Pallet::::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;
@@ -78,10 +95,18 @@
Ok((*sponsor.as_eth(), sponsor_sub))
}
+ /// 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 {
Ok(Pallet::::get_sponsor(contract_address).is_some())
}
+ /// 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 {
Ok(match Sponsoring::::get(contract_address) {
SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,
--- a/pallets/evm-contract-helpers/src/lib.rs
+++ b/pallets/evm-contract-helpers/src/lib.rs
@@ -101,6 +101,11 @@
OnEmpty = T::DefaultSponsoringRateLimit,
>;
+ /// Storage for last sponsored block.
+ ///
+ /// * **Key1** - contract address.
+ /// * **Key2** - sponsored user address.
+ /// * **Value** - last sponsored block number.
#[pallet::storage]
pub(super) type SponsorBasket = StorageDoubleMap<
Hasher1 = Twox128,
@@ -151,6 +156,14 @@
}
impl Pallet {
+ /// Get contract owner.
+ pub fn contract_owner(contract: H160) -> H160 {
+ >::get(contract)
+ }
+
+ /// Set `sponsor` for `contract`.
+ ///
+ /// `sender` must be owner of contract.
pub fn set_sponsor(
sender: &T::CrossAccountId,
contract: H160,
@@ -164,6 +177,9 @@
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) {
SponsorshipState::Unconfirmed(sponsor) => {
@@ -181,6 +197,7 @@
}
}
+ /// Get sponsor.
pub fn get_sponsor(contract: H160) -> Option {
match Sponsoring::::get(contract) {
SponsorshipState::Disabled | SponsorshipState::Unconfirmed(_) => None,
@@ -224,12 +241,6 @@
pub fn ensure_owner(contract: H160, user: H160) -> DispatchResult {
ensure!(>::get(&contract) == user, Error::::NoPermission);
Ok(())
- }
- }
-
- impl Pallet {
- pub fn contract_owner(contract: H160) -> H160 {
- >::get(contract)
}
}
}