git.delta.rocks / unique-network / refs/commits / 46475864a647

difftreelog

CORE-302 Fix PR

Trubnikov Sergey2022-04-26parent: #02be24d.patch.diff
in: master

2 files changed

modifiedpallets/evm-collection/src/eth.rsdiffbeforeafterboth
18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};18use evm_coder::{abi::AbiWriter, execution::*, generate_stubgen, solidity_interface, types::*, ToLog};
19use ethereum as _;19use ethereum as _;
20use pallet_common::CollectionById;20use pallet_common::CollectionById;
21use pallet_common::CollectionHandle;21use pallet_common::{CollectionHandle};
22use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};22use pallet_evm_coder_substrate::{SubstrateRecorder, WithRecorder};
23use pallet_evm::{23use pallet_evm::{
24 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,24 ExitRevert, OnCreate, OnMethodCall, PrecompileResult, PrecompileFailure,
113 let mut collection = collection_from_address(collection_address, &self.0)?;113 let mut collection = collection_from_address(collection_address, &self.0)?;
114 check_is_owner(caller, &collection)?;114 check_is_owner(caller, &collection)?;
115115
116 fn set_offchain_shema(shema: string) -> Result<void> {116 let sponsor = T::CrossAccountId::from_eth(sponsor);
117 let shema = shema
118 .into_bytes()117 collection.set_sponsor(sponsor.as_sub().clone());
119 .try_into()
120 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;118 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
121 collection.offchain_schema = shema;119 Ok(()).map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
122 save(collection)120 Ok(())
123 }121 }
124122
125 fn confirm_sponsorship(&self, caller: caller, collection_address: address) -> Result<void> {123 fn confirm_sponsorship(&self, caller: caller, collection_address: address) -> Result<void> {
128 if !collection.confirm_sponsorship(caller.as_sub()) {126 if !collection.confirm_sponsorship(caller.as_sub()) {
129 return Err(Error::Revert("Caller is not set as sponsor".into()));127 return Err(Error::Revert("Caller is not set as sponsor".into()));
130 }128 }
131 save(collection)129 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
130 Ok(())
132 }131 }
133132
134 fn set_offchain_shema(133 fn set_offchain_shema(
144 .into_bytes()143 .into_bytes()
145 .try_into()144 .try_into()
146 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;145 .map_err(|_| error_feild_too_long(stringify!(shema), OFFCHAIN_SCHEMA_LIMIT))?;
147 collection.offchain_schema = shema;146 // collection.offchain_schema = shema;
148 save(collection)147 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
148 Ok(())
149 }149 }
150150
151 fn set_variable_on_chain_schema(151 fn set_variable_on_chain_schema(
160 let variable = variable.into_bytes().try_into().map_err(|_| {160 let variable = variable.into_bytes().try_into().map_err(|_| {
161 error_feild_too_long(stringify!(variable), VARIABLE_ON_CHAIN_SCHEMA_LIMIT)161 error_feild_too_long(stringify!(variable), VARIABLE_ON_CHAIN_SCHEMA_LIMIT)
162 })?;162 })?;
163 collection.variable_on_chain_schema = variable;163 // collection.variable_on_chain_schema = variable;
164 save(collection)164 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
165 Ok(())
165 }166 }
166167
167 fn set_const_on_chain_schema(168 fn set_const_on_chain_schema(
176 let const_on_chain = const_on_chain.into_bytes().try_into().map_err(|_| {177 let const_on_chain = const_on_chain.into_bytes().try_into().map_err(|_| {
177 error_feild_too_long(stringify!(const_on_chain), CONST_ON_CHAIN_SCHEMA_LIMIT)178 error_feild_too_long(stringify!(const_on_chain), CONST_ON_CHAIN_SCHEMA_LIMIT)
178 })?;179 })?;
179 collection.const_on_chain_schema = const_on_chain;180 // collection.const_on_chain_schema = const_on_chain;
180 save(collection)181 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
182 Ok(())
181 }183 }
182184
183 fn set_limits(185 fn set_limits(
192 let limits = serde_json::from_str(limits_json.as_ref())194 let limits = serde_json::from_str(limits_json.as_ref())
193 .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;195 .map_err(|e| Error::Revert(format!("Parse JSON error: {}", e)))?;
194 collection.limits = limits;196 collection.limits = limits;
195 save(collection)197 collection.save().map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
198 Ok(())
196 }199 }
197}200}
198201
202205
203fn collection_from_address<T: Config>(206fn collection_from_address<T: Config>(
204 collection_address: address,207 collection_address: address,
205 recorder: &Rc<SubstrateRecorder<T>>,208 recorder: &SubstrateRecorder<T>,
206) -> Result<CollectionHandle<T>> {209) -> Result<CollectionHandle<T>> {
207 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)210 let collection_id = pallet_common::eth::map_eth_to_id(&collection_address)
208 .ok_or(Error::Revert("Contract is not an unique collection".into()))?;211 .ok_or(Error::Revert("Contract is not an unique collection".into()))?;
209 let collection =212 let collection =
210 pallet_common::CollectionHandle::new_with_recorder(collection_id, recorder.clone())213 pallet_common::CollectionHandle::new_with_gas_limit(collection_id, recorder.gas_left())
211 .ok_or(Error::Revert("Create collection handle error".into()))?;214 .ok_or(Error::Revert("Create collection handle error".into()))?;
212 Ok(collection)215 Ok(collection)
213}216}
218 .check_is_owner(&caller)221 .check_is_owner(&caller)
219 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;222 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?;
220 Ok(())223 Ok(())
221}
222
223fn save<T: Config>(collection: CollectionHandle<T>) -> Result<()> {
224 Ok(collection
225 .save()
226 .map_err(pallet_evm_coder_substrate::dispatch_to_evm::<T>)?)
227}224}
228225
229pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);226pub struct CollectionOnMethodCall<T: Config>(PhantomData<*const T>);
modifiedtests/src/eth/createCollection.test.tsdiffbeforeafterboth
--- a/tests/src/eth/createCollection.test.ts
+++ b/tests/src/eth/createCollection.test.ts
@@ -150,7 +150,7 @@
     let result = await helper.methods.create721Collection('Mint collection', '6', '6').send();
     const {collectionIdAddress, collectionId} = await getCollectionAddressFromResult(api, result);
     const receiver = createEthAccount(web3);
-    const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress.toLowerCase(), {from: owner, ...GAS_ARGS});
+    const contract = new web3.eth.Contract(nonFungibleAbi as any, collectionIdAddress, {from: owner, ...GAS_ARGS});
     const nextTokenId = await contract.methods.nextTokenId().call();
 
     expect(nextTokenId).to.be.equal('1');