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

Add a way to know if an address is provider of an asset.

This commit is contained in:
Pedro Gutiérrez 2019-08-30 10:50:30 +02:00 committed by Pedro Gutiérrez
parent 860967d246
commit 3235e4f930
2 changed files with 17 additions and 3 deletions

View File

@ -25,7 +25,7 @@ describe('Asset Owners', () => {
}
})
it('should be set correctly the owner of a asset', async () => {
it('should be set correctly the owner of an asset', async () => {
const ddo = await ocean.assets.create(metadata as any, account1)
const owner = await ocean.assets.owner(ddo.id)
@ -33,6 +33,17 @@ describe('Asset Owners', () => {
assert.equal(owner, account1.getId())
})
it('should be set correctly the provider of an asset', async () => {
const ddo = await ocean.assets.create(metadata as any, account1)
const isProvider = await ocean.keeper.didRegistry.isDIDProvider(
ddo.id,
config.brizoAddress
)
assert.isTrue(isProvider)
})
it('should get the assets owned by a user', async () => {
const { length: initialLength } = await ocean.assets.ownerAssets(
account2.getId()

View File

@ -1,4 +1,3 @@
import Web3Provider from '../Web3Provider'
import ContractBase from './ContractBase'
import { zeroX, didPrefixed, didZeroX } from '../../utils'
import { InstantiableConfig } from '../../Instantiable.abstract'
@ -28,13 +27,17 @@ export default class DIDRegistry extends ContractBase {
}
public async getDIDOwner(did: string): Promise<string> {
return this.call('getDIDOwner', [zeroX(did)])
return this.call('getDIDOwner', [didZeroX(did)])
}
public async getBlockNumberUpdated(did: string): Promise<number> {
return +(await this.call('getBlockNumberUpdated', [zeroX(did)]))
}
public async isDIDProvider(did: string, provider: string): Promise<string> {
return this.call('isDIDProvider', [didZeroX(did), zeroX(provider)])
}
public async getAttributesByOwner(owner: string): Promise<string[]> {
return (await this.getPastEvents('DIDAttributeRegistered', {
_owner: zeroX(owner)