mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Add consumerAssets method to assets module.
This commit is contained in:
parent
47ced8af1b
commit
b36e3a4f06
|
@ -6,7 +6,7 @@ import { getMetadata } from "../utils"
|
||||||
|
|
||||||
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
|
import { Ocean, Account } from "../../src" // @oceanprotocol/squid
|
||||||
|
|
||||||
describe.only("Asset Owners", () => {
|
describe("Asset Owners", () => {
|
||||||
let ocean: Ocean
|
let ocean: Ocean
|
||||||
|
|
||||||
let account1: Account
|
let account1: Account
|
||||||
|
@ -43,4 +43,21 @@ describe.only("Asset Owners", () => {
|
||||||
|
|
||||||
assert.equal(finalLength - initialLength, 1)
|
assert.equal(finalLength - initialLength, 1)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should get the assets that can be consumer by a user", async () => {
|
||||||
|
const {length: initialLength} = await ocean.assets.consumerAssets(account2.getId())
|
||||||
|
|
||||||
|
const ddo = await ocean.assets.create(metadata as any, account1)
|
||||||
|
|
||||||
|
const {length: finalLength1} = await ocean.assets.consumerAssets(account2.getId())
|
||||||
|
assert.equal(finalLength1 - initialLength, 0)
|
||||||
|
|
||||||
|
// Granting access
|
||||||
|
await account2.requestTokens(metadata.base.price)
|
||||||
|
await ocean.assets.order(ddo.id, ddo.findServiceByType("Access").serviceDefinitionId, account2)
|
||||||
|
// Access granted
|
||||||
|
|
||||||
|
const {length: finalLength2} = await ocean.assets.consumerAssets(account2.getId())
|
||||||
|
assert.equal(finalLength2 - initialLength, 1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@ export default class DIDRegistry extends ContractBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getAttributesByOwner(owner: string): Promise<string[]> {
|
public async getAttributesByOwner(owner: string): Promise<string[]> {
|
||||||
return (await this.getPastEvents('DIDAttributeRegistered', {_owner: zeroX(owner)}))
|
return (await this.getPastEvents("DIDAttributeRegistered", {_owner: zeroX(owner)}))
|
||||||
.map(({returnValues}) => returnValues._did)
|
.map(({returnValues}) => returnValues._did)
|
||||||
.map(didPrefixed)
|
.map(didPrefixed)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Condition } from "./Condition.abstract"
|
import { Condition } from "./Condition.abstract"
|
||||||
import { zeroX, didZeroX } from "../../../utils"
|
import { zeroX, didZeroX, didPrefixed } from "../../../utils"
|
||||||
import { InstantiableConfig } from "../../../Instantiable.abstract"
|
import { InstantiableConfig } from "../../../Instantiable.abstract"
|
||||||
|
|
||||||
export class AccessSecretStoreCondition extends Condition {
|
export class AccessSecretStoreCondition extends Condition {
|
||||||
|
@ -19,4 +19,10 @@ export class AccessSecretStoreCondition extends Condition {
|
||||||
public checkPermissions(grantee: string, did: string, from?: string) {
|
public checkPermissions(grantee: string, did: string, from?: string) {
|
||||||
return this.call<boolean>("checkPermissions", [grantee, didZeroX(did)].map(zeroX), from)
|
return this.call<boolean>("checkPermissions", [grantee, didZeroX(did)].map(zeroX), from)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getGrantedDidByConsumer(consumer: string): Promise<string[]> {
|
||||||
|
return (await this.getPastEvents("Fulfilled", {_grantee: zeroX(consumer)}))
|
||||||
|
.map(({returnValues}) => returnValues._documentId)
|
||||||
|
.map(didPrefixed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,6 +286,15 @@ export class OceanAssets extends Instantiable {
|
||||||
return this.ocean.keeper.didRegistry.getAttributesByOwner(owner)
|
return this.ocean.keeper.didRegistry.getAttributesByOwner(owner)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the assets of a consumer.
|
||||||
|
* @param {string} consumer Consumer address.
|
||||||
|
* @return {Promise<string[]>} List of DIDs.
|
||||||
|
*/
|
||||||
|
public async consumerAssets(consumer: string) {
|
||||||
|
return this.ocean.keeper.conditions.accessSecretStoreCondition.getGrantedDidByConsumer(consumer)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Search over the assets using a query.
|
* Search over the assets using a query.
|
||||||
* @param {SearchQuery} query Query to filter the assets.
|
* @param {SearchQuery} query Query to filter the assets.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user