Skip to content

Commit

Permalink
chore: rename by version instead of feature
Browse files Browse the repository at this point in the history
  • Loading branch information
YamenMerhi committed Jul 14, 2023
1 parent cef2dce commit ad34165
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
9 changes: 6 additions & 3 deletions src/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export const ERC725Y_INTERFACE_IDS = {
};

export enum ERC725_VERSION {
ERC725_BATCH = 'ERC725_BATCH', // https://github.com/ERC725Alliance/ERC725/pull/209
ERC725 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/commit/cca7f98cdf243f1ebf1c0a3ae89b1e46931481b0
ERC725_LEGACY = 'ERC725_LEGACY',
NOT_ERC725 = 'NOT_ERC725',
// The ERC725Y_LEGACY version uses getData(bytes32) function
ERC725_LEGACY = 'ERC725_LEGACY',
// The ERC725_v2 version uses getData(bytes32[]) function, as well as v3 and v4
ERC725_v2 = 'ERC725', // https://github.com/ERC725Alliance/ERC725/releases/tag/v2.2.0
// The ERC725_v5 version uses getDataBatch(bytes32[]) function
ERC725_v5 = 'ERC725_v5', // https://github.com/ERC725Alliance/ERC725/releases/tag/v5.0.0
}

export const METHODS: Record<Method, MethodData> = {
Expand Down
4 changes: 2 additions & 2 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ describe('Running @erc725/erc725.js tests...', () => {

describe('Getting data (using new getDataBatch) in schema by provider [e2e] - luksoTestnet', () => {
const web3 = new Web3('https://rpc.testnet.lukso.network');
const ERC725_BATCH_CONTRACT_ADDRESS =
const ERC725_V5_CONTRACT_ADDRESS =
'0x4b30900F119E11D2A8CAe18176c4f9840E586Cc4';

const e2eSchema: any = [
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('Running @erc725/erc725.js tests...', () => {
it('with web3.currentProvider [ERC725Y_BATCH]', async () => {
const erc725 = new ERC725(
e2eSchema,
ERC725_BATCH_CONTRACT_ADDRESS,
ERC725_V5_CONTRACT_ADDRESS,
web3.currentProvider,
);
const result = await erc725.getData();
Expand Down
23 changes: 12 additions & 11 deletions src/provider/providerWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,31 +61,32 @@ export class ProviderWrapper {
}

async getErc725YVersion(address: string): Promise<ERC725_VERSION> {
const isErc725YBatch = await this.supportsInterface(
const isErc725Yv5 = await this.supportsInterface(
address,
ERC725Y_INTERFACE_IDS['5.0'],
);

if (isErc725YBatch) {
return ERC725_VERSION.ERC725_BATCH;
if (isErc725Yv5) {
return ERC725_VERSION.ERC725_v5;
}

const isErc725Y = await this.supportsInterface(
const isErc725Yv3 = await this.supportsInterface(
address,
ERC725Y_INTERFACE_IDS['3.0'],
);

if (isErc725Y) {
return ERC725_VERSION.ERC725;
// The version 3 of the package can use the getData function from v2, still compatible
if (isErc725Yv3) {
return ERC725_VERSION.ERC725_v2;
}

const isErc725Yv200 = await this.supportsInterface(
const isErc725Yv2 = await this.supportsInterface(
address,
ERC725Y_INTERFACE_IDS['2.0'],
);

if (isErc725Yv200) {
return ERC725_VERSION.ERC725;
if (isErc725Yv2) {
return ERC725_VERSION.ERC725_v2;
}

// v0.2.0 and v0.6.0 have the same function signatures for getData, only versions before v0.2.0 requires a different call
Expand Down Expand Up @@ -206,9 +207,9 @@ export class ProviderWrapper {
}

switch (erc725Version) {
case ERC725_VERSION.ERC725_BATCH:
case ERC725_VERSION.ERC725_v5:
return this._getAllDataBatch(address, keyHashes);
case ERC725_VERSION.ERC725:
case ERC725_VERSION.ERC725_v2:
return this._getAllData(address, keyHashes);
case ERC725_VERSION.ERC725_LEGACY:
return this._getAllDataLegacy(address, keyHashes);
Expand Down

0 comments on commit ad34165

Please sign in to comment.