Skip to content

Commit 0d82e47

Browse files
fix: add chain specific feature check errors (#483)
1 parent 72e2323 commit 0d82e47

File tree

11 files changed

+229
-3
lines changed

11 files changed

+229
-3
lines changed

src/common/ens/registration.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import { checkSigner } from '../utils/utils.js';
1919
import { NULL_ADDRESS, APP, DATASET, WORKERPOOL } from '../utils/constant.js';
2020
import { getEnsRegistryAddress } from './registry.js';
2121
import { getOwner, lookupAddress } from './resolution.js';
22+
import {
23+
CHAIN_SPECIFIC_FEATURES,
24+
checkImplementedOnChain,
25+
} from '../utils/config.js';
2226

2327
const debug = Debug('iexec:ens:registration');
2428

@@ -34,6 +38,7 @@ export const getDefaultDomain = async (
3438
address,
3539
) => {
3640
try {
41+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
3742
const vAddress = await addressSchema({
3843
ethProvider: contracts.provider,
3944
})
@@ -66,6 +71,7 @@ export const registerFifsEns = async (
6671
domain = FIFS_DOMAINS.default,
6772
) => {
6873
try {
74+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
6975
checkSigner(contracts);
7076
const vDomain = await ensDomainSchema().validate(domain);
7177
const vLabel = await ensLabelSchema().validate(label);
@@ -129,12 +135,13 @@ export const obsConfigureResolution = (
129135
address,
130136
) =>
131137
new Observable((observer) => {
138+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
139+
checkSigner(contracts);
140+
132141
const safeObserver = new SafeObserver(observer);
133142
let abort = false;
134-
135143
const configure = async () => {
136144
try {
137-
checkSigner(contracts);
138145
const vAddress =
139146
address !== undefined
140147
? await addressSchema({
@@ -367,6 +374,7 @@ export const configureResolution = async (
367374
address,
368375
) => {
369376
try {
377+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
370378
checkSigner(contracts);
371379
const vAddress =
372380
address !== undefined

src/common/ens/resolution.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import {
88
} from '../utils/validator.js';
99
import { wrapCall } from '../utils/errorWrappers.js';
1010
import { getEnsRegistryAddress, checkEns } from './registry.js';
11+
import {
12+
CHAIN_SPECIFIC_FEATURES,
13+
checkImplementedOnChain,
14+
} from '../utils/config.js';
1115

1216
const debug = Debug('iexec:ens:resolution');
1317

@@ -16,6 +20,7 @@ export const getOwner = async (
1620
name = throwIfMissing(),
1721
) => {
1822
try {
23+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
1924
const vName = await ensDomainSchema().validate(name);
2025
const nameHash = namehash(vName);
2126
const ensAddress = await getEnsRegistryAddress(contracts);
@@ -36,6 +41,7 @@ export const resolveName = async (
3641
name = throwIfMissing(),
3742
) => {
3843
try {
44+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
3945
const vName = await ensDomainSchema().validate(name);
4046
await checkEns(contracts);
4147
return await wrapCall(contracts.provider.resolveName(vName));
@@ -47,6 +53,7 @@ export const resolveName = async (
4753

4854
export const lookupAddress = async (contracts = throwIfMissing(), address) => {
4955
try {
56+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
5057
const vAddress = await addressSchema({
5158
ethProvider: contracts.provider,
5259
})

src/common/ens/text-record.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import { getAddress } from '../wallet/address.js';
1111
import { wrapSend, wrapWait, wrapCall } from '../utils/errorWrappers.js';
1212
import { NULL_ADDRESS } from '../utils/constant.js';
1313
import { getOwner } from './resolution.js';
14+
import {
15+
CHAIN_SPECIFIC_FEATURES,
16+
checkImplementedOnChain,
17+
} from '../utils/config.js';
1418

1519
const debug = Debug('iexec:ens:text-record');
1620

@@ -20,6 +24,7 @@ export const readTextRecord = async (
2024
key,
2125
) => {
2226
try {
27+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
2328
const vName = await ensDomainSchema().validate(name);
2429
const vKey = await textRecordKeySchema().validate(key);
2530
const node = namehash(vName);
@@ -52,6 +57,7 @@ export const setTextRecord = async (
5257
value = '',
5358
) => {
5459
try {
60+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.ENS);
5561
const vName = await ensDomainSchema().validate(name);
5662
const vKey = await textRecordKeySchema().validate(key);
5763
const vValue = await textRecordValueSchema().validate(value);

src/common/execution/debug.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ import { jsonApi, getAuthorization } from '../utils/api-utils.js';
1414
import { checkSigner } from '../utils/utils.js';
1515
import { getAddress } from '../wallet/address.js';
1616
import { CompassCallError, WorkerpoolCallError } from '../utils/errors.js';
17+
import {
18+
CHAIN_SPECIFIC_FEATURES,
19+
checkImplementedOnChain,
20+
} from '../utils/config.js';
1721

1822
const debug = Debug('iexec:execution:debug');
1923

@@ -32,6 +36,10 @@ export const getWorkerpoolApiUrl = async (
3236

3337
// Compass base workerpool API URL resolution
3438
if (compassUrl) {
39+
checkImplementedOnChain(
40+
contracts.chainId,
41+
CHAIN_SPECIFIC_FEATURES.COMPASS,
42+
);
3543
const json = await jsonApi.get({
3644
api: compassUrl,
3745
endpoint: `/${contracts.chainId}/workerpools/${vAddress}`,

src/common/execution/workerpool.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
import { lookupAddress } from '../ens/resolution.js';
88
import { setTextRecord } from '../ens/text-record.js';
99
import { WORKERPOOL_URL_TEXT_RECORD_KEY } from '../utils/constant.js';
10+
import {
11+
CHAIN_SPECIFIC_FEATURES,
12+
checkImplementedOnChain,
13+
} from '../utils/config.js';
1014

1115
const debug = Debug('iexec:execution:workerpool');
1216

@@ -16,6 +20,10 @@ export const setWorkerpoolApiUrl = async (
1620
url,
1721
) => {
1822
try {
23+
checkImplementedOnChain(
24+
contracts.chainId,
25+
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
26+
);
1927
const vAddress = await addressSchema({
2028
ethProvider: contracts.provider,
2129
})

src/common/market/order.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ import {
6363
import { getVoucherHubContract } from '../utils/voucher-utils.js';
6464
import { checkAllowance } from '../account/allowance.js';
6565
import { fetchVoucherContract } from '../voucher/voucher.js';
66+
import {
67+
CHAIN_SPECIFIC_FEATURES,
68+
checkImplementedOnChain,
69+
} from '../utils/config.js';
6670

6771
const debug = Debug('iexec:market:order');
6872

@@ -818,6 +822,9 @@ export const estimateMatchOrders = async ({
818822
.label('voucherAddress')
819823
.validate(voucherAddress),
820824
]);
825+
if (!vUseVoucher) {
826+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
827+
}
821828
const matchableVolume = await getMatchableVolume(
822829
contracts,
823830
vAppOrder,
@@ -938,6 +945,12 @@ export const matchOrders = async ({
938945
.label('voucherAddress')
939946
.validate(voucherAddress),
940947
]);
948+
if (vUseVoucher) {
949+
checkImplementedOnChain(
950+
contracts.chainId,
951+
CHAIN_SPECIFIC_FEATURES.VOUCHER,
952+
);
953+
}
941954

942955
// check resulting tag
943956
await tagSchema()

src/common/utils/config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import { EnsPlugin, Network } from 'ethers';
22
import { address as voucherHubBellecourAddress } from '../generated/@iexec/voucher-contracts/deployments/bellecour/VoucherHubERC1967Proxy.js';
33
import { TEE_FRAMEWORKS } from './constant.js';
44

5+
export const CHAIN_SPECIFIC_FEATURES = {
6+
ENS: 'ENS',
7+
WORKERPOOL_API_URL_REGISTRATION: 'Workerpool API Registration',
8+
VOUCHER: 'iExec Voucher',
9+
COMPASS: 'iExec Compass',
10+
XRLC_BRIDGE: 'iExec xRLC Bridge',
11+
};
12+
513
const networkConfigs = [
614
{
715
id: 134,
@@ -28,6 +36,7 @@ const networkConfigs = [
2836
},
2937
shouldRegisterNetwork: true,
3038
isExperimental: false,
39+
notImplemented: [CHAIN_SPECIFIC_FEATURES.COMPASS],
3140
},
3241
{
3342
id: 1,
@@ -50,6 +59,10 @@ const networkConfigs = [
5059
},
5160
shouldRegisterNetwork: false,
5261
isExperimental: false,
62+
notImplemented: [
63+
CHAIN_SPECIFIC_FEATURES.COMPASS,
64+
CHAIN_SPECIFIC_FEATURES.VOUCHER,
65+
],
5366
},
5467
{
5568
id: 421614,
@@ -72,6 +85,12 @@ const networkConfigs = [
7285
bridge: {}, // no bridge
7386
shouldRegisterNetwork: false,
7487
isExperimental: false,
88+
notImplemented: [
89+
CHAIN_SPECIFIC_FEATURES.ENS,
90+
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
91+
CHAIN_SPECIFIC_FEATURES.VOUCHER,
92+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
93+
],
7594
},
7695
{
7796
id: 42161,
@@ -93,6 +112,12 @@ const networkConfigs = [
93112
voucherSubgraph: undefined, // no voucher
94113
bridge: {}, // no bridge
95114
shouldRegisterNetwork: false,
115+
notImplemented: [
116+
CHAIN_SPECIFIC_FEATURES.ENS,
117+
CHAIN_SPECIFIC_FEATURES.WORKERPOOL_API_URL_REGISTRATION,
118+
CHAIN_SPECIFIC_FEATURES.VOUCHER,
119+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
120+
],
96121
},
97122
];
98123

@@ -147,6 +172,20 @@ export const getChainDefaults = (
147172
};
148173
};
149174

175+
export const checkImplementedOnChain = (chainId, featureName) => {
176+
const networkConfig = networkConfigs.find(
177+
(network) => `${network.id}` === `${chainId}`,
178+
);
179+
if (
180+
networkConfig?.notImplemented &&
181+
networkConfig.notImplemented.includes(featureName)
182+
) {
183+
throw new Error(
184+
`${featureName} is not available on network ${networkConfig.name}`,
185+
);
186+
}
187+
};
188+
150189
// Register unknown networks and their ENS settings for the ethers library
151190
networkConfigs.forEach((networkConfig) => {
152191
if (

src/common/voucher/voucher.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
getVoucherContract,
1111
getVoucherSubgraphClient,
1212
} from '../utils/voucher-utils.js';
13+
import {
14+
CHAIN_SPECIFIC_FEATURES,
15+
checkImplementedOnChain,
16+
} from '../utils/config.js';
1317

1418
const debug = Debug('iexec:voucher:voucher');
1519

@@ -78,6 +82,7 @@ export const showUserVoucher = async (
7882
owner = throwIfMissing(),
7983
) => {
8084
try {
85+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
8186
const vOwner = await addressSchema({
8287
ethProvider: contracts.provider,
8388
})
@@ -139,6 +144,7 @@ export const authorizeRequester = async (
139144
requester,
140145
) => {
141146
try {
147+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
142148
checkSigner(contracts);
143149
const userAddress = await getAddress(contracts);
144150
const vRequester = await addressSchema({
@@ -180,6 +186,7 @@ export const revokeRequesterAuthorization = async (
180186
requester,
181187
) => {
182188
try {
189+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
183190
checkSigner(contracts);
184191
const userAddress = await getAddress(contracts);
185192
const vRequester = await addressSchema({

src/common/voucher/voucherHub.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { addressSchema, throwIfMissing } from '../utils/validator.js';
44
import { wrapCall } from '../utils/errorWrappers.js';
55
import { NULL_ADDRESS } from '../utils/constant.js';
66
import { getVoucherHubContract } from '../utils/voucher-utils.js';
7+
import {
8+
CHAIN_SPECIFIC_FEATURES,
9+
checkImplementedOnChain,
10+
} from '../utils/config.js';
711

812
const debug = Debug('iexec:voucher:voucherHub');
913

@@ -13,6 +17,7 @@ export const fetchVoucherAddress = async (
1317
owner,
1418
) => {
1519
try {
20+
checkImplementedOnChain(contracts.chainId, CHAIN_SPECIFIC_FEATURES.VOUCHER);
1621
const vOwner = await addressSchema({ ethProvider: contracts.provider })
1722
.required()
1823
.label('owner')

src/common/wallet/bridge.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import { abi as HomeBridgeErcToNativeAbi } from './abi/HomeBridgeErcToNative.js'
2121
import { getAddress } from './address.js';
2222
import { getRlcBalance } from './balance.js';
2323
import { sendRLC } from './send.js';
24+
import {
25+
CHAIN_SPECIFIC_FEATURES,
26+
checkImplementedOnChain,
27+
} from '../utils/config.js';
2428

2529
const debug = Debug('iexec:wallet:bridge');
2630

@@ -69,6 +73,10 @@ export const obsBridgeToSidechain = (
6973
{ sidechainBridgeAddress, bridgedContracts } = {},
7074
) =>
7175
new Observable((observer) => {
76+
checkImplementedOnChain(
77+
contracts.chainId,
78+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
79+
);
7280
const safeObserver = new SafeObserver(observer);
7381
let abort;
7482
let stopWatchPromise;
@@ -289,6 +297,10 @@ export const bridgeToSidechain = async (
289297
nRlcAmount = throwIfMissing(),
290298
{ sidechainBridgeAddress, bridgedContracts } = {},
291299
) => {
300+
checkImplementedOnChain(
301+
contracts.chainId,
302+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
303+
);
292304
checkSigner(contracts);
293305
let sendTxHash;
294306
let receiveTxHash;
@@ -326,6 +338,10 @@ export const obsBridgeToMainchain = (
326338
{ mainchainBridgeAddress, bridgedContracts } = {},
327339
) =>
328340
new Observable((observer) => {
341+
checkImplementedOnChain(
342+
contracts.chainId,
343+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
344+
);
329345
const safeObserver = new SafeObserver(observer);
330346
let abort;
331347
let stopWatchPromise;
@@ -517,6 +533,10 @@ export const bridgeToMainchain = async (
517533
nRlcAmount = throwIfMissing(),
518534
{ mainchainBridgeAddress, bridgedContracts } = {},
519535
) => {
536+
checkImplementedOnChain(
537+
contracts.chainId,
538+
CHAIN_SPECIFIC_FEATURES.XRLC_BRIDGE,
539+
);
520540
checkSigner(contracts);
521541
let sendTxHash;
522542
let receiveTxHash;

0 commit comments

Comments
 (0)