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:
parent
b06d8a78df
commit
26de27a31b
@ -6,7 +6,7 @@ const configJson: Config = {
|
|||||||
aquariusUri: 'http://aquarius:5000',
|
aquariusUri: 'http://aquarius:5000',
|
||||||
brizoUri: 'http://localhost:8030',
|
brizoUri: 'http://localhost:8030',
|
||||||
secretStoreUri: 'http://localhost:12001',
|
secretStoreUri: 'http://localhost:12001',
|
||||||
brizoAddress: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0',
|
brizoAddress: '0x068Ed00cF0441e4829D9784fCBe7b9e26D4BD8d0',
|
||||||
verbose: false
|
verbose: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,8 @@ describe('Consume Asset', () => {
|
|||||||
accessService.index,
|
accessService.index,
|
||||||
serviceAgreementSignatureResult.signature,
|
serviceAgreementSignatureResult.signature,
|
||||||
consumer,
|
consumer,
|
||||||
publisher
|
config.brizoAddress,
|
||||||
|
consumer
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.isTrue(success)
|
assert.isTrue(success)
|
||||||
|
@ -39,7 +39,7 @@ describe('Consume Asset (Brizo)', () => {
|
|||||||
await consumer.authenticate()
|
await consumer.authenticate()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should regiester an asset', async () => {
|
it('should register an asset', async () => {
|
||||||
const steps = []
|
const steps = []
|
||||||
ddo = await ocean.assets
|
ddo = await ocean.assets
|
||||||
.create(metadata as any, publisher)
|
.create(metadata as any, publisher)
|
||||||
|
@ -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)
|
ddo = await ocean.assets.create(metadata as any, publisher)
|
||||||
|
|
||||||
assert.instanceOf(ddo, DDO)
|
assert.instanceOf(ddo, DDO)
|
||||||
|
@ -154,8 +154,8 @@ describe('Register Escrow Access Secret Store Template', () => {
|
|||||||
[conditionIdLock, conditionIdAccess, conditionIdEscrow],
|
[conditionIdLock, conditionIdAccess, conditionIdEscrow],
|
||||||
[0, 0, 0],
|
[0, 0, 0],
|
||||||
[0, 0, 0],
|
[0, 0, 0],
|
||||||
[consumer.getId(), publisher.getId()],
|
[consumer.getId(), config.brizoAddress],
|
||||||
publisher.getId()
|
consumer.getId()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.isTrue(agreement.status)
|
assert.isTrue(agreement.status)
|
||||||
@ -247,7 +247,8 @@ describe('Register Escrow Access Secret Store Template', () => {
|
|||||||
did,
|
did,
|
||||||
escrowAmount,
|
escrowAmount,
|
||||||
consumer.getId(),
|
consumer.getId(),
|
||||||
publisher.getId()
|
config.brizoAddress,
|
||||||
|
consumer.getId()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
||||||
|
@ -152,8 +152,8 @@ describe('Register Escrow Compute Execution Template', () => {
|
|||||||
[conditionIdLock, conditionIdCompute, conditionIdEscrow],
|
[conditionIdLock, conditionIdCompute, conditionIdEscrow],
|
||||||
[0, 0, 0],
|
[0, 0, 0],
|
||||||
[0, 0, 0],
|
[0, 0, 0],
|
||||||
[consumer.getId(), publisher.getId()],
|
[consumer.getId(), config.brizoAddress],
|
||||||
publisher.getId()
|
consumer.getId()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.isTrue(agreement.status)
|
assert.isTrue(agreement.status)
|
||||||
@ -245,7 +245,8 @@ describe('Register Escrow Compute Execution Template', () => {
|
|||||||
did,
|
did,
|
||||||
escrowAmount,
|
escrowAmount,
|
||||||
consumer.getId(),
|
consumer.getId(),
|
||||||
publisher.getId()
|
config.brizoAddress,
|
||||||
|
consumer.getId()
|
||||||
)
|
)
|
||||||
|
|
||||||
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
assert.match(agreementId, /^0x[a-f0-9]{64}$/i)
|
||||||
|
@ -37,6 +37,11 @@ export default class DIDRegistry extends ContractBase {
|
|||||||
return this.call('isDIDProvider', [didZeroX(did), zeroX(provider)])
|
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[]> {
|
public async getAttributesByOwner(owner: string): Promise<string[]> {
|
||||||
return (
|
return (
|
||||||
await this.getPastEvents('DIDAttributeRegistered', {
|
await this.getPastEvents('DIDAttributeRegistered', {
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
ConditionState,
|
ConditionState,
|
||||||
conditionStateNames
|
conditionStateNames
|
||||||
} from '../conditions'
|
} from '../conditions'
|
||||||
|
import {ServiceType} from "../../../ddo/Service";
|
||||||
|
|
||||||
export interface Conditions {
|
export interface Conditions {
|
||||||
lockRewardCondition: LockRewardCondition
|
lockRewardCondition: LockRewardCondition
|
||||||
@ -65,13 +66,16 @@ export class AgreementTemplateBase {
|
|||||||
public async createAgreementFromDDO(
|
public async createAgreementFromDDO(
|
||||||
agreementId: string,
|
agreementId: string,
|
||||||
ddo: DDO,
|
ddo: DDO,
|
||||||
|
serviceType: ServiceType,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
|
provider: string,
|
||||||
from?: string
|
from?: string
|
||||||
) {
|
) {
|
||||||
return !!(await this.createFullAgreement(
|
return !!(await this.createFullAgreement(
|
||||||
ddo.shortId(),
|
ddo.shortId(),
|
||||||
ddo.findServiceByType('metadata').attributes.main.price,
|
ddo.findServiceByType(serviceType).attributes.main.price,
|
||||||
consumer,
|
consumer,
|
||||||
|
provider,
|
||||||
from,
|
from,
|
||||||
agreementId
|
agreementId
|
||||||
))
|
))
|
||||||
@ -104,6 +108,7 @@ export class AgreementTemplateBase {
|
|||||||
* @param {string} did Asset DID.
|
* @param {string} did Asset DID.
|
||||||
* @param {number} amount Asset price.
|
* @param {number} amount Asset price.
|
||||||
* @param {string} consumer ethereum address of consumer.
|
* @param {string} consumer ethereum address of consumer.
|
||||||
|
* @param {string} provider ethereum address of service provider (brizo address)
|
||||||
* @param {string} from Consumer address.
|
* @param {string} from Consumer address.
|
||||||
* @param {string} agreementId bytes32 agreement id.
|
* @param {string} agreementId bytes32 agreement id.
|
||||||
*
|
*
|
||||||
@ -113,6 +118,7 @@ export class AgreementTemplateBase {
|
|||||||
did: string,
|
did: string,
|
||||||
amount: number | string,
|
amount: number | string,
|
||||||
consumer: string,
|
consumer: string,
|
||||||
|
provider: string,
|
||||||
from?: string,
|
from?: string,
|
||||||
agreementId: string = generateId()
|
agreementId: string = generateId()
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
@ -123,7 +129,6 @@ export class AgreementTemplateBase {
|
|||||||
consumer
|
consumer
|
||||||
)
|
)
|
||||||
|
|
||||||
const publisher = await this.didRegistry.getDIDOwner(did)
|
|
||||||
const timeouts = [0, 0, 0]
|
const timeouts = [0, 0, 0]
|
||||||
const timelocks = [0, 0, 0]
|
const timelocks = [0, 0, 0]
|
||||||
await this.agreementStoreManager.createAgreement(
|
await this.agreementStoreManager.createAgreement(
|
||||||
@ -133,10 +138,9 @@ export class AgreementTemplateBase {
|
|||||||
conditionIds,
|
conditionIds,
|
||||||
timelocks,
|
timelocks,
|
||||||
timeouts,
|
timeouts,
|
||||||
[consumer, publisher],
|
[consumer, provider],
|
||||||
from
|
from
|
||||||
)
|
)
|
||||||
|
|
||||||
return zeroX(agreementId)
|
return zeroX(agreementId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ export class OceanAgreements extends Instantiable {
|
|||||||
* @param {number} index Service index.
|
* @param {number} index Service index.
|
||||||
* @param {string} signature Service agreement signature.
|
* @param {string} signature Service agreement signature.
|
||||||
* @param {Account} consumer Consumer account.
|
* @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>}
|
* @return {Promise<boolean>}
|
||||||
*/
|
*/
|
||||||
public async create(
|
public async create(
|
||||||
@ -115,16 +116,23 @@ export class OceanAgreements extends Instantiable {
|
|||||||
index: number,
|
index: number,
|
||||||
signature: string,
|
signature: string,
|
||||||
consumer: Account,
|
consumer: Account,
|
||||||
publisher: Account
|
provider: string,
|
||||||
|
from: Account
|
||||||
) {
|
) {
|
||||||
const d: DID = DID.parse(did)
|
const d: DID = DID.parse(did)
|
||||||
const ddo = await this.ocean.aquarius.retrieveDDO(d)
|
const ddo = await this.ocean.aquarius.retrieveDDO(d)
|
||||||
|
const service = ddo.findServiceById(index)
|
||||||
const templateName = ddo.findServiceById<'access'>(index).attributes
|
const templateName = service.attributes.serviceAgreementTemplate.contractName
|
||||||
.serviceAgreementTemplate.contractName
|
|
||||||
await this.ocean.keeper
|
await this.ocean.keeper
|
||||||
.getTemplateByName(templateName)
|
.getTemplateByName(templateName)
|
||||||
.createAgreementFromDDO(agreementId, ddo, consumer.getId(), publisher.getId())
|
.createAgreementFromDDO(
|
||||||
|
agreementId,
|
||||||
|
ddo,
|
||||||
|
service.type,
|
||||||
|
consumer.getId(),
|
||||||
|
provider,
|
||||||
|
from.getId()
|
||||||
|
)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -151,7 +159,7 @@ export class OceanAgreements extends Instantiable {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (templateId === `0x${'0'.repeat(64)}`) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,12 +284,14 @@ export class OceanAssets extends Instantiable {
|
|||||||
* @param {string} did Decentralized ID.
|
* @param {string} did Decentralized ID.
|
||||||
* @param {number} index Service index.
|
* @param {number} index Service index.
|
||||||
* @param {Account} consumer Consumer account.
|
* @param {Account} consumer Consumer account.
|
||||||
|
* @param {string} provider ethereum address of service provider (optional)
|
||||||
* @return {Promise<string>} Returns Agreement ID
|
* @return {Promise<string>} Returns Agreement ID
|
||||||
*/
|
*/
|
||||||
public order(
|
public order(
|
||||||
did: string,
|
did: string,
|
||||||
index: number,
|
index: number,
|
||||||
consumer: Account
|
consumer: Account,
|
||||||
|
provider?: string
|
||||||
): SubscribablePromise<OrderProgressStep, string> {
|
): SubscribablePromise<OrderProgressStep, string> {
|
||||||
return new SubscribablePromise(async observer => {
|
return new SubscribablePromise(async observer => {
|
||||||
const oceanAgreements = this.ocean.agreements
|
const oceanAgreements = this.ocean.agreements
|
||||||
@ -343,12 +345,22 @@ export class OceanAssets extends Instantiable {
|
|||||||
|
|
||||||
observer.next(OrderProgressStep.CreatingAgreement)
|
observer.next(OrderProgressStep.CreatingAgreement)
|
||||||
this.logger.log('Creating agreement')
|
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(
|
await oceanAgreements.create(
|
||||||
did,
|
did,
|
||||||
agreementId,
|
agreementId,
|
||||||
index,
|
index,
|
||||||
undefined,
|
undefined,
|
||||||
consumer,
|
consumer,
|
||||||
|
provider,
|
||||||
consumer
|
consumer
|
||||||
)
|
)
|
||||||
this.logger.log('Agreement created')
|
this.logger.log('Agreement created')
|
||||||
|
Loading…
Reference in New Issue
Block a user