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

difftreelog

tests(util): introduce CrossAccountId class to take on some util functionality

Fahrrader2022-09-28parent: #a9c2603.patch.diff
in: master

4 files changed

modifiedtests/src/nesting/nest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/nest.test.ts
+++ b/tests/src/nesting/nest.test.ts
@@ -35,7 +35,7 @@
     // Create an immediately nested token
     const nestedToken = await collection.mintToken(alice, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
     
     // Create a token to be nested
     const newToken = await collection.mintToken(alice);
@@ -43,14 +43,14 @@
     // Nest
     await newToken.nest(alice, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Move bundle to different user
     await targetToken.transfer(alice, {Substrate: bob.address});
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Unnest
     await newToken.unnest(bob, targetToken, {Substrate: bob.address});
@@ -65,12 +65,12 @@
 
     // Create a nested token
     const tokenC = await collection.mintToken(alice, tokenA.nestingAccount());
-    expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccountInLowerCase());
+    expect(await tokenC.getOwner()).to.be.deep.equal(tokenA.nestingAccount().toLowerCase());
     
     // Transfer the nested token to another token
     await expect(tokenC.transferFrom(alice, tokenA.nestingAccount(), tokenB.nestingAccount())).to.be.fulfilled;
     expect(await tokenC.getTopmostOwner()).to.be.deep.equal({Substrate: alice.address});
-    expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccountInLowerCase());
+    expect(await tokenC.getOwner()).to.be.deep.equal(tokenB.nestingAccount().toLowerCase());
   });
 
   itSub('Checks token children', async ({helper}) => {
@@ -150,13 +150,13 @@
     // Create an immediately nested token
     const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Create a token to be nested and nest
     const newToken = await collection.mintToken(bob);
     await newToken.nest(bob, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   itSub('Admin (NFT): Admin and Token Owner can operate together', async ({helper}) => {
@@ -167,13 +167,13 @@
     // Create an immediately nested token by an administrator
     const nestedToken = await collection.mintToken(bob, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Create a token to be nested and nest
     const newToken = await collection.mintToken(alice, {Substrate: charlie.address});
     await newToken.nest(charlie, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   itSub('Admin (NFT): allows an Admin to nest a token (Restricted nesting)', async ({helper}) => {
@@ -187,13 +187,13 @@
     // Create an immediately nested token
     const nestedToken = await collectionB.mintToken(bob, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Create a token to be nested and nest
     const newToken = await collectionB.mintToken(bob);
     await newToken.nest(bob, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   // ---------- Non-Fungible ----------
@@ -207,13 +207,13 @@
     // Create an immediately nested token
     const nestedToken = await collection.mintToken(charlie, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Create a token to be nested and nest
     const newToken = await collection.mintToken(charlie);
     await newToken.nest(charlie, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   itSub('NFT: allows an Owner to nest/unnest their token (Restricted nesting)', async ({helper}) => {
@@ -233,13 +233,13 @@
     // Create an immediately nested token
     const nestedToken = await collectionB.mintToken(charlie, targetToken.nestingAccount());
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Create a token to be nested and nest
     const newToken = await collectionB.mintToken(charlie);
     await newToken.nest(charlie, targetToken);
     expect(await newToken.getTopmostOwner()).to.be.deep.equal({Substrate: charlie.address});
-    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await newToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   // ---------- Fungible ----------
@@ -424,7 +424,7 @@
 
     expect(await targetToken.getChildren()).to.be.length(1);
     expect(await nestedToken.getTopmostOwner()).to.be.deep.equal({Substrate: bob.address});
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   itSub('Admin (NFT): disallows an Admin to nest a token from an unlisted collection (Restricted nesting)', async ({helper}) => {
modifiedtests/src/nesting/unnest.test.tsdiffbeforeafterboth
--- a/tests/src/nesting/unnest.test.ts
+++ b/tests/src/nesting/unnest.test.ts
@@ -105,11 +105,11 @@
 
     // Try to unnest
     await expect(nestedToken.unnest(bob, targetToken, {Substrate: alice.address})).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
 
     // Try to burn
     await expect(nestedToken.burnFrom(bob, targetToken.nestingAccount())).to.be.rejectedWith(/common\.ApprovedValueTooLow/);
-    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccountInLowerCase());
+    expect(await nestedToken.getOwner()).to.be.deep.equal(targetToken.nestingAccount().toLowerCase());
   });
 
   // todo another test for creating excessive depth matryoshka with Ethereum?
modifiedtests/src/rpc.test.tsdiffbeforeafterboth
--- a/tests/src/rpc.test.ts
+++ b/tests/src/rpc.test.ts
@@ -16,7 +16,7 @@
 
 import {IKeyringPair} from '@polkadot/types/types';
 import {usingPlaygrounds, itSub, expect} from './util/playgrounds';
-import {crossAccountIdFromLower} from './util/playgrounds/unique';
+import {CrossAccountId} from './util/playgrounds/unique';
 
 describe('integration test: RPC methods', () => {
   let donor: IKeyringPair;
@@ -55,7 +55,7 @@
     // Set-up over
 
     const owners = await helper.callRpc('api.rpc.unique.tokenOwners', [collection.collectionId, 0]);
-    const ids = (owners.toJSON() as any[]).map(crossAccountIdFromLower);
+    const ids = (owners.toJSON() as any[]).map(CrossAccountId.fromLowerCaseKeys);
 
     expect(ids).to.deep.include.members([{Substrate: alice.address}, ethAcc, {Substrate: bob.address}, ...facelessCrowd]);
     expect(owners.length == 10).to.be.true;
modifiedtests/src/util/playgrounds/unique.tsdiffbeforeafterboth
11import {IKeyringPair} from '@polkadot/types/types';11import {IKeyringPair} from '@polkadot/types/types';
12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, TUniqueNetworks} from './types';12import {IApiListeners, IBlock, IEvent, IChainProperties, ICollectionCreationOptions, ICollectionLimits, ICollectionPermissions, ICrossAccountId, ICrossAccountIdLower, ILogger, INestingPermissions, IProperty, IStakingInfo, ISubstrateBalance, IToken, ITokenPropertyPermission, ITransactionResult, IUniqueHelperLog, TApiAllowedListeners, TEthereumAccount, TSigner, TSubstrateAccount, TUniqueNetworks} from './types';
1313
14export const crossAccountIdFromLower = (lowerAddress: ICrossAccountIdLower): ICrossAccountId => {14export class CrossAccountId implements ICrossAccountId {
15 Substrate?: TSubstrateAccount;
16 Ethereum?: TEthereumAccount;
17
18 constructor(account: ICrossAccountId) {
19 if (account.Substrate) this.Substrate = account.Substrate;
20 if (account.Ethereum) this.Ethereum = account.Ethereum;
21 }
22
23 static fromKeyring(account: IKeyringPair) {
24 return new CrossAccountId({Substrate: account.address});
25 }
26
27 static fromLowerCaseKeys(address: ICrossAccountIdLower): CrossAccountId {
28 return new CrossAccountId({Substrate: address.substrate, Ethereum: address.ethereum});
29 }
30
31 static normalizeSubstrateAddress(address: TSubstrateAccount, ss58Format = 42): TSubstrateAccount {
32 return encodeAddress(decodeAddress(address), ss58Format);
33 }
34
35 static withNormalizedSubstrate(address: TSubstrateAccount, ss58Format = 42): CrossAccountId {
36 return new CrossAccountId({Substrate: CrossAccountId.normalizeSubstrateAddress(address, ss58Format)});
37 }
38
15 const address = {} as ICrossAccountId;39 withNormalizedSubstrate(ss58Format = 42): CrossAccountId {
40 if (this.Substrate) return CrossAccountId.withNormalizedSubstrate(this.Substrate, ss58Format);
41 return this;
42 }
43
44 toLowerCase(): CrossAccountId {
16 if(lowerAddress.substrate) address.Substrate = lowerAddress.substrate;45 if (this.Substrate) this.Substrate = this.Substrate.toLowerCase();
17 if(lowerAddress.ethereum) address.Ethereum = lowerAddress.ethereum;46 if (this.Ethereum) this.Ethereum = this.Ethereum.toLowerCase();
18 return address;47 return this;
19};48 }
49}
2050
21const nesting = {51const nesting = {
22 toChecksumAddress(address: string): string {52 toChecksumAddress(address: string): string {
55 RPC: 'rpc',85 RPC: 'rpc',
56 };86 };
5787
58 static getTokenAccount(token: IToken): ICrossAccountId {88 static getTokenAccount(token: IToken): CrossAccountId {
59 return {Ethereum: this.getTokenAddress(token)};89 return new CrossAccountId({Ethereum: this.getTokenAddress(token)});
60 }90 }
61
62 static getTokenAccountInLowerCase(token: IToken): ICrossAccountId {
63 return {Ethereum: this.getTokenAddress(token).toLowerCase()};
64 }
6591
66 static getTokenAddress(token: IToken): string {92 static getTokenAddress(token: IToken): string {
67 return nesting.tokenIdToAddress(token.collectionId, token.tokenId);93 return nesting.tokenIdToAddress(token.collectionId, token.tokenId);
94 return keyring.addFromUri(seed);120 return keyring.addFromUri(seed);
95 }121 }
96
97 static normalizeSubstrateAddress(address: string, ss58Format = 42) {
98 return encodeAddress(decodeAddress(address), ss58Format);
99 }
100122
101 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {123 static extractCollectionIdFromCreationResult(creationResult: ITransactionResult) {
102 if (creationResult.status !== this.transactionStatus.SUCCESS) {124 if (creationResult.status !== this.transactionStatus.SUCCESS) {
178 Object.keys(address).forEach(k => {200 Object.keys(address).forEach(k => {
179 obj[k.toLocaleLowerCase()] = address[k as 'Substrate' | 'Ethereum'];201 obj[k.toLocaleLowerCase()] = address[k as 'Substrate' | 'Ethereum'];
180 });202 });
181 if(obj.substrate) return {Substrate: this.normalizeSubstrateAddress(obj.substrate)};203 if(obj.substrate) return CrossAccountId.withNormalizedSubstrate(obj.substrate);
182 if(obj.ethereum) return {Ethereum: obj.ethereum.toLocaleLowerCase()};204 if(obj.ethereum) return CrossAccountId.fromLowerCaseKeys(obj).toLowerCase();
183 return address;205 return address;
184 };206 };
185 let transfer = {collectionId: null, tokenId: null, from: null, to: null, amount: 1} as any;207 let transfer = {collectionId: null, tokenId: null, from: null, to: null, amount: 1} as any;
563 name: string;585 name: string;
564 description: string;586 description: string;
565 tokensCount: number;587 tokensCount: number;
566 admins: ICrossAccountId[];588 admins: CrossAccountId[];
567 normalizedOwner: TSubstrateAccount;589 normalizedOwner: TSubstrateAccount;
568 raw: any590 raw: any
569 } | null> {591 } | null> {
596 * @example await getAdmins(1)618 * @example await getAdmins(1)
597 * @returns array of administrators619 * @returns array of administrators
598 */620 */
599 async getAdmins(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {621 async getAdmins(collectionId: number, normalize = false): Promise<CrossAccountId[]> {
600 const admins = (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman();622 const admins = (await this.helper.callRpc('api.rpc.unique.adminlist', [collectionId])).toHuman();
601623
602 return normalize624 return normalize
603 ? admins.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))625 ? admins.map((address: CrossAccountId) => address.withNormalizedSubstrate())
604 : admins;626 : admins;
605 }627 }
606628
611 * @example await getAllowList(1)633 * @example await getAllowList(1)
612 * @returns array of allow-listed addresses634 * @returns array of allow-listed addresses
613 */635 */
614 async getAllowList(collectionId: number, normalize = false): Promise<ICrossAccountId[]> {636 async getAllowList(collectionId: number, normalize = false): Promise<CrossAccountId[]> {
615 const allowListed = (await this.helper.callRpc('api.rpc.unique.allowlist', [collectionId])).toHuman();637 const allowListed = (await this.helper.callRpc('api.rpc.unique.allowlist', [collectionId])).toHuman();
616 return normalize638 return normalize
617 ? allowListed.map((address: any) => this.helper.address.normalizeCrossAccountIfSubstrate(address))639 ? allowListed.map((address: CrossAccountId) => address.withNormalizedSubstrate())
618 : allowListed;640 : allowListed;
619 }641 }
620642
1099 */1121 */
1100 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{1122 async getToken(collectionId: number, tokenId: number, propertyKeys: string[] = [], blockHashAt?: string): Promise<{
1101 properties: IProperty[];1123 properties: IProperty[];
1102 owner: ICrossAccountId;1124 owner: CrossAccountId;
1103 normalizedOwner: ICrossAccountId;1125 normalizedOwner: CrossAccountId;
1104 }| null> {1126 }| null> {
1105 let tokenData;1127 let tokenData;
1106 if(typeof blockHashAt === 'undefined') {1128 if(typeof blockHashAt === 'undefined') {
1118 if (tokenData === null || tokenData.owner === null) return null;1140 if (tokenData === null || tokenData.owner === null) return null;
1119 const owner = {} as any;1141 const owner = {} as any;
1120 for (const key of Object.keys(tokenData.owner)) {1142 for (const key of Object.keys(tokenData.owner)) {
1121 owner[key.toLocaleLowerCase()] = this.helper.address.normalizeCrossAccountIfSubstrate(tokenData.owner[key]);1143 owner[key.toLocaleLowerCase()] = new CrossAccountId(tokenData.owner[key]).withNormalizedSubstrate();
1122 }1144 }
1123 tokenData.normalizedOwner = crossAccountIdFromLower(owner);1145 tokenData.normalizedOwner = CrossAccountId.fromLowerCaseKeys(owner);
1124 return tokenData;1146 return tokenData;
1125 }1147 }
11261148
1272 * @example getTokenOwner(10, 5);1294 * @example getTokenOwner(10, 5);
1273 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}1295 * @returns Address in CrossAccountId format, e.g. {Substrate: "5DnSF6RRjwteE3BrCj..."}
1274 */1296 */
1275 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId> {1297 async getTokenOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<CrossAccountId> {
1276 let owner;1298 let owner;
1277 if (typeof blockHashAt === 'undefined') {1299 if (typeof blockHashAt === 'undefined') {
1278 owner = await this.helper.callRpc('api.rpc.unique.tokenOwner', [collectionId, tokenId]);1300 owner = await this.helper.callRpc('api.rpc.unique.tokenOwner', [collectionId, tokenId]);
1279 } else {1301 } else {
1280 owner = await this.helper.callRpc('api.rpc.unique.tokenOwner', [collectionId, tokenId, blockHashAt]);1302 owner = await this.helper.callRpc('api.rpc.unique.tokenOwner', [collectionId, tokenId, blockHashAt]);
1281 }1303 }
1282 return crossAccountIdFromLower(owner.toJSON());1304 return CrossAccountId.fromLowerCaseKeys(owner.toJSON());
1283 }1305 }
12841306
1285 /**1307 /**
1331 * @example getTokenTopmostOwner(10, 5);1353 * @example getTokenTopmostOwner(10, 5);
1332 * @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}1354 * @returns address in CrossAccountId format, e.g. {Substrate: "5DyN4Y92vZCjv38fg..."}
1333 */1355 */
1334 async getTokenTopmostOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<ICrossAccountId | null> {1356 async getTokenTopmostOwner(collectionId: number, tokenId: number, blockHashAt?: string): Promise<CrossAccountId | null> {
1335 let owner;1357 let owner;
1336 if (typeof blockHashAt === 'undefined') {1358 if (typeof blockHashAt === 'undefined') {
1337 owner = await this.helper.callRpc('api.rpc.unique.topmostTokenOwner', [collectionId, tokenId]);1359 owner = await this.helper.callRpc('api.rpc.unique.topmostTokenOwner', [collectionId, tokenId]);
1541 * @example getTokenTop10Owners(10, 5);1563 * @example getTokenTop10Owners(10, 5);
1542 * @returns array of top 10 owners1564 * @returns array of top 10 owners
1543 */1565 */
1544 async getTokenTop10Owners(collectionId: number, tokenId: number): Promise<ICrossAccountId[]> {1566 async getTokenTop10Owners(collectionId: number, tokenId: number): Promise<CrossAccountId[]> {
1545 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, tokenId])).toJSON().map(crossAccountIdFromLower);1567 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, tokenId])).toJSON().map(CrossAccountId.fromLowerCaseKeys);
1546 }1568 }
15471569
1548 /**1570 /**
1825 * @example getTop10Owners(10);1847 * @example getTop10Owners(10);
1826 * @returns array of ```ICrossAccountId```1848 * @returns array of ```ICrossAccountId```
1827 */1849 */
1828 async getTop10Owners(collectionId: number): Promise<ICrossAccountId[]> {1850 async getTop10Owners(collectionId: number): Promise<CrossAccountId[]> {
1829 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(crossAccountIdFromLower);1851 return (await this.helper.callRpc('api.rpc.unique.tokenOwners', [collectionId, 0])).toJSON().map(CrossAccountId.fromLowerCaseKeys);
1830 }1852 }
18311853
1832 /**1854 /**
2045 };2067 };
2046 }2068 }
2047 });2069 });
2048 let isSuccess = this.helper.address.normalizeSubstrate(typeof signer === 'string' ? signer : signer.address) === transfer.from;2070 const isSuccess = this.helper.address.normalizeSubstrate(typeof signer === 'string' ? signer : signer.address) === transfer.from
2049 isSuccess = isSuccess && this.helper.address.normalizeSubstrate(address) === transfer.to;2071 && this.helper.address.normalizeSubstrate(address) === transfer.to
2050 isSuccess = isSuccess && BigInt(amount) === transfer.amount;2072 && BigInt(amount) === transfer.amount;
2051 return isSuccess;2073 return isSuccess;
2052 }2074 }
2053}2075}
2062 * @returns substrate address converted to normalized (i.e., starting with 5) or specified explicitly representation2084 * @returns substrate address converted to normalized (i.e., starting with 5) or specified explicitly representation
2063 */2085 */
2064 normalizeSubstrate(address: TSubstrateAccount, ss58Format = 42): TSubstrateAccount {2086 normalizeSubstrate(address: TSubstrateAccount, ss58Format = 42): TSubstrateAccount {
2065 return this.helper.util.normalizeSubstrateAddress(address, ss58Format);2087 return CrossAccountId.normalizeSubstrateAddress(address, ss58Format);
2066 }2088 }
2067
2068 /**
2069 * Normalizes the address of an account ONLY if it's Substrate to the specified ss58 format, by default ```42```.
2070 * @param account account of either Substrate type or Ethereum, but only Substrate will be changed
2071 * @param ss58Format format for address conversion, by default ```42```
2072 * @example normalizeCrossAccountIfSubstrate({Substrate: "unjKJQJrRd238pkUZZvzDQrfKuM39zBSnQ5zjAGAGcdRhaJTx"}) // returns 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
2073 * @returns untouched ethereum account or substrate account converted to normalized (i.e., starting with 5) or specified explicitly representation
2074 */
2075 normalizeCrossAccountIfSubstrate(account: ICrossAccountId, ss58Format = 42): ICrossAccountId {
2076 return account.Substrate
2077 ? {Substrate: this.normalizeSubstrate(account.Substrate, ss58Format)}
2078 : account;
2079 }
20802089
2081 /**2090 /**
2082 * Get address in the connected chain format2091 * Get address in the connected chain format
2574 return this.collection.helper.util.getTokenAccount(this);2583 return this.collection.helper.util.getTokenAccount(this);
2575 }2584 }
2576
2577 nestingAccountInLowerCase() {
2578 return this.collection.helper.util.getTokenAccountInLowerCase(this);
2579 }
2580}2585}
25812586
25822587