difftreelog
path: Add 'self_sponsored_enable' and 'remove_sponsor'.
in: master
2 files changed
pallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth47 T::AccountId: AsRef<[u8]>,48 T::AccountId: AsRef<[u8]>,48{49{49 /// Get contract ovner50 /// Get contract ovner50 /// 51 ///51 /// @param Contract_address contract for which the owner is being determined.52 /// @param Contract_address contract for which the owner is being determined.52 /// @return Contract owner.53 /// @return Contract owner.53 fn contract_owner(&self, contract_address: address) -> Result<address> {54 fn contract_owner(&self, contract_address: address) -> Result<address> {54 Ok(<Owner<T>>::get(contract_address))55 Ok(<Owner<T>>::get(contract_address))55 }56 }565757 /// Set sponsor.58 /// Set sponsor.58 /// 59 ///59 /// @param contract_address Contract for which a sponsor is being established.60 /// @param contract_address Contract for which a sponsor is being established.60 /// @param sponsor User address who set as pending sponsor.61 /// @param sponsor User address who set as pending sponsor.61 fn set_sponsor(62 fn set_sponsor(73 Ok(())74 Ok(())74 }75 }7677 /// Set contract as self sponsored.78 ///79 /// @param contract_address Contract for which a self sponsoring is being enabled.80 fn self_sponsored_enable(&mut self, caller: caller, contract_address: address) -> Result<void> {81 Pallet::<T>::self_sponsored_enable(&T::CrossAccountId::from_eth(caller), contract_address)82 .map_err(dispatch_to_evm::<T>)?;83 Ok(())84 }8586 /// Remove sponsor.87 ///88 /// @param contract_address Contract for which a sponsorship is being removed.89 fn remove_sponsor(&mut self, caller: caller, contract_address: address) -> Result<void> {90 Pallet::<T>::remove_sponsor(&T::CrossAccountId::from_eth(caller), contract_address)91 .map_err(dispatch_to_evm::<T>)?;92 Ok(())93 }759476 /// Confirm sponsorship.95 /// Confirm sponsorship.77 /// 96 ///78 /// @dev Caller must be same that set via [`set_sponsor`].97 /// @dev Caller must be same that set via [`set_sponsor`].79 /// 98 ///80 /// @param contract_address Сontract for which need to confirm sponsorship.99 /// @param contract_address Сontract for which need to confirm sponsorship.81 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {100 fn confirm_sponsorship(&mut self, caller: caller, contract_address: address) -> Result<void> {82 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)101 Pallet::<T>::confirm_sponsorship(&T::CrossAccountId::from_eth(caller), contract_address)85 }104 }8610587 /// Get current sponsor.106 /// Get current sponsor.88 /// 107 ///89 /// @param contract_address The contract for which a sponsor is requested.108 /// @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.109 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.91 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {110 fn get_sponsor(&self, contract_address: address) -> Result<(address, uint256)> {96 }115 }9711698 /// Check tat contract has confirmed sponsor.117 /// Check tat contract has confirmed sponsor.99 /// 118 ///100 /// @param contract_address The contract for which the presence of a confirmed sponsor is checked.119 /// @param contract_address The contract for which the presence of a confirmed sponsor is checked.101 /// @return **true** if contract has confirmed sponsor.120 /// @return **true** if contract has confirmed sponsor.102 fn has_sponsor(&self, contract_address: address) -> Result<bool> {121 fn has_sponsor(&self, contract_address: address) -> Result<bool> {103 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())122 Ok(Pallet::<T>::get_sponsor(contract_address).is_some())104 }123 }105124106 /// Check tat contract has pending sponsor.125 /// Check tat contract has pending sponsor.107 /// 126 ///108 /// @param contract_address The contract for which the presence of a pending sponsor is checked.127 /// @param contract_address The contract for which the presence of a pending sponsor is checked.109 /// @return **true** if contract has pending sponsor.128 /// @return **true** if contract has pending sponsor.110 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {129 fn has_pending_sponsor(&self, contract_address: address) -> Result<bool> {pallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth49 NoPendingSponsor,49 NoPendingSponsor,50 }50 }5152 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);535154 #[pallet::pallet]52 #[pallet::pallet]55 #[pallet::storage_version(STORAGE_VERSION)]56 #[pallet::generate_store(pub(super) trait Store)]53 #[pallet::generate_store(pub(super) trait Store)]57 pub struct Pallet<T>(_);54 pub struct Pallet<T>(_);5855102 >;99 >;103100104 /// Storage for last sponsored block.101 /// Storage for last sponsored block.105 /// 102 ///106 /// * **Key1** - contract address.103 /// * **Key1** - contract address.107 /// * **Key2** - sponsored user address.104 /// * **Key2** - sponsored user address.108 /// * **Value** - last sponsored block number.105 /// * **Value** - last sponsored block number.145 QueryKind = ValueQuery,142 QueryKind = ValueQuery,146 >;143 >;147148 #[pallet::hooks]149 impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {150 fn on_runtime_upgrade() -> Weight {151 let storage_version = StorageVersion::get::<Pallet<T>>();152 if storage_version < StorageVersion::new(1) {}153154 0155 }156 }157144158 impl<T: Config> Pallet<T> {145 impl<T: Config> Pallet<T> {159 /// Get contract owner.146 /// Get contract owner.160 pub fn contract_owner(contract: H160) -> H160 {147 pub fn contract_owner(contract: H160) -> H160 {161 <Owner<T>>::get(contract)148 <Owner<T>>::get(contract)162 }149 }163 150164 /// Set `sponsor` for `contract`. 151 /// Set `sponsor` for `contract`.165 /// 152 ///166 /// `sender` must be owner of contract.153 /// `sender` must be owner of contract.167 pub fn set_sponsor(154 pub fn set_sponsor(168 sender: &T::CrossAccountId,155 sender: &T::CrossAccountId,177 Ok(())164 Ok(())178 }165 }166167 /// Set `contract` as self sponsored.168 ///169 /// `sender` must be owner of contract.170 pub fn self_sponsored_enable(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {171 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;172 Sponsoring::<T>::insert(173 contract,174 SponsorshipState::<T::CrossAccountId>::Confirmed(T::CrossAccountId::from_eth(175 contract,176 )),177 );178 Ok(())179 }180181 /// Remove sponsor for `contract`.182 ///183 /// `sender` must be owner of contract.184 pub fn remove_sponsor(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {185 Pallet::<T>::ensure_owner(contract, *sender.as_eth())?;186 Sponsoring::<T>::remove(contract);187 Ok(())188 }179189180 /// Confirm sponsorship.190 /// Confirm sponsorship.181 /// 191 ///182 /// `sender` must be same that set via [`set_sponsor`].192 /// `sender` must be same that set via [`set_sponsor`].183 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {193 pub fn confirm_sponsorship(sender: &T::CrossAccountId, contract: H160) -> DispatchResult {184 match Sponsoring::<T>::get(contract) {194 match Sponsoring::<T>::get(contract) {