difftreelog
docs
in: master
2 files changed
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth46where46where47 T::AccountId: AsRef<[u8]>,47 T::AccountId: AsRef<[u8]>,48{48{49 /// Get contract ovner50 /// 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 }525657 /// 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 }677576 /// 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 }738687 /// 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 }809798 /// 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 }84105106 /// 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,pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth101 OnEmpty = T::DefaultSponsoringRateLimit,101 OnEmpty = T::DefaultSponsoringRateLimit,102 >;102 >;103103104 /// 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 }152157153 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 }166179180 /// 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 }183199200 /// 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 }229230 impl<T: Config> Pallet<T> {231 pub fn contract_owner(contract: H160) -> H160 {232 <Owner<T>>::get(contract)233 }234 }235}246}236247237#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]248#[derive(Encode, Decode, PartialEq, TypeInfo, MaxEncodedLen)]