git.delta.rocks / unique-network / refs/commits / 9d33b05e829a

difftreelog

docs

Trubnikov Sergey2022-08-05parent: #4afd851.patch.diff
in: master

2 files changed

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
--- 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<address> {
 		Ok(<Owner<T>>::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<void> {
 		Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)
 			.map_err(dispatch_to_evm::<T>)?;
 		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::<T>::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<bool> {
 		Ok(Pallet::<T>::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<bool> {
 		Ok(match Sponsoring::<T>::get(contract_address) {
 			SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
101 OnEmpty = T::DefaultSponsoringRateLimit,101 OnEmpty = T::DefaultSponsoringRateLimit,
102 >;102 >;
103103
104 /// Storage for last sponsored block.
105 ///
106 /// * **Key1** - contract address.
107 /// * **Key2** - sponsored user address.
108 /// * **Value** - last sponsored block number.
104 #[pallet::storage]109 #[pallet::storage]
105 pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<110 pub(super) type SponsorBasket<T: Config> = StorageDoubleMap<
106 Hasher1 = Twox128,111 Hasher1 = Twox128,
151 }156 }
152157
153 impl<T: Config> Pallet<T> {158 impl<T: Config> Pallet<T> {
159 /// Get contract owner.
160 pub fn contract_owner(contract: H160) -> H160 {
161 <Owner<T>>::get(contract)
162 }
163
164 /// Set `sponsor` for `contract`.
165 ///
166 /// `sender` must be owner of contract.
154 pub fn set_sponsor(167 pub fn set_sponsor(
155 sender: &T::CrossAccountId,168 sender: &T::CrossAccountId,
156 contract: H160,169 contract: H160,
164 Ok(())177 Ok(())
165 }178 }
166179
180 /// Confirm sponsorship.
181 ///
182 /// `sender` must be same that set via [`set_sponsor`].
167 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {183 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {
168 match Sponsoring::<T>::get(contract) {184 match Sponsoring::<T>::get(contract) {
169 SponsorshipState::Unconfirmed(sponsor) => {185 SponsorshipState::Unconfirmed(sponsor) => {
181 }197 }
182 }198 }
183199
200 /// Get sponsor.
184 pub fn get_sponsor(contract: H160) -> Option<T::CrossAccountId> {201 pub fn get_sponsor(contract: H160) -> Option<T::CrossAccountId> {
185 match Sponsoring::<T>::get(contract) {202 match Sponsoring::<T>::get(contract) {
186 SponsorshipState::Disabled | SponsorshipState::Unconfirmed(_) => None,203 SponsorshipState::Disabled | SponsorshipState::Unconfirmed(_) => None,
227 }244 }
228 }245 }
229
230 impl<T: Config> Pallet<T> {
231 pub fn contract_owner(contract: H160) -> H160 {
232 <Owner<T>>::get(contract)
233 }
234 }
235}246}
236247
237#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]248#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]