mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix encrypt fucntion
This commit is contained in:
parent
fea7eca0a1
commit
cb779eaf0d
@ -1,5 +1,5 @@
|
|||||||
import Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { LoggerInstance } from '../utils'
|
import { LoggerInstance, fetchData, getData } from '../utils'
|
||||||
import {
|
import {
|
||||||
Asset,
|
Asset,
|
||||||
FileMetadata,
|
FileMetadata,
|
||||||
@ -25,9 +25,9 @@ export class Provider {
|
|||||||
* @param {any} fetchMethod
|
* @param {any} fetchMethod
|
||||||
* @return {Promise<ServiceEndpoint[]>}
|
* @return {Promise<ServiceEndpoint[]>}
|
||||||
*/
|
*/
|
||||||
async getEndpoints(providerUri: string, fetchMethod: any): Promise<any> {
|
async getEndpoints(providerUri: string): Promise<any> {
|
||||||
try {
|
try {
|
||||||
const endpoints = await await fetchMethod(providerUri).json()
|
const endpoints = await (await getData(providerUri)).json()
|
||||||
return endpoints
|
return endpoints
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error('Finding the service endpoints failed:', e)
|
LoggerInstance.error('Finding the service endpoints failed:', e)
|
||||||
@ -77,7 +77,7 @@ export class Provider {
|
|||||||
serviceEndpoints?: ServiceEndpoint[]
|
serviceEndpoints?: ServiceEndpoint[]
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
if (!providerEndpoints) {
|
if (!providerEndpoints) {
|
||||||
providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
}
|
}
|
||||||
if (!serviceEndpoints) {
|
if (!serviceEndpoints) {
|
||||||
serviceEndpoints = await this.getServiceEndpoints(providerUri, providerEndpoints)
|
serviceEndpoints = await this.getServiceEndpoints(providerUri, providerEndpoints)
|
||||||
@ -128,7 +128,7 @@ export class Provider {
|
|||||||
providerUri: string,
|
providerUri: string,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -162,7 +162,7 @@ export class Provider {
|
|||||||
providerUri: string,
|
providerUri: string,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
): Promise<FileMetadata[]> {
|
): Promise<FileMetadata[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -204,7 +204,7 @@ export class Provider {
|
|||||||
fetchMethod: any,
|
fetchMethod: any,
|
||||||
userCustomParameters?: UserCustomParameters
|
userCustomParameters?: UserCustomParameters
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -253,7 +253,7 @@ export class Provider {
|
|||||||
fetchMethod: any,
|
fetchMethod: any,
|
||||||
userCustomParameters?: UserCustomParameters
|
userCustomParameters?: UserCustomParameters
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -315,7 +315,7 @@ export class Provider {
|
|||||||
fetchMethod: any,
|
fetchMethod: any,
|
||||||
output?: ComputeOutput
|
output?: ComputeOutput
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -384,7 +384,7 @@ export class Provider {
|
|||||||
web3: Web3,
|
web3: Web3,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -452,7 +452,7 @@ export class Provider {
|
|||||||
fetchMethod: any,
|
fetchMethod: any,
|
||||||
jobId?: string
|
jobId?: string
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -522,7 +522,7 @@ export class Provider {
|
|||||||
web3: Web3,
|
web3: Web3,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
@ -581,7 +581,7 @@ export class Provider {
|
|||||||
web3: Web3,
|
web3: Web3,
|
||||||
fetchMethod: any
|
fetchMethod: any
|
||||||
): Promise<ComputeJob | ComputeJob[]> {
|
): Promise<ComputeJob | ComputeJob[]> {
|
||||||
const providerEndpoints = await this.getEndpoints(providerUri, fetchMethod)
|
const providerEndpoints = await this.getEndpoints(providerUri)
|
||||||
const serviceEndpoints = await this.getServiceEndpoints(
|
const serviceEndpoints = await this.getServiceEndpoints(
|
||||||
providerUri,
|
providerUri,
|
||||||
providerEndpoints
|
providerEndpoints
|
||||||
|
@ -10,3 +10,37 @@ export async function fetchData(url: string, opts: RequestInit): Promise<Respons
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getData(url: string): Promise<Response> {
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async function postWithHeaders(
|
||||||
|
url: string,
|
||||||
|
payload: BodyInit,
|
||||||
|
headers: any
|
||||||
|
): Promise<Response> {
|
||||||
|
if (payload != null) {
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST',
|
||||||
|
body: payload,
|
||||||
|
headers
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
return fetch(url, {
|
||||||
|
method: 'POST'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function postData(url: string, payload: BodyInit): Promise<Response> {
|
||||||
|
const headers = {
|
||||||
|
'Content-type': 'application/json'
|
||||||
|
}
|
||||||
|
return postWithHeaders(url, payload, headers)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user