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.rsdiffbeforeafterboth--- a/pallets/common/src/erc.rs
+++ b/pallets/common/src/erc.rs
@@ -231,13 +231,13 @@
fn set_collection_sponsor_cross(
&mut self,
caller: caller,
- sponsor: (address, uint256),
+ sponsor: EthCrossAccount,
) -> Result<void> {
self.consume_store_reads_and_writes(1, 1)?;
check_is_owner_or_admin(caller, self)?;
- let sponsor = convert_tuple_to_cross_account::<T>(sponsor)?;
+ let sponsor = sponsor.into_sub_cross_account::<T>()?;
self.set_sponsor(sponsor.as_sub().clone())
.map_err(dispatch_to_evm::<T>)?;
save(self)
@@ -388,12 +388,12 @@
fn add_collection_admin_cross(
&mut self,
caller: caller,
- new_admin: (address, uint256),
+ new_admin: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(2)?;
let caller = T::CrossAccountId::from_eth(caller);
- let new_admin = convert_tuple_to_cross_account::<T>(new_admin)?;
+ let new_admin = new_admin.into_sub_cross_account::<T>()?;
<Pallet<T>>::toggle_admin(self, &caller, &new_admin, true).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -403,12 +403,12 @@
fn remove_collection_admin_cross(
&mut self,
caller: caller,
- admin: (address, uint256),
+ admin: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(2)?;
let caller = T::CrossAccountId::from_eth(caller);
- let admin = convert_tuple_to_cross_account::<T>(admin)?;
+ let admin = admin.into_sub_cross_account::<T>()?;
<Pallet<T>>::toggle_admin(self, &caller, &admin, false).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -566,12 +566,12 @@
fn add_to_collection_allow_list_cross(
&mut self,
caller: caller,
- user: (address, uint256),
+ user: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ let user = user.into_sub_cross_account::<T>()?;
Pallet::<T>::toggle_allowlist(self, &caller, &user, true).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -594,12 +594,12 @@
fn remove_from_collection_allow_list_cross(
&mut self,
caller: caller,
- user: (address, uint256),
+ user: EthCrossAccount,
) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ let user = user.into_sub_cross_account::<T>()?;
Pallet::<T>::toggle_allowlist(self, &caller, &user, false).map_err(dispatch_to_evm::<T>)?;
Ok(())
}
@@ -639,8 +639,8 @@
///
/// @param user User cross account to verify
/// @return "true" if account is the owner or admin
- fn is_owner_or_admin_cross(&self, user: (address, uint256)) -> Result<bool> {
- let user = convert_tuple_to_cross_account::<T>(user)?;
+ fn is_owner_or_admin_cross(&self, user: EthCrossAccount) -> Result<bool> {
+ let user = user.into_sub_cross_account::<T>()?;
Ok(self.is_owner_or_admin(&user))
}
@@ -660,8 +660,8 @@
///
/// @return Tuble with sponsor address and his substrate mirror.
/// If address is canonical then substrate mirror is zero and vice versa.
- fn collection_owner(&self) -> Result<(address, uint256)> {
- Ok(convert_cross_account_to_tuple::<T>(
+ fn collection_owner(&self) -> Result<EthCrossAccount> {
+ Ok(EthCrossAccount::from_sub_cross_account::<T>(
&T::CrossAccountId::from_sub(self.owner.clone()),
))
}
@@ -684,9 +684,9 @@
///
/// @return Vector of tuples with admins address and his substrate mirror.
/// If address is canonical then substrate mirror is zero and vice versa.
- fn collection_admins(&self) -> Result<Vec<(address, uint256)>> {
+ fn collection_admins(&self) -> Result<Vec<EthCrossAccount>> {
let result = crate::IsAdmin::<T>::iter_prefix((self.id,))
- .map(|(admin, _)| crate::eth::convert_cross_account_to_tuple::<T>(&admin))
+ .map(|(admin, _)| EthCrossAccount::from_sub_cross_account::<T>(&admin))
.collect();
Ok(result)
}
@@ -695,11 +695,11 @@
///
/// @dev Owner can be changed only by current owner
/// @param newOwner new owner cross account
- fn set_owner_cross(&mut self, caller: caller, new_owner: (address, uint256)) -> Result<void> {
+ fn set_owner_cross(&mut self, caller: caller, new_owner: EthCrossAccount) -> Result<void> {
self.consume_store_writes(1)?;
let caller = T::CrossAccountId::from_eth(caller);
- let new_owner = convert_tuple_to_cross_account::<T>(new_owner)?;
+ let new_owner = new_owner.into_sub_cross_account::<T>()?;
self.set_owner_internal(caller, new_owner)
.map_err(dispatch_to_evm::<T>)
}
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.tsdiffbeforeafterboth409 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));409 expect(cost < BigInt(0.2 * Number(helper.balance.getOneTokenNominal())));410 });410 });411411412 itEth.only('Can perform transferFromCross()', async ({helper, privateKey}) => {412 itEth('Can perform transferFromCross()', async ({helper, privateKey}) => {413 const alice = privateKey('//Alice');413 const alice = privateKey('//Alice');414 const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});414 const collection = await helper.nft.mintCollection(alice, {name: 'A', description: 'B', tokenPrefix: 'C'});415415tests/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};
}