difftreelog
feat Using EthCrossAccount in appropriate functions
in: master
11 files changed
crates/evm-coder/src/abi.rsdiffbeforeafterboth--- a/crates/evm-coder/src/abi.rs
+++ b/crates/evm-coder/src/abi.rs
@@ -450,7 +450,7 @@
}
}
-impl AbiWrite for &EthCrossAccount {
+impl AbiWrite for EthCrossAccount {
fn abi_write(&self, writer: &mut AbiWriter) {
self.eth.abi_write(writer);
self.sub.abi_write(writer);
crates/evm-coder/src/lib.rsdiffbeforeafterboth--- a/crates/evm-coder/src/lib.rs
+++ b/crates/evm-coder/src/lib.rs
@@ -218,7 +218,7 @@
}
}
- #[derive(Debug)]
+ #[derive(Debug, Default)]
pub struct EthCrossAccount {
pub(crate) eth: address,
pub(crate) sub: uint256,
crates/evm-coder/src/solidity.rsdiffbeforeafterboth--- a/crates/evm-coder/src/solidity.rs
+++ b/crates/evm-coder/src/solidity.rs
@@ -203,7 +203,7 @@
}
fn solidity_default(writer: &mut impl fmt::Write, tc: &TypeCollector) -> fmt::Result {
- write!(writer, "{}(", tc.collect_tuple::<Self>())?;
+ write!(writer, "{}(", tc.collect_struct::<Self>())?;
address::solidity_default(writer, tc)?;
write!(writer, ",")?;
uint256::solidity_default(writer, tc)?;
pallets/common/src/erc.rsdiffbeforeafterboth231 fn set_collection_sponsor_cross(231 fn set_collection_sponsor_cross(232 &mut self,232 &mut self,233 caller: caller,233 caller: caller,234 sponsor: (address, uint256),234 sponsor: EthCrossAccount,235 ) -> Result<void> {235 ) -> Result<void> {236 self.consume_store_reads_and_writes(1, 1)?;236 self.consume_store_reads_and_writes(1, 1)?;237237238 check_is_owner_or_admin(caller, self)?;238 check_is_owner_or_admin(caller, self)?;239239240 let sponsor = convert_tuple_to_cross_account::<T>(sponsor)?;240 let sponsor = sponsor.into_sub_cross_account::<T>()?;241 self.set_sponsor(sponsor.as_sub().clone())241 self.set_sponsor(sponsor.as_sub().clone())242 .map_err(dispatch_to_evm::<T>)?;242 .map_err(dispatch_to_evm::<T>)?;243 save(self)243 save(self)388 fn add_collection_admin_cross(388 fn add_collection_admin_cross(389 &mut self,389 &mut self,390 caller: caller,390 caller: caller,391 new_admin: (address, uint256),391 new_admin: EthCrossAccount,392 ) -> Result<void> {392 ) -> Result<void> {393 self.consume_store_writes(2)?;393 self.consume_store_writes(2)?;394394395 let caller = T::CrossAccountId::from_eth(caller);395 let caller = T::CrossAccountId::from_eth(caller);396 let new_admin = convert_tuple_to_cross_account::<T>(new_admin)?;396 let new_admin = new_admin.into_sub_cross_account::<T>()?;397 <Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;397 <Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;398 Ok(())398 Ok(())399 }399 }403 fn remove_collection_admin_cross(403 fn remove_collection_admin_cross(404 &mut self,404 &mut self,405 caller: caller,405 caller: caller,406 admin: (address, uint256),406 admin: EthCrossAccount,407 ) -> Result<void> {407 ) -> Result<void> {408 self.consume_store_writes(2)?;408 self.consume_store_writes(2)?;409409410 let caller = T::CrossAccountId::from_eth(caller);410 let caller = T::CrossAccountId::from_eth(caller);411 let admin = convert_tuple_to_cross_account::<T>(admin)?;411 let admin = admin.into_sub_cross_account::<T>()?;412 <Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;412 <Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;413 Ok(())413 Ok(())414 }414 }566 fn add_to_collection_allow_list_cross(566 fn add_to_collection_allow_list_cross(567 &mut self,567 &mut self,568 caller: caller,568 caller: caller,569 user: (address, uint256),569 user: EthCrossAccount,570 ) -> Result<void> {570 ) -> Result<void> {571 self.consume_store_writes(1)?;571 self.consume_store_writes(1)?;572572573 let caller = T::CrossAccountId::from_eth(caller);573 let caller = T::CrossAccountId::from_eth(caller);574 let user = convert_tuple_to_cross_account::<T>(user)?;574 let user = user.into_sub_cross_account::<T>()?;575 Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;575 Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;576 Ok(())576 Ok(())577 }577 }594 fn remove_from_collection_allow_list_cross(594 fn remove_from_collection_allow_list_cross(595 &mut self,595 &mut self,596 caller: caller,596 caller: caller,597 user: (address, uint256),597 user: EthCrossAccount,598 ) -> Result<void> {598 ) -> Result<void> {599 self.consume_store_writes(1)?;599 self.consume_store_writes(1)?;600600601 let caller = T::CrossAccountId::from_eth(caller);601 let caller = T::CrossAccountId::from_eth(caller);602 let user = convert_tuple_to_cross_account::<T>(user)?;602 let user = user.into_sub_cross_account::<T>()?;603 Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;603 Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;604 Ok(())604 Ok(())605 }605 }639 ///639 ///640 /// @param user User cross account to verify640 /// @param user User cross account to verify641 /// @return "true" if account is the owner or admin641 /// @return "true" if account is the owner or admin642 fn is_owner_or_admin_cross(&self, user: (address, uint256)) -> Result<bool> {642 fn is_owner_or_admin_cross(&self, user: EthCrossAccount) -> Result<bool> {643 let user = convert_tuple_to_cross_account::<T>(user)?;643 let user = user.into_sub_cross_account::<T>()?;644 Ok(self.is_owner_or_admin(&user))644 Ok(self.is_owner_or_admin(&user))645 }645 }646646660 ///660 ///661 /// @return Tuble with sponsor address and his substrate mirror.661 /// @return Tuble with sponsor address and his substrate mirror.662 /// If address is canonical then substrate mirror is zero and vice versa.662 /// If address is canonical then substrate mirror is zero and vice versa.663 fn collection_owner(&self) -> Result<(address, uint256)> {663 fn collection_owner(&self) -> Result<EthCrossAccount> {664 Ok(convert_cross_account_to_tuple::<T>(664 Ok(EthCrossAccount::from_sub_cross_account::<T>(665 &T::CrossAccountId::from_sub(self.owner.clone()),665 &T::CrossAccountId::from_sub(self.owner.clone()),666 ))666 ))667 }667 }684 ///684 ///685 /// @return Vector of tuples with admins address and his substrate mirror.685 /// @return Vector of tuples with admins address and his substrate mirror.686 /// If address is canonical then substrate mirror is zero and vice versa.686 /// If address is canonical then substrate mirror is zero and vice versa.687 fn collection_admins(&self) -> Result<Vec<(address, uint256)>> {687 fn collection_admins(&self) -> Result<Vec<EthCrossAccount>> {688 let result = crate::IsAdmin::<T>::iter_prefix((self.id,))688 let result = crate::IsAdmin::<T>::iter_prefix((self.id,))689 .map(|(admin, _)| crate::eth::convert_cross_account_to_tuple::<T>(&admin))689 .map(|(admin, _)| EthCrossAccount::from_sub_cross_account::<T>(&admin))690 .collect();690 .collect();691 Ok(result)691 Ok(result)692 }692 }695 ///695 ///696 /// @dev Owner can be changed only by current owner696 /// @dev Owner can be changed only by current owner697 /// @param newOwner new owner cross account697 /// @param newOwner new owner cross account698 fn set_owner_cross(&mut self, caller: caller, new_owner: (address, uint256)) -> Result<void> {698 fn set_owner_cross(&mut self, caller: caller, new_owner: EthCrossAccount) -> Result<void> {699 self.consume_store_writes(1)?;699 self.consume_store_writes(1)?;700700701 let caller = T::CrossAccountId::from_eth(caller);701 let caller = T::CrossAccountId::from_eth(caller);702 let new_owner = convert_tuple_to_cross_account::<T>(new_owner)?;702 let new_owner = new_owner.into_sub_cross_account::<T>()?;703 self.set_owner_internal(caller, new_owner)703 self.set_owner_internal(caller, new_owner)704 .map_err(dispatch_to_evm::<T>)704 .map_err(dispatch_to_evm::<T>)705 }705 }pallets/fungible/src/erc.rsdiffbeforeafterboth--- a/pallets/fungible/src/erc.rs
+++ b/pallets/fungible/src/erc.rs
@@ -167,11 +167,11 @@
fn approve_cross(
&mut self,
caller: caller,
- spender: (address, uint256),
+ spender: EthCrossAccount,
amount: uint256,
) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
- let spender = convert_tuple_to_cross_account::<T>(spender)?;
+ let spender = spender.into_sub_cross_account::<T>()?;
let amount = amount.try_into().map_err(|_| "amount overflow")?;
<Pallet<T>>::set_allowance(self, &caller, &spender, amount)
@@ -207,11 +207,11 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
+ from: EthCrossAccount,
amount: uint256,
) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
+ let from = from.into_sub_cross_account::<T>()?;
let amount = amount.try_into().map_err(|_| "amount overflow")?;
let budget = self
.recorder
@@ -249,13 +249,13 @@
fn transfer_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
- to: (address, uint256),
+ from: EthCrossAccount,
+ to: EthCrossAccount,
amount: uint256,
) -> Result<bool> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
- let to = convert_tuple_to_cross_account::<T>(to)?;
+ let from = from.into_sub_cross_account::<T>()?;
+ let to = to.into_sub_cross_account::<T>()?;
let amount = amount.try_into().map_err(|_| "amount overflow")?;
let budget = self
.recorder
pallets/nonfungible/src/erc.rsdiffbeforeafterboth--- a/pallets/nonfungible/src/erc.rs
+++ b/pallets/nonfungible/src/erc.rs
@@ -684,11 +684,11 @@
fn approve_cross(
&mut self,
caller: caller,
- approved: (address, uint256),
+ approved: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let approved = convert_tuple_to_cross_account::<T>(approved)?;
+ let approved = approved.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
<Pallet<T>>::set_allowance(self, &caller, token, Some(&approved))
@@ -770,11 +770,11 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
+ from: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
+ let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
let budget = self
.recorder
pallets/refungible/src/erc.rsdiffbeforeafterboth--- a/pallets/refungible/src/erc.rs
+++ b/pallets/refungible/src/erc.rs
@@ -734,23 +734,23 @@
fn transfer_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
- to: (address, uint256),
+ from: EthCrossAccount,
+ to: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- // let from = convert_tuple_to_cross_account::<T>(from)?;
- // let to = convert_tuple_to_cross_account::<T>(to)?;
- // let token_id = token_id.try_into()?;
- // let budget = self
- // .recorder
- // .weight_calls_budget(<StructureWeight<T>>::find_parent());
+ let from = from.into_sub_cross_account::<T>()?;
+ let to = to.into_sub_cross_account::<T>()?;
+ let token_id = token_id.try_into()?;
+ let budget = self
+ .recorder
+ .weight_calls_budget(<StructureWeight<T>>::find_parent());
- // let balance = balance(self, token_id, &from)?;
- // ensure_single_owner(self, token_id, balance)?;
+ let balance = balance(self, token_id, &from)?;
+ ensure_single_owner(self, token_id, balance)?;
- // Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)
- // .map_err(dispatch_to_evm::<T>)?;
+ Pallet::<T>::transfer_from(self, &caller, &from, &to, token_id, balance, &budget)
+ .map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -789,11 +789,11 @@
fn burn_from_cross(
&mut self,
caller: caller,
- from: (address, uint256),
+ from: EthCrossAccount,
token_id: uint256,
) -> Result<void> {
let caller = T::CrossAccountId::from_eth(caller);
- let from = convert_tuple_to_cross_account::<T>(from)?;
+ let from = from.into_sub_cross_account::<T>()?;
let token = token_id.try_into()?;
let budget = self
.recorder
tests/src/eth/collectionAdmin.test.tsdiffbeforeafterboth--- a/tests/src/eth/collectionAdmin.test.ts
+++ b/tests/src/eth/collectionAdmin.test.ts
@@ -94,25 +94,6 @@
await collectionEvm.methods.addCollectionAdmin(newAdmin).send();
expect(await collectionEvm.methods.isOwnerOrAdmin(newAdmin).call()).to.be.true;
});
-
- itEth.skip('Check adminlist', async ({helper, privateKey}) => {
- const owner = await helper.eth.createAccountWithBalance(donor);
-
- const {collectionAddress, collectionId} = await helper.eth.createNonfungibleCollection(owner, 'A', 'B', 'C');
- const collectionEvm = helper.ethNativeContract.collection(collectionAddress, 'nft', owner);
-
- const admin1 = helper.eth.createAccount();
- const admin2 = privateKey('admin');
- await collectionEvm.methods.addCollectionAdmin(admin1).send();
- await collectionEvm.methods.addCollectionAdminSubstrate(admin2.addressRaw).send();
-
- const adminListRpc = await helper.collection.getAdmins(collectionId);
- let adminListEth = await collectionEvm.methods.collectionAdmins().call();
- adminListEth = adminListEth.map((element: IEthCrossAccountId) => {
- return helper.address.convertCrossAccountFromEthCrossAcoount(element);
- });
- expect(adminListRpc).to.be.like(adminListEth);
- });
itEth('(!negative tests!) Add admin by ADMIN is not allowed', async ({helper}) => {
const owner = await helper.eth.createAccountWithBalance(donor);
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -409,7 +409,7 @@
expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));
});
- itEth.only('Can perform transferFromCross()', async ({helper, privateKey}) => {
+ itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {
const alice = privateKey('//Alice');
const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});
tests/src/util/playgrounds/types.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/types.ts
+++ b/tests/src/util/playgrounds/types.ts
@@ -73,8 +73,8 @@
export interface IEthCrossAccountId {
0: TEthereumAccount;
1: TSubstrateAccount;
- field_0: TEthereumAccount;
- field_1: TSubstrateAccount;
+ eth: TEthereumAccount;
+ sub: TSubstrateAccount;
}
export interface ICollectionLimits {
tests/src/util/playgrounds/unique.tsdiffbeforeafterboth--- a/tests/src/util/playgrounds/unique.ts
+++ b/tests/src/util/playgrounds/unique.ts
@@ -2430,11 +2430,11 @@
* @returns substrate cross account id
*/
convertCrossAccountFromEthCrossAcoount(ethCrossAccount: IEthCrossAccountId): ICrossAccountId {
- if (ethCrossAccount.field_1 === '0') {
- return {Ethereum: ethCrossAccount.field_0.toLocaleLowerCase()};
+ if (ethCrossAccount.sub === '0') {
+ return {Ethereum: ethCrossAccount.eth.toLocaleLowerCase()};
}
- const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.field_1));
+ const ss58 = this.restoreCrossAccountFromBigInt(BigInt(ethCrossAccount.sub));
return {Substrate: ss58};
}