@@ -13,12 +13,13 @@ import { WORKERPOOL_URL_TEXT_RECORD_KEY } from '../utils/constant.js';
1313import { jsonApi , getAuthorization } from '../utils/api-utils.js' ;
1414import { checkSigner } from '../utils/utils.js' ;
1515import { getAddress } from '../wallet/address.js' ;
16- import { WorkerpoolCallError } from '../utils/errors.js' ;
16+ import { CompassCallError , WorkerpoolCallError } from '../utils/errors.js' ;
1717
1818const debug = Debug ( 'iexec:execution:debug' ) ;
1919
2020export const getWorkerpoolApiUrl = async (
2121 contracts = throwIfMissing ( ) ,
22+ compassUrl ,
2223 workerpoolAddress ,
2324) => {
2425 try {
@@ -28,6 +29,21 @@ export const getWorkerpoolApiUrl = async (
2829 . required ( )
2930 . label ( 'workerpool address' )
3031 . validate ( workerpoolAddress ) ;
32+
33+ // Compass base workerpool API URL resolution
34+ if ( compassUrl ) {
35+ const json = await jsonApi . get ( {
36+ api : compassUrl ,
37+ endpoint : `/${ contracts . chainId } /workerpools/${ vAddress } ` ,
38+ ApiCallErrorClass : CompassCallError ,
39+ } ) ;
40+ if ( ! json ?. apiUrl ) {
41+ throw new Error ( `No apiUrl found in compass response` ) ;
42+ }
43+ return json . apiUrl ;
44+ }
45+
46+ // ENS based workerpool API URL resolution
3147 const name = await lookupAddress ( contracts , vAddress ) . catch ( ( ) => {
3248 /** return undefined */
3349 } ) ;
@@ -53,6 +69,7 @@ export const getWorkerpoolApiUrl = async (
5369
5470const getTaskOffchainApiUrl = async (
5571 contracts = throwIfMissing ( ) ,
72+ compassUrl ,
5673 taskid = throwIfMissing ( ) ,
5774) => {
5875 try {
@@ -63,7 +80,11 @@ const getTaskOffchainApiUrl = async (
6380 if ( ! workerpool ) {
6481 throw Error ( `Cannot find task's workerpool` ) ;
6582 }
66- const workerpoolApiUrl = await getWorkerpoolApiUrl ( contracts , workerpool ) ;
83+ const workerpoolApiUrl = await getWorkerpoolApiUrl (
84+ contracts ,
85+ compassUrl ,
86+ workerpool ,
87+ ) ;
6788 if ( ! workerpoolApiUrl ) {
6889 throw Error ( `Impossible to resolve API url for workerpool ${ workerpool } ` ) ;
6990 }
@@ -76,11 +97,16 @@ const getTaskOffchainApiUrl = async (
7697
7798export const fetchTaskOffchainInfo = async (
7899 contracts = throwIfMissing ( ) ,
100+ compassURL ,
79101 taskid = throwIfMissing ( ) ,
80102) => {
81103 try {
82104 const vTaskid = await bytes32Schema ( ) . validate ( taskid ) ;
83- const workerpoolApiUrl = await getTaskOffchainApiUrl ( contracts , vTaskid ) ;
105+ const workerpoolApiUrl = await getTaskOffchainApiUrl (
106+ contracts ,
107+ compassURL ,
108+ vTaskid ,
109+ ) ;
84110 const data = await jsonApi . get ( {
85111 api : workerpoolApiUrl ,
86112 endpoint : `/tasks/${ vTaskid } ` ,
@@ -106,12 +132,17 @@ export const fetchTaskOffchainInfo = async (
106132
107133export const fetchAllReplicatesLogs = async (
108134 contracts = throwIfMissing ( ) ,
135+ compassURL ,
109136 taskid = throwIfMissing ( ) ,
110137) => {
111138 try {
112139 checkSigner ( contracts ) ;
113140 const vTaskid = await bytes32Schema ( ) . validate ( taskid ) ;
114- const workerpoolApiUrl = await getTaskOffchainApiUrl ( contracts , vTaskid ) ;
141+ const workerpoolApiUrl = await getTaskOffchainApiUrl (
142+ contracts ,
143+ compassURL ,
144+ vTaskid ,
145+ ) ;
115146 const { dealid } = await taskShow ( contracts , vTaskid ) ;
116147 const { requester } = await dealShow ( contracts , dealid ) ;
117148 const userAddress = await getAddress ( contracts ) ;
0 commit comments