Skip to content

Commit

Permalink
Merge pull request #555 from nevermined-io/feat/multi_service
Browse files Browse the repository at this point in the history
Support of assets with multiple services of the same type
  • Loading branch information
aaitor authored Jul 26, 2023
2 parents ebfc11e + 941f96f commit fe0fecc
Show file tree
Hide file tree
Showing 88 changed files with 1,989 additions and 727 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/testing-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
with:
repository: nevermined-io/node
path: node
# TODO: replace this with develop once https://github.com/nevermined-io/node/pull/212 is merged
ref: feat/sdk-2.0.0-rc0
# TODO: remove this when Node integrated with SDKv2 is integraged
ref: develop
token: ${{ secrets.API_TOKEN_GITHUB }}
- uses: nevermined-io/[email protected]
with:
Expand Down
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [v2.0.0-rc1](https://github.com/nevermined-io/sdk-js/compare/v2.0.0-rc0...v2.0.0-rc1)

> 25 July 2023
- Feat/ethers v6 [`#556`](https://github.com/nevermined-io/sdk-js/pull/556)
- feat: support for multiple services of the same type [`240cca6`](https://github.com/nevermined-io/sdk-js/commit/240cca68afdfe264aaf006d76cc0aa4cec0097be)
- feat: allow the registration of multiple services of the same type [`ad2d1b4`](https://github.com/nevermined-io/sdk-js/commit/ad2d1b4eb25772a589fb4cd0ab26007bbc7af74a)
- ci: multiple services tests [`afe27c3`](https://github.com/nevermined-io/sdk-js/commit/afe27c3a649b30a9f9e2f75ec6ed566630ac87d0)

#### [v2.0.0-rc0](https://github.com/nevermined-io/sdk-js/compare/v1.13.16...v2.0.0-rc0)

> 20 July 2023
Expand Down Expand Up @@ -339,7 +348,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- ci: testing with https services [`bb96077`](https://github.com/nevermined-io/sdk-js/commit/bb96077c9403ea7ae26195a51d8a92e144cea384)
- linting [`d2547ed`](https://github.com/nevermined-io/sdk-js/commit/d2547edfbfebb49b488c97c4ce9e6d6f2ee849e4)

### [v1.0.0](https://github.com/nevermined-io/sdk-js/compare/v1.0.0-rc9...v1.0.0)
#### [v1.0.0](https://github.com/nevermined-io/sdk-js/compare/v1.0.0-rc9...v1.0.0)

> 14 February 2023
Expand Down Expand Up @@ -1078,7 +1087,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 2 May 2022
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Adding v0.19.21 Changelog updates [`c93cdc5`](https://github.com/nevermined-io/sdk-js/commit/c93cdc55f139a43db4130ccb0f80924d2645a931)

#### [v0.19.21](https://github.com/nevermined-io/sdk-js/compare/v0.19.20...v0.19.21)
Expand Down Expand Up @@ -1341,7 +1350,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 18 January 2022
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Adding v0.17.2 Changelog updates [`5eddda4`](https://github.com/nevermined-io/sdk-js/commit/5eddda43954e013e6e6f7344c9a877d801aacb5c)
Expand Down Expand Up @@ -1847,7 +1856,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/sync develop [`#268`](https://github.com/nevermined-io/sdk-js/pull/268)
- Quick fix for non-eip1559 networks [`#266`](https://github.com/nevermined-io/sdk-js/pull/266)
- integrate Permissions and refactor search query [`#264`](https://github.com/nevermined-io/sdk-js/pull/264)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Get the keeper version from the artifacts instead of package version [`#244`](https://github.com/nevermined-io/sdk-js/pull/244)
- replace `metadata-api` url by `marketplace-api` and sort type [`#243`](https://github.com/nevermined-io/sdk-js/pull/243)
- fixing issues with BigNumbers [`#246`](https://github.com/nevermined-io/sdk-js/pull/246)
Expand Down Expand Up @@ -1886,7 +1895,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/190 add did to sec markets [`#191`](https://github.com/nevermined-io/sdk-js/pull/191)
- Adding utility methods for getting nft token uri [`#189`](https://github.com/nevermined-io/sdk-js/pull/189)
- Lint ... [`#187`](https://github.com/nevermined-io/sdk-js/pull/187)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Correct typo in route [`#184`](https://github.com/nevermined-io/sdk-js/pull/184)
Expand Down
40 changes: 40 additions & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Migration guide to v2

## Breaking changes

### Defining Asset Price

The assetPrice is not part of AssetAttributes anymore and is part of each individual service added to the DDO when registering a service. So for services having a price, this must be added as part of the services array of the AssetAttributes.

Example:

```typescript
const nftAttributes = NFTAttributes.getNFT721Instance({
metadata,
services: [
{
serviceType: 'nft-sales',
price: assetPrice,
},
{
serviceType: 'nft-access',
},
],
nftContractAddress: nftContract.address,
})
```

You will find multiple examples of this in the integration tests.

### Big Numbers

To handle big numbers v2 uses the ES2020 built-in `BigInt` values ([see the BigInt documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt)):
Expand Down Expand Up @@ -33,3 +59,17 @@ isEqual = value1.eq(value2)
// Using BigInt in v2
isEqual = value1 == value2
```

### DDO Helper functions

Most of them were migrated to the `DDO` class:

- `findServiceConditionByName` -> `DDO.findServiceConditionByName`
- `getAssetPriceFromDDOByService` -> `DDO.getAssetPriceFromDDOByServiceType`
- `setNFTRewardsFromDDOByService` -> `DDO.setNFTRewardsFromDDOByService`
- `setAssetPriceFromDDOByService` -> `DDO.setAssetPriceFromDDOByService`
- `getAssetPriceFromService` -> `DDO.getAssetPriceFromService`
- `getDIDFromService` -> `DDO.getDIDFromService`
- `getNftHolderFromService` -> `DDO.getNftHolderFromService`
- `getNftAmountFromService` -> `DDO.getNftAmountFromService`
- `getNftContractAddressFromService` -> `DDO.getNftContractAddressFromService`
7 changes: 6 additions & 1 deletion integration/compute/ComputeAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ describe('Compute Asset', () => {

const computeAttributes = AssetAttributes.getInstance({
metadata: workflowMetadatas.compute(userId),
price: assetPrice,
services: [
{
serviceType: 'compute',
price: assetPrice,
},
],
providers: [config.neverminedNodeAddress],
})
computeDdo = await nevermined.compute.create(computeAttributes, publisher)
Expand Down
22 changes: 16 additions & 6 deletions integration/external/Datasets.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,19 @@ describe('Gate-keeping of Dataset using NFT ERC-721 End-to-End', () => {
subscriptionMetadata = getMetadata(undefined, 'Service Subscription NFT')
const nftAttributes = NFTAttributes.getSubscriptionInstance({
metadata: subscriptionMetadata,
price: assetPrice,
serviceTypes: ['nft-sales'],
services: [
{
serviceType: 'nft-sales',
price: assetPrice,
nft: {
duration: subscriptionDuration,
nftTransfer,
},
},
],
providers: [neverminedNodeAddress],
duration: subscriptionDuration,
nftContractAddress: subscriptionNFT.address,
preMint,
nftTransfer,
royaltyAttributes: royaltyAttributes,
})
subscriptionDDO = await nevermined.nfts721.create(nftAttributes, publisher)
Expand All @@ -196,11 +202,15 @@ describe('Gate-keeping of Dataset using NFT ERC-721 End-to-End', () => {

const nftAttributes = NFTAttributes.getNFT721Instance({
metadata: datasetMetadata,
serviceTypes: ['nft-access'],
services: [
{
serviceType: 'nft-access',
nft: { nftTransfer },
},
],
providers: [neverminedNodeAddress],
nftContractAddress: subscriptionNFT.address,
preMint,
nftTransfer,
royaltyAttributes: royaltyAttributes,
})
datasetDDO = await nevermined.nfts721.create(nftAttributes, publisher)
Expand Down
26 changes: 20 additions & 6 deletions integration/external/Services.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,19 @@ describe('Gate-keeping of Web Services using NFT ERC-721 End-to-End', () => {
subscriptionMetadata.main.type = 'subscription'
const nftAttributes = NFTAttributes.getSubscriptionInstance({
metadata: subscriptionMetadata,
price: assetPrice,
serviceTypes: ['nft-sales'],
services: [
{
serviceType: 'nft-sales',
price: assetPrice,
nft: {
duration: subscriptionDuration,
nftTransfer,
},
},
],
providers: [neverminedNodeAddress],
duration: subscriptionDuration,
nftContractAddress: subscriptionNFT.address,
preMint,
nftTransfer,
royaltyAttributes: royaltyAttributes,
})
subscriptionDDO = await nevermined.nfts721.create(nftAttributes, publisher)
Expand All @@ -265,13 +271,21 @@ describe('Gate-keeping of Web Services using NFT ERC-721 End-to-End', () => {
) as MetaData
serviceMetadata.userId = payload.sub

console.log(`Registering service with metadata: ${JSON.stringify(serviceMetadata)}`)

const nftAttributes = NFTAttributes.getNFT721Instance({
metadata: serviceMetadata,
serviceTypes: ['nft-access'],
services: [
{
serviceType: 'nft-access',
nft: {
nftTransfer,
},
},
],
providers: [neverminedNodeAddress],
nftContractAddress: subscriptionNFT.address,
preMint,
nftTransfer,
royaltyAttributes: royaltyAttributes,
})
serviceDDO = await nevermined.nfts721.create(nftAttributes, publisher)
Expand Down
2 changes: 1 addition & 1 deletion integration/nevermined/AgreementStoreManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('Agreement Store Manager', () => {
await account2.requestTokens(
ddo.getPriceByService() * 10n ** BigInt(await nevermined.keeper.token.decimals()),
)
agreementId = await nevermined.assets.order(ddo.id, account2)
agreementId = await nevermined.assets.order(ddo.id, 'access', account2)

// wait for the graph to pickup the event
await sleep(3000)
Expand Down
7 changes: 6 additions & 1 deletion integration/nevermined/Arweave.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ describe.skip('Get DDO status', () => {
it('should get the external status of an asset', async () => {
const assetAttributes = AssetAttributes.getInstance({
metadata: getMetadata(),
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
})
const ddo = await nevermined.assets.create(assetAttributes, publisher)

Expand Down
35 changes: 30 additions & 5 deletions integration/nevermined/Assets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ describe('Assets', () => {
metadata.userId = payload.sub
const assetAttributes = AssetAttributes.getInstance({
metadata,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
})
ddoBefore = await nevermined.assets.create(assetAttributes, publisher)
})
Expand All @@ -49,7 +54,12 @@ describe('Assets', () => {

const assetAttributes = AssetAttributes.getInstance({
metadata: createdMetadata,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
})
ddo = await nevermined.assets.create(assetAttributes, publisher, PublishMetadata.IPFS)

Expand Down Expand Up @@ -240,7 +250,12 @@ describe('Assets', () => {
// Create 1 asset with appId-test1
const assetAttributes = AssetAttributes.getInstance({
metadata: metadata1,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
appId: appId1,
})
ddoBefore = await neverminedApp1.assets.create(assetAttributes, publisher)
Expand All @@ -249,15 +264,25 @@ describe('Assets', () => {
// Create 2 assets with appId-test2
const assetAttributes2 = AssetAttributes.getInstance({
metadata: metadata2,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
appId: appId2,
})
ddoBefore = await neverminedApp2.assets.create(assetAttributes2, publisher)
await sleep(2000)

const assetAttributes22 = AssetAttributes.getInstance({
metadata: metadata22,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
appId: appId2,
})
ddoBefore = await neverminedApp2.assets.create(assetAttributes22, publisher)
Expand Down
18 changes: 15 additions & 3 deletions integration/nevermined/AssetsPriceQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ describe('Assets Query by Price', () => {

const _attributes = AssetAttributes.getInstance({
metadata,
price: assetPrice,
services: [
{
serviceType: 'access',
price: assetPrice,
},
],
appId,
})
ddoAccess = await nevermined.assets.create(_attributes, account)
Expand All @@ -61,8 +66,15 @@ describe('Assets Query by Price', () => {

const assetAttributes = AssetAttributes.getInstance({
metadata,
price: assetPrice,
serviceTypes: ['nft-sales', 'nft-access'],
services: [
{
serviceType: 'nft-sales',
price: assetPrice,
},
{
serviceType: 'nft-access',
},
],
appId,
})
const nftAttributes = NFTAttributes.getNFT1155Instance({
Expand Down
Loading

0 comments on commit fe0fecc

Please sign in to comment.