Skip to content

Commit 2f9b242

Browse files
don't fallback to default chain config
1 parent 1038ad5 commit 2f9b242

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

packages/sdk/src/lib/IExecDataProtectorModule.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { GraphQLClient } from 'graphql-request';
77
import { IExec } from 'iexec';
88
import {
99
CHAIN_CONFIG,
10-
DEFAULT_CHAIN_ID,
1110
} from '../config/config.js';
11+
import { getChainIdFromProvider } from '../utils/getChainId.js';
1212
import {
1313
AddressOrENS,
1414
DataProtectorConfigOptions,
1515
Web3SignerProvider,
1616
} from './types/index.js';
17-
import { getChainIdFromProvider } from '../utils/getChainId.js';
1817

1918
type EthersCompatibleProvider =
2019
| AbstractProvider
@@ -79,49 +78,64 @@ abstract class IExecDataProtectorModule {
7978

8079
private async resolveConfig(): Promise<IExecDataProtectorResolvedConfig> {
8180
const chainId = await getChainIdFromProvider(this.ethProvider);
82-
const config = CHAIN_CONFIG[chainId] || CHAIN_CONFIG[DEFAULT_CHAIN_ID];
81+
const chainDefaultConfig = CHAIN_CONFIG[chainId];
82+
83+
const subgraphUrl = this.options?.subgraphUrl || chainDefaultConfig?.subgraphUrl;
84+
const dataprotectorContractAddress = this.options?.dataprotectorContractAddress || chainDefaultConfig?.dataprotectorContractAddress;
85+
const sharingContractAddress = this.options?.sharingContractAddress || chainDefaultConfig?.sharingContractAddress;
86+
const ipfsGateway = this.options?.ipfsGateway || chainDefaultConfig?.ipfsGateway;
87+
const ipfsNode = this.options?.ipfsNode || chainDefaultConfig?.ipfsNode;
88+
const smsURL = this.options?.iexecOptions?.smsDebugURL || chainDefaultConfig?.smsDebugURL;
89+
90+
const missing = [];
91+
if (!subgraphUrl) missing.push('subgraphUrl');
92+
if (!dataprotectorContractAddress) missing.push('dataprotectorContractAddress');
93+
if (!sharingContractAddress) missing.push('sharingContractAddress');
94+
if (!ipfsGateway) missing.push('ipfsGateway');
95+
if (!ipfsNode) missing.push('ipfsNode');
96+
if (!smsURL) missing.push('smsDebugURL');
97+
98+
if (missing.length > 0) {
99+
throw new Error(
100+
`Missing required configuration for chainId ${chainId}: ${missing.join(', ')}`
101+
);
102+
}
83103

84104
let iexec: IExec, iexecDebug: IExec, graphQLClient: GraphQLClient;
85105

86106
try {
87107
iexec = new IExec(
88108
{ ethProvider: this.ethProvider },
89109
{
90-
ipfsGatewayURL: config.ipfsGateway,
110+
ipfsGatewayURL: ipfsGateway,
91111
...this.options?.iexecOptions,
92112
}
93113
);
94114

95115
iexecDebug = new IExec(
96116
{ ethProvider: this.ethProvider },
97117
{
98-
ipfsGatewayURL: config.ipfsGateway,
118+
ipfsGatewayURL: ipfsGateway,
99119
...this.options?.iexecOptions,
100-
smsURL: this.options?.iexecOptions?.smsDebugURL || config.smsDebugURL,
120+
smsURL,
101121
}
102122
);
103123
} catch (e: any) {
104124
throw new Error(`Unsupported ethProvider: ${e.message}`);
105125
}
106126

107127
try {
108-
graphQLClient = new GraphQLClient(
109-
this.options?.subgraphUrl || config.subgraphUrl
110-
);
128+
graphQLClient = new GraphQLClient(subgraphUrl);
111129
} catch (error: any) {
112130
throw new Error(`Failed to create GraphQLClient: ${error.message}`);
113131
}
114132

115133
return {
116-
dataprotectorContractAddress:
117-
this.options?.dataprotectorContractAddress?.toLowerCase() ||
118-
config.dataprotectorContractAddress,
119-
sharingContractAddress:
120-
this.options?.sharingContractAddress?.toLowerCase() ||
121-
config.sharingContractAddress,
134+
dataprotectorContractAddress: dataprotectorContractAddress.toLowerCase(),
135+
sharingContractAddress: sharingContractAddress.toLowerCase(),
122136
graphQLClient,
123-
ipfsNode: this.options?.ipfsNode || config.ipfsNode,
124-
ipfsGateway: config.ipfsGateway,
137+
ipfsNode,
138+
ipfsGateway,
125139
iexec,
126140
iexecDebug,
127141
};

0 commit comments

Comments
 (0)