1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

update get compute env return type (#1721)

This commit is contained in:
Bogdan Fazakas 2023-05-03 09:21:21 +03:00 committed by GitHub
parent 15ac930e88
commit 59568d292e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -238,13 +238,16 @@ export class Provider {
} }
} }
/** Get Compute Environments /**
* @return {Promise<ComputeEnvironment[]>} urlDetails * Returns compute environments from a provider.
* @param {string} providerUri - The URI of the provider.
* @param {AbortSignal} [signal] - An optional abort signal.
* @returns {Promise<{[chainId: number]: ComputeEnvironment[]}>} A promise that resolves with an object containing compute environments for each chain ID.
*/ */
public async getComputeEnvironments( public async getComputeEnvironments(
providerUri: string, providerUri: string,
signal?: AbortSignal signal?: AbortSignal
): Promise<ComputeEnvironment[]> { ): Promise<{ [chainId: number]: ComputeEnvironment[] }> {
const providerEndpoints = await this.getEndpoints(providerUri) const providerEndpoints = await this.getEndpoints(providerUri)
const serviceEndpoints = await this.getServiceEndpoints( const serviceEndpoints = await this.getServiceEndpoints(
providerUri, providerUri,
@ -258,8 +261,12 @@ export class Provider {
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
signal signal
}) })
const envs: ComputeEnvironment[] = await response.json() const result = response.json()
return envs if (Array.isArray(result)) {
const providerChain: number = providerEndpoints.chainId
return { [providerChain]: result }
}
return result
} catch (e) { } catch (e) {
LoggerInstance.error(e) LoggerInstance.error(e)
throw new Error('HTTP request failed calling Provider') throw new Error('HTTP request failed calling Provider')