1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Fix issues in creating agreement. Mainly the issue was using the publisher address in place of the provider's in the actors list when creating agreement. This also adds an optional provider argument to the order method. Add method to fetch providers of a did (via the didRegistry).

This commit is contained in:
ssallam 2020-01-22 13:46:10 +01:00
parent b06d8a78df
commit 26de27a31b
10 changed files with 54 additions and 22 deletions

View File

@ -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
}

View File

@ -90,7 +90,8 @@ describe('Consume Asset', () => {
accessService.index,
serviceAgreementSignatureResult.signature,
consumer,
publisher
config.brizoAddress,
consumer
)
assert.isTrue(success)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -37,6 +37,11 @@ export default class DIDRegistry extends ContractBase {
return this.call('isDIDProvider', [didZeroX(did), zeroX(provider)])
}
public async getDIDProviders(did: string): Promise<string[]> {
const { providers } = await this.call('getDIDRegister', [didZeroX(did)])
return providers
}
public async getAttributesByOwner(owner: string): Promise<string[]> {
return (
await this.getPastEvents('DIDAttributeRegistered', {

View File

@ -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<string> {
@ -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)
}

View File

@ -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<boolean>}
*/
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
}

View File

@ -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<string>} Returns Agreement ID
*/
public order(
did: string,
index: number,
consumer: Account
consumer: Account,
provider?: string
): SubscribablePromise<OrderProgressStep, string> {
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')