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
46where46where
47 T::AccountId: AsRef<[u8]>,47 T::AccountId: AsRef<[u8]>,
48{48{
49 /// Get contract ovner
50 ///
51 /// @param Contract_address contract for which the owner is being determined.
52 /// @return Contract owner.
49 fn contract_owner(&self, contract_address: address) -> Result<address> {53 fn contract_owner(&self, contract_address: address) -> Result<address> {
50 Ok(<Owner<T>>::get(contract_address))54 Ok(<Owner<T>>::get(contract_address))
51 }55 }
5256
57 /// Set sponsor.
58 ///
59 /// @param contract_address Contract for which a sponsor is being established.
60 /// @param sponsor User address who set as pending sponsor.
53 fn set_sponsor(61 fn set_sponsor(
54 &mut self,62 &mut self,
55 caller: caller,63 caller: caller,
65 Ok(())73 Ok(())
66 }74 }
6775
76 /// Confirm sponsorship.
77 ///
78 /// @dev Caller must be same that set via [`set_sponsor`].
79 ///
80 /// @param contract_address Сontract for which need to confirm sponsorship.
68 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {81 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {
69 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)82 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)
70 .map_err(dispatch_to_evm::<T>)?;83 .map_err(dispatch_to_evm::<T>)?;
71 Ok(())84 Ok(())
72 }85 }
7386
87 /// Get current sponsor.
88 ///
89 /// @param contract_address The contract for which a sponsor is requested.
90 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
74 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {91 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {
75 let sponsor =92 let sponsor =
76 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;93 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;
77 let sponsor_sub = pallet_common::eth::convert_cross_account_to_eth_uint256::<T>(&sponsor);94 let sponsor_sub = pallet_common::eth::convert_cross_account_to_eth_uint256::<T>(&sponsor);
78 Ok((*sponsor.as_eth(), sponsor_sub))95 Ok((*sponsor.as_eth(), sponsor_sub))
79 }96 }
8097
98 /// Check tat contract has confirmed sponsor.
99 ///
100 /// @param contract_address The contract for which the presence of a confirmed sponsor is checked.
101 /// @return **true** if contract has confirmed sponsor.
81 fn has_sponsor(&self, contract_address: address) -> Result<bool> {102 fn has_sponsor(&self, contract_address: address) -> Result<bool> {
82 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())103 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())
83 }104 }
84105
106 /// Check tat contract has pending sponsor.
107 ///
108 /// @param contract_address The contract for which the presence of a pending sponsor is checked.
109 /// @return **true** if contract has pending sponsor.
85 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {110 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {
86 Ok(match Sponsoring::<T>::get(contract_address) {111 Ok(match Sponsoring::<T>::get(contract_address) {
87 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,112 SponsorshipState::Disabled | SponsorshipState::Confirmed(_) => false,
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
--- 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<T: Config> = StorageDoubleMap<
 		Hasher1 = Twox128,
@@ -151,6 +156,14 @@
 	}
 
 	impl<T: Config> Pallet<T> {
+		/// Get contract owner.
+		pub fn contract_owner(contract: H160) -> H160 {
+			<Owner<T>>::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::<T>::get(contract) {
 				SponsorshipState::Unconfirmed(sponsor) => {
@@ -181,6 +197,7 @@
 			}
 		}
 
+		/// Get sponsor.
 		pub fn get_sponsor(contract: H160) -> Option<T::CrossAccountId> {
 			match Sponsoring::<T>::get(contract) {
 				SponsorshipState::Disabled | SponsorshipState::Unconfirmed(_) => None,
@@ -224,12 +241,6 @@
 		pub fn ensure_owner(contract: H160, user: H160) -> DispatchResult {
 			ensure!(<Owner<T>>::get(&contract) == user, Error::<T>::NoPermission);
 			Ok(())
-		}
-	}
-
-	impl<T: Config> Pallet<T> {
-		pub fn contract_owner(contract: H160) -> H160 {
-			<Owner<T>>::get(contract)
 		}
 	}
 }