mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
use compute serviceEndpoint from DDO
This commit is contained in:
parent
40754ca46a
commit
f3cbf1ad01
@ -2,6 +2,8 @@ import { File, MetaData } from '../ddo/MetaData'
|
||||
import Account from '../ocean/Account'
|
||||
import { noZeroX } from '../utils'
|
||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||
import { DDO } from '../ddo/DDO'
|
||||
import { ServiceType } from '../ddo/Service'
|
||||
|
||||
const apiPath = '/api/v1/brizo/services'
|
||||
|
||||
@ -39,6 +41,18 @@ export class Brizo extends Instantiable {
|
||||
return `${this.url}${apiPath}/compute`
|
||||
}
|
||||
|
||||
public async getEndpointFromAgreement(
|
||||
type: ServiceType,
|
||||
agreementId: string
|
||||
): Promise<string> {
|
||||
const { assets, keeper } = this.ocean
|
||||
const { did } = await keeper.agreementStoreManager.getAgreement(agreementId)
|
||||
const ddo: DDO = await assets.resolve(did)
|
||||
const { serviceEndpoint } = ddo.findServiceByType(type)
|
||||
|
||||
return serviceEndpoint
|
||||
}
|
||||
|
||||
public async initializeServiceAgreement(
|
||||
did: string,
|
||||
serviceAgreementId: string,
|
||||
@ -105,9 +119,19 @@ export class Brizo extends Instantiable {
|
||||
): Promise<any> {
|
||||
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
|
||||
const address = consumerAccount.getId()
|
||||
const serviceEndpoint = await this.getEndpointFromAgreement(
|
||||
'compute',
|
||||
serviceAgreementId
|
||||
)
|
||||
|
||||
if (!serviceEndpoint) {
|
||||
throw new Error(
|
||||
'Computing on asset failed, service definition is missing the `serviceEndpoint`.'
|
||||
)
|
||||
}
|
||||
|
||||
// construct Brizo URL
|
||||
let url = this.getComputeEndpoint()
|
||||
let url = serviceEndpoint
|
||||
url += `&signature=${signature}`
|
||||
url += `&consumerAddress=${address}`
|
||||
url += `&serviceAgreementId=${noZeroX(serviceAgreementId)}`
|
||||
|
Loading…
Reference in New Issue
Block a user