diff --git a/integration/config.ts b/integration/config.ts index c3fa6c3..3d2bd3d 100644 --- a/integration/config.ts +++ b/integration/config.ts @@ -6,7 +6,7 @@ const configJson: Config = { aquariusUri: 'http://aquarius:5000', brizoUri: 'http://localhost:8030', secretStoreUri: 'http://localhost:12001', - brizoAddress: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0', + brizoAddress: '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0', verbose: false } diff --git a/integration/ocean/ConsumeAsset.test.ts b/integration/ocean/ConsumeAsset.test.ts index be85f89..48a933b 100644 --- a/integration/ocean/ConsumeAsset.test.ts +++ b/integration/ocean/ConsumeAsset.test.ts @@ -90,7 +90,8 @@ describe('Consume Asset', () => { accessService.index, serviceAgreementSignatureResult.signature, consumer, - publisher + config.brizoAddress, + consumer ) assert.isTrue(success) diff --git a/integration/ocean/ConsumeAssetBrizo.test.ts b/integration/ocean/ConsumeAssetBrizo.test.ts index 4459f1b..53c5924 100644 --- a/integration/ocean/ConsumeAssetBrizo.test.ts +++ b/integration/ocean/ConsumeAssetBrizo.test.ts @@ -39,7 +39,7 @@ describe('Consume Asset (Brizo)', () => { await consumer.authenticate() }) - it('should regiester an asset', async () => { + it('should register an asset', async () => { const steps = [] ddo = await ocean.assets .create(metadata as any, publisher) diff --git a/integration/ocean/ConsumeBigAsset.test.ts b/integration/ocean/ConsumeBigAsset.test.ts index ca2223f..b1d1f22 100644 --- a/integration/ocean/ConsumeBigAsset.test.ts +++ b/integration/ocean/ConsumeBigAsset.test.ts @@ -43,7 +43,7 @@ xdescribe('Consume Asset (Large size)', () => { } }) - it('should regiester an asset', async () => { + it('should register an asset', async () => { ddo = await ocean.assets.create(metadata as any, publisher) assert.instanceOf(ddo, DDO) diff --git a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts index 9100faa..acb56f4 100644 --- a/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts +++ b/integration/ocean/RegisterEscrowAccessSecretStoreTemplate.test.ts @@ -154,8 +154,8 @@ describe('Register Escrow Access Secret Store Template', () => { [conditionIdLock, conditionIdAccess, conditionIdEscrow], [0, 0, 0], [0, 0, 0], - [consumer.getId(), publisher.getId()], - publisher.getId() + [consumer.getId(), config.brizoAddress], + consumer.getId() ) assert.isTrue(agreement.status) @@ -247,7 +247,8 @@ describe('Register Escrow Access Secret Store Template', () => { did, escrowAmount, consumer.getId(), - publisher.getId() + config.brizoAddress, + consumer.getId() ) assert.match(agreementId, /^0x[a-f0-9]{64}$/i) diff --git a/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts b/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts index 305402f..7f476fa 100644 --- a/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts +++ b/integration/ocean/RegisterEscrowComputeExecutionTemplate.test.ts @@ -152,8 +152,8 @@ describe('Register Escrow Compute Execution Template', () => { [conditionIdLock, conditionIdCompute, conditionIdEscrow], [0, 0, 0], [0, 0, 0], - [consumer.getId(), publisher.getId()], - publisher.getId() + [consumer.getId(), config.brizoAddress], + consumer.getId() ) assert.isTrue(agreement.status) @@ -245,7 +245,8 @@ describe('Register Escrow Compute Execution Template', () => { did, escrowAmount, consumer.getId(), - publisher.getId() + config.brizoAddress, + consumer.getId() ) assert.match(agreementId, /^0x[a-f0-9]{64}$/i) diff --git a/src/keeper/contracts/DIDRegistry.ts b/src/keeper/contracts/DIDRegistry.ts index 35e41ac..026491d 100644 --- a/src/keeper/contracts/DIDRegistry.ts +++ b/src/keeper/contracts/DIDRegistry.ts @@ -37,6 +37,11 @@ export default class DIDRegistry extends ContractBase { return this.call('isDIDProvider', [didZeroX(did), zeroX(provider)]) } + public async getDIDProviders(did: string): Promise { + const { providers } = await this.call('getDIDRegister', [didZeroX(did)]) + return providers + } + public async getAttributesByOwner(owner: string): Promise { return ( await this.getPastEvents('DIDAttributeRegistered', { diff --git a/src/keeper/contracts/templates/AgreementTemplateBase.ts b/src/keeper/contracts/templates/AgreementTemplateBase.ts index b8b2683..6757a6a 100644 --- a/src/keeper/contracts/templates/AgreementTemplateBase.ts +++ b/src/keeper/contracts/templates/AgreementTemplateBase.ts @@ -16,6 +16,7 @@ import { ConditionState, conditionStateNames } from '../conditions' +import {ServiceType} from "../../../ddo/Service"; export interface Conditions { lockRewardCondition: LockRewardCondition @@ -65,13 +66,16 @@ export class AgreementTemplateBase { public async createAgreementFromDDO( agreementId: string, ddo: DDO, + serviceType: ServiceType, consumer: string, + provider: string, from?: string ) { return !!(await this.createFullAgreement( ddo.shortId(), - ddo.findServiceByType('metadata').attributes.main.price, + ddo.findServiceByType(serviceType).attributes.main.price, consumer, + provider, from, agreementId )) @@ -104,6 +108,7 @@ export class AgreementTemplateBase { * @param {string} did Asset DID. * @param {number} amount Asset price. * @param {string} consumer ethereum address of consumer. + * @param {string} provider ethereum address of service provider (brizo address) * @param {string} from Consumer address. * @param {string} agreementId bytes32 agreement id. * @@ -113,6 +118,7 @@ export class AgreementTemplateBase { did: string, amount: number | string, consumer: string, + provider: string, from?: string, agreementId: string = generateId() ): Promise { @@ -123,7 +129,6 @@ export class AgreementTemplateBase { consumer ) - const publisher = await this.didRegistry.getDIDOwner(did) const timeouts = [0, 0, 0] const timelocks = [0, 0, 0] await this.agreementStoreManager.createAgreement( @@ -133,10 +138,9 @@ export class AgreementTemplateBase { conditionIds, timelocks, timeouts, - [consumer, publisher], + [consumer, provider], from ) - return zeroX(agreementId) } diff --git a/src/ocean/OceanAgreements.ts b/src/ocean/OceanAgreements.ts index 35c7eda..0ba2dd3 100644 --- a/src/ocean/OceanAgreements.ts +++ b/src/ocean/OceanAgreements.ts @@ -106,7 +106,8 @@ export class OceanAgreements extends Instantiable { * @param {number} index Service index. * @param {string} signature Service agreement signature. * @param {Account} consumer Consumer account. - * @param {Account} publisher Publisher account. + * @param {string} provider ethereum address of service provider + * @param {Account} from account of party creating the agreement (usually the consumer). * @return {Promise} */ public async create( @@ -115,16 +116,23 @@ export class OceanAgreements extends Instantiable { index: number, signature: string, consumer: Account, - publisher: Account + provider: string, + from: Account ) { const d: DID = DID.parse(did) const ddo = await this.ocean.aquarius.retrieveDDO(d) - - const templateName = ddo.findServiceById<'access'>(index).attributes - .serviceAgreementTemplate.contractName + const service = ddo.findServiceById(index) + const templateName = service.attributes.serviceAgreementTemplate.contractName await this.ocean.keeper .getTemplateByName(templateName) - .createAgreementFromDDO(agreementId, ddo, consumer.getId(), publisher.getId()) + .createAgreementFromDDO( + agreementId, + ddo, + service.type, + consumer.getId(), + provider, + from.getId() + ) return true } @@ -151,7 +159,7 @@ export class OceanAgreements extends Instantiable { ) if (templateId === `0x${'0'.repeat(64)}`) { - console.error('agreement is not found: ' + agreementId + ' ' + templateId) + this.logger.error(`agreement ${agreementId} is not found, templateId is ${templateId}`) return } diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 8f558eb..5d566d8 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -284,12 +284,14 @@ export class OceanAssets extends Instantiable { * @param {string} did Decentralized ID. * @param {number} index Service index. * @param {Account} consumer Consumer account. + * @param {string} provider ethereum address of service provider (optional) * @return {Promise} Returns Agreement ID */ public order( did: string, index: number, - consumer: Account + consumer: Account, + provider?: string ): SubscribablePromise { return new SubscribablePromise(async observer => { const oceanAgreements = this.ocean.agreements @@ -343,12 +345,22 @@ export class OceanAssets extends Instantiable { observer.next(OrderProgressStep.CreatingAgreement) this.logger.log('Creating agreement') + + // Get provider from didRegistry if not given in arguments + if (!provider) { + const providers = await keeper.didRegistry.getDIDProviders(ddo.shortId()) + if (!!providers) { + provider = providers[0] + } + } + await oceanAgreements.create( did, agreementId, index, undefined, consumer, + provider, consumer ) this.logger.log('Agreement created')