Skip to content

Commit

Permalink
Merge pull request #95 from nevermined-io/feature/full_import
Browse files Browse the repository at this point in the history
Import of extended metadata & services flow
  • Loading branch information
aaitor authored Apr 14, 2023
2 parents f8bb530 + fae5a9e commit 476e55c
Show file tree
Hide file tree
Showing 22 changed files with 202 additions and 111 deletions.
26 changes: 17 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
{
"extends": [
"nevermined"
],
"rules": {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@next/next/no-html-link-for-pages": "off"
"extends": [
"nevermined"
],
"rules": {
"@next/next/no-html-link-for-pages": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-unused-vars": [
"error", {
"argsIgnorePattern": "^_",
"varsIgnorePattern": "^_",
"caughtErrorsIgnorePattern": "^_"
}]
},
"ignorePatterns": []
}
}
1 change: 0 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
opengsn: "true"
estuary: "true"
contracts-version: "v3.0.0"
node-version: "develop"
- name: Check artifacts and circuits
run: |
nvm-tools copy-artifacts /tmp/.nevermined/artifacts
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/cli",
"version": "1.1.0",
"version": "1.1.1",
"main": "index.js",
"repository": "[email protected]:nevermined-io/cli.git",
"author": "Nevermined",
Expand All @@ -24,8 +24,8 @@
"ncli": "./dist/src/index.js"
},
"dependencies": {
"@nevermined-io/sdk": "1.2.0",
"@nevermined-io/sdk-dtp": "0.4.1",
"@nevermined-io/sdk": "1.3.3",
"@nevermined-io/sdk-dtp": "0.4.4",
"@truffle/hdwallet-provider": "^2.0.9",
"chalk": "^4.1.2",
"cross-fetch": "~3.1.5",
Expand Down
70 changes: 51 additions & 19 deletions resources/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@
"type": "string",
"description": "When the asset was created"
},
{
"name": "tags",
"type": "string",
"demandOption": false,
"default": "",
"description": "Comma separated list of tags"
},
{
"name": "access",
"type": "string",
Expand Down Expand Up @@ -247,6 +254,13 @@
"type": "string",
"description": "When the asset was created"
},
{
"name": "tags",
"type": "string",
"demandOption": false,
"default": "",
"description": "Comma separated list of tags"
},
{
"name": "access",
"type": "string",
Expand Down Expand Up @@ -345,6 +359,13 @@
"type": "string",
"description": "When the asset was created"
},
{
"name": "tags",
"type": "string",
"demandOption": false,
"default": "",
"description": "Comma separated list of tags"
},
{
"name": "access",
"type": "string",
Expand Down Expand Up @@ -861,12 +882,12 @@
"type": "boolean",
"default": false,
"description": "If true the NFTs will be minted during creation"
},
},
{
"name": "subscription",
"type": "boolean",
"default": false,
"description": "The NFT contract allows to mint NFTs as subscriptions"
"name": "type",
"type": "string",
"default": "dataset",
"description": "The type of asset to register (dataset, algorithm, workflow, container, subscription)"
},
{
"name": "transfer",
Expand Down Expand Up @@ -1044,11 +1065,11 @@
"description": "The NFT type"
}]
}, {
"name": "transfer [agreementId]",
"description": "It allows to transfer a NFT (ERC-721) to the account of the buyer",
"name": "claim [agreementId]",
"description": "It allows to claim a NFT (ERC-721) to the account of the buyer",
"details": "This command requires a valid `serviceAgreementId` and the `sellerAddress` that demonstrates that an asset was bought. The asset is then transferred to the buyer's account.",
"examples": ["ncli nfts721 transfer 0x44dba17d62dd4004c109921cb976ac7c5ec6e4c07d24cc82182b0c49c6381869"],
"commandHandler": "transferNft",
"examples": ["ncli nfts721 claim 0x44dba17d62dd4004c109921cb976ac7c5ec6e4c07d24cc82182b0c49c6381869"],
"commandHandler": "claimNft",
"positionalArguments": [{
"name": "agreementId",
"type": "string",
Expand Down Expand Up @@ -1272,7 +1293,13 @@
"type": "array",
"demand": false,
"description": "The list of services attached to the asset"
},
},
{
"name": "type",
"type": "string",
"default": "dataset",
"description": "The type of asset to register (dataset, algorithm, workflow, container, subscription)"
},
{
"name": "license",
"type": "string",
Expand Down Expand Up @@ -1445,11 +1472,11 @@
}
]
}, {
"name": "transfer [agreementId]",
"description": "It allows to transfer a NFT (ERC-1155) to the account of the buyer",
"name": "claim [agreementId]",
"description": "It allows to claim a NFT (ERC-1155) to the account of the buyer",
"details": "This command requires a valid `serviceAgreementId` created by the `buyerAccount` that demonstrates that an asset was payed. Having that this command will allow to transfer the asset to the buyer account.",
"examples": ["ncli nfts1155 transfer 0x44dba17d62dd4004c109921cb976ac7c5ec6e4c07d24cc82182b0c49c6381869 --amount 1 --buyerAddress 0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"],
"commandHandler": "transferNft",
"examples": ["ncli nfts1155 claim 0x44dba17d62dd4004c109921cb976ac7c5ec6e4c07d24cc82182b0c49c6381869 --amount 1 --buyerAddress 0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"],
"commandHandler": "claimNft",
"positionalArguments": [{
"name": "agreementId",
"type": "string",
Expand All @@ -1467,7 +1494,7 @@
"name": "amount",
"type": "number",
"default": "1",
"description": "The number of NFTs (ERC-1155) to transfer"
"description": "The number of NFTs (ERC-1155) to claim"
}, {
"name": "nftType",
"type": "number",
Expand Down Expand Up @@ -1532,19 +1559,24 @@
"usage": "usage: $0 utils <command> parameters [options]",
"subcommands": [{
"name": "upload [file]",
"description": "Upload file to Filecoin",
"details": "It uploads a local file to the decentralized storage network Filecoin. It returns a `CID` identifying that file into the storage network. If the `--password` flag is provided, it will encrypts the file before uploading it and will return the password used.",
"description": "Upload file to IPFS or Filecoin",
"details": "It uploads a local file to the decentralized storage network like IPFS or Filecoin. It returns a `CID` identifying that file into the storage network. If the `--password` flag is provided, it will encrypts the file before uploading it and will return the password used.",
"examples": ["ncli utils upload README.md"],
"commandHandler": "uploadFile",
"positionalArguments": [{
"name": "file",
"type": "string",
"description": "The path to the file to upload to Filecoin"
"description": "The path to the file to upload"
}],
"optionalArguments": [{
"name": "where",
"type": "string",
"default": "ipfs",
"description": "The network where upload the file (ipfs or filecoin)."
}, {
"name": "encrypt",
"type": "boolean",
"default": "false",
"default": false,
"description": "If given it encrypts the file with AES and return password"
}]
}, {
Expand Down
4 changes: 2 additions & 2 deletions resources/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
"web3ProviderUri": "https://matic-mumbai.chainstacklabs.com",
"marketplaceUri": "https://marketplace-api-public.nevermined.network/",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/common",
"neverminedNodeUri": "https://gateway.mumbai.public.nevermined.network/",
"neverminedNodeUri": "https://gateway.mumbai.public.nevermined.network",
"neverminedNodeAddress": "0x5838B5512cF9f12FE9f2beccB20eb47211F9B0bc",
"verbose": true
},
Expand All @@ -185,7 +185,7 @@
"web3ProviderUri": "https://matic-mumbai.chainstacklabs.com",
"marketplaceUri": "https://marketplace-api.mumbai.nevermined.one",
"graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/public",
"neverminedNodeUri": "https://node.mumbai.nevermined.one/",
"neverminedNodeUri": "https://node.mumbai.nevermined.one",
"neverminedNodeAddress": "0x5838B5512cF9f12FE9f2beccB20eb47211F9B0bc",
"verbose": true
},
Expand Down
16 changes: 14 additions & 2 deletions src/commands/assets/registerAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
printTokenBanner,
loadToken,
loadNeverminedConfigContract,
getFeesFromBigNumber
getFeesFromBigNumber,
getExtraInputParams
} from '../../utils'
import chalk from 'chalk'
import { ExecutionOutput } from '../../models/ExecutionOutput'
Expand Down Expand Up @@ -85,6 +86,7 @@ export const registerAsset = async (
})
_fileIndex++
})
logger.debug(`We have metadata`)

ddoMetadata = {
main: {
Expand All @@ -94,6 +96,7 @@ export const registerAsset = async (
dateCreated: new Date().toISOString().replace(/\.[0-9]{3}/, ''),
author: argv.author,
license: argv.license,
tags: argv.tags ? argv.tags.split(',') : [],
files: _files
} as MetaDataMain
}
Expand All @@ -109,7 +112,7 @@ export const registerAsset = async (
logger.info(`We are here now ${JSON.stringify(ddoMetadata.additionalInformation)}`)
}
if (assetType === 'algorithm') {
const containerTokens = argv.container.split(':')
const containerTokens = argv.cointaer ? argv.container.split(':') : []
ddoMetadata.main.algorithm = {
language: argv.language,
version: '0.1',
Expand Down Expand Up @@ -142,6 +145,15 @@ export const registerAsset = async (
ddoMetadata = JSON.parse(fs.readFileSync(metadata).toString())
}

logger.debug(`Parsing extra metadata parameters`)
// Parsing extra parameters (`--+extraParam xxx`) given to add as additional information
const customData = getExtraInputParams(argv)

ddoMetadata.additionalInformation = {
...ddoMetadata.additionalInformation,
customData
}

console.log(`DDO Metadata = ${JSON.stringify(ddoMetadata)}`)

const configContract = loadNeverminedConfigContract(config)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export * from './nfts/mintNft'
export * from './nfts/showNft'
export * from './nfts/burnNft'
export * from './nfts/orderNft'
export * from './nfts/transferNft'
export * from './nfts/claimNft'
export * from './nfts/downloadNft'
export * from './nfts/accessNft'
export * from './nfts/getJWT'
Expand Down
2 changes: 1 addition & 1 deletion src/commands/nfts/accessNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const accessNft = async (


if (!isHolder) {
logger.info(`Not owner of the NFT, trying transfer`)
logger.info(`Not owner of the NFT, trying to claim it`)
logger.debug(`Using AgreementId: ${agreementId}`)
logger.debug(`Claiming NFT (ERC-${nftType})`)

Expand Down
20 changes: 10 additions & 10 deletions src/commands/nfts/transferNft.ts → src/commands/nfts/claimNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Logger } from 'log4js'
import { ExecutionOutput } from '../../models/ExecutionOutput'
import { ConfigEntry } from '../../models/ConfigDefinition'

export const transferNft = async (
export const claimNft = async (
nvm: Nevermined,
userAccount: Account,
argv: any,
Expand All @@ -18,8 +18,8 @@ export const transferNft = async (

const token = await loadToken(nvm, config, verbose)

logger.debug(
chalk.dim(`Executing agreement: '${chalk.whiteBright(agreementId)}'`)
logger.info(
chalk.dim(`Claiming NFT order by agreement: '${chalk.whiteBright(agreementId)}'`)
)

let agreementData
Expand All @@ -36,7 +36,7 @@ export const transferNft = async (
}`
}
}
logger.trace(
logger.debug(
chalk.dim(
`Agreement Data: '${chalk.whiteBright(JSON.stringify(agreementData))}'`
)
Expand All @@ -49,13 +49,13 @@ export const transferNft = async (
const conditionData = await nvm.keeper.conditionStoreManager.getCondition(
agreementData.conditionIds[0]
)
logger.trace(
logger.debug(
chalk.dim(
`Lock Condition Id: '${chalk.whiteBright(JSON.stringify(conditionData))}'`
)
)

const ddo = await nvm.assets.resolve(agreementData.did)
const ddo = await nvm.assets.resolve(agreementData.did)
const buyerAddress = argv.buyerAddress ? argv.buyerAddress : userAccount.getId()
const sellerAddress = argv.sellerAddress ? argv.sellerAddress : ddo.proof.creator

Expand Down Expand Up @@ -83,8 +83,8 @@ export const transferNft = async (
let isSuccessfulTransfer = false

if (nftType === 721) {
logger.info(
chalk.dim(`Transferring NFT (ERC-721) '${chalk.whiteBright(ddo.id)}' ...`)
logger.debug(
chalk.dim(`Claiming NFT (ERC-721) associated to asset: '${chalk.whiteBright(ddo.id)}' ...`)
)
let nftAddress
try {
Expand All @@ -106,7 +106,7 @@ export const transferNft = async (
// ERC-1155
logger.info(
chalk.dim(
`Transferring NFT (ERC-1155) '${chalk.whiteBright(ddo.id)}' ...`
`Claiming NFT (ERC-1155) '${chalk.whiteBright(ddo.id)}' ...`
)
)
isSuccessfulTransfer = await nvm.nfts1155.claim(
Expand All @@ -120,7 +120,7 @@ export const transferNft = async (
if (!isSuccessfulTransfer) {
return {
status: StatusCodes.ERROR,
errorMessage: `Problem executing 'transferForDelegate' through the Nevermined Node`
errorMessage: `Problem executing 'claim' through the Nevermined Node`
}
}

Expand Down
Loading

0 comments on commit 476e55c

Please sign in to comment.