git.delta.rocks / unique-network / refs/commits / f1e64f25a71d

difftreelog

path: Add 'self_sponsored_enable' and 'remove_sponsor'.

Trubnikov Sergey2022-08-05parent: #9d33b05.patch.diff
in: master

2 files changed

modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
47 T::AccountId: AsRef<[u8]>,48 T::AccountId: AsRef<[u8]>,
48{49{
49 /// Get contract ovner50 /// Get contract ovner
50 /// 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 }
5657
57 /// 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 }
76
77 /// 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 }
85
86 /// 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 }
7594
76 /// 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 }
86105
87 /// 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 }
97116
98 /// 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 }
105124
106 /// 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> {
modifiedpallets/evm-contract-helpers/src/lib.rsdiffbeforeafterboth
49 NoPendingSponsor,49 NoPendingSponsor,
50 }50 }
51
52 const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
5351
54 #[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>(_);
5855
102 >;99 >;
103100
104 /// 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 >;
147
148 #[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) {}
153
154 0
155 }
156 }
157144
158 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 150
164 /// 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 }
166
167 /// 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 }
180
181 /// 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 }
179189
180 /// 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) {