diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f9f432b..c2acb09 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -17,12 +17,12 @@ jobs: include: - network: "--geth" network-name: geth-localnet - chainId: 8998 + chainId: 1337 delay: GRAPH_DELAY steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 with: node-version: ${{ matrix.node }} - name: Install dependencies @@ -60,13 +60,14 @@ jobs: NETWORK: ${{ matrix.network-name }} IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }} IPFS_PROJECT_SECRET: ${{ secrets.IPFS_PROJECT_SECRET }} + USE_NEW_GATEWAY: true run: | export ${{ matrix.delay }}=true sleep 10 yarn build yarn test - name: Upload logs - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: nevermined-tools-output diff --git a/package.json b/package.json index ddb0f81..8563de6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@nevermined-io/cli", - "version": "0.5.0", + "version": "0.5.2", "main": "index.js", "repository": "git@github.com:nevermined-io/cli.git", "author": "Nevermined", @@ -22,7 +22,7 @@ "ncli": "./dist/src/index.js" }, "dependencies": { - "@nevermined-io/nevermined-sdk-js": "0.23.5", + "@nevermined-io/nevermined-sdk-js": "0.25.0-rc1", "@truffle/hdwallet-provider": "^2.0.9", "chalk": "^4.1.2", "cross-fetch": "~3.1.5", diff --git a/resources/commands.json b/resources/commands.json index aa4e84b..e5e8690 100644 --- a/resources/commands.json +++ b/resources/commands.json @@ -315,7 +315,12 @@ "type": "number", "default": "1", "description": "The page to show" - }] + }, { + "name": "onlyMetadata", + "type": "boolean", + "default": false, + "description": "True if we only want to get metadata" + }] }, { "name": "download [did]", "description": "Download an asset owned by me", diff --git a/resources/networks.json b/resources/networks.json index 5a297f7..f23ef13 100644 --- a/resources/networks.json +++ b/resources/networks.json @@ -132,7 +132,7 @@ "verbose": true }, "nativeToken": "ETH", - "networkId": "8998", + "networkId": "1337", "networkName": "geth-localnet", "etherscanUrl": "", "erc20TokenAddress": "0x0000000000000000000000000000000000000000", @@ -167,18 +167,18 @@ "isProduction": false, "nvm": { "nodeUri": "", - "marketplaceUri": "https://defi.v2.marketplace-api.mumbai.nevermined.rocks", + "marketplaceUri": "https://marketplace-api-public.nevermined.network/", "faucetUri": "https://faucet.mumbai.public.nevermined.rocks", "graphHttpUri": "https://api.thegraph.com/subgraphs/name/nevermined-io/common", - "gatewayUri": "https://defi.v2.gateway.mumbai.nevermined.rocks", - "gatewayAddress": "0x7DFa856BC27b67bfA83F190755D6C7D0A0D7BBC0", + "gatewayUri": "https://gateway.defi.public.nevermined.network/", + "gatewayAddress": "0x5838B5512cF9f12FE9f2beccB20eb47211F9B0bc", "verbose": true }, "nativeToken": "MATIC", "networkId": "80001", "networkName": "mumbai", - "contractsVersion": "2.0.0", - "tagName": "common", + "contractsVersion": "2.0.5", + "tagName": "public", "etherscanUrl": "https://mumbai.polygonscan.com", "erc20TokenAddress": "0xe11A86849d99F524cAC3E7A0Ec1241828e332C62", "gasMultiplier": 0, diff --git a/src/cli.ts b/src/cli.ts index 7c0924e..6b77ba1 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -45,7 +45,8 @@ const cmdHandler = async ( // The `--json` parameter was given so we setup logs in json format addLayout('json', function (config) { return function (logEvent) { - return JSON.stringify(logEvent) + config.separator + // we don't need separator as we only have one line, wich represents the output of the command + return JSON.stringify(logEvent) // + config.separator } }) configure(getJsonLoggerConfig()) @@ -116,7 +117,7 @@ const cmdHandler = async ( logger ) if (argv.json) { - logger.mark(JSON.stringify(executionOutput)) + logger.mark(executionOutput) } if (executionOutput.status > 0) { logger.error(`Command error: ${executionOutput.errorMessage}`) @@ -198,4 +199,4 @@ commandsParser.commands.map((_cmd) => { }) }) }) -y.argv \ No newline at end of file +y.argv diff --git a/src/commands/assets/downloadAsset.ts b/src/commands/assets/downloadAsset.ts index 2076a7e..8fd34f6 100644 --- a/src/commands/assets/downloadAsset.ts +++ b/src/commands/assets/downloadAsset.ts @@ -28,8 +28,7 @@ export const downloadAsset = async ( did, account, argv.path, - argv.fileIndex, - false + argv.fileIndex ) logger.info(chalk.dim(`Files downloaded to: ${path}`)) diff --git a/src/commands/assets/getAsset.ts b/src/commands/assets/getAsset.ts index 62c12b2..8a98f32 100644 --- a/src/commands/assets/getAsset.ts +++ b/src/commands/assets/getAsset.ts @@ -37,11 +37,7 @@ export const getAsset = async ( if (argv.agreementId === '') { logger.info(chalk.dim(`Ordering asset: ${did}`)) - if (password) { - agreementId = await nvm.assets.order(did, 'access-proof', account) - } else { - agreementId = await nvm.assets.order(did, 'access', account) - } + agreementId = await nvm.assets.order(did, 'access', account) } else { ;({ agreementId } = argv) } diff --git a/src/commands/assets/registerAsset.ts b/src/commands/assets/registerAsset.ts index 2df2677..53949ad 100644 --- a/src/commands/assets/registerAsset.ts +++ b/src/commands/assets/registerAsset.ts @@ -124,7 +124,7 @@ export const registerAsset = async ( account, // @ts-ignore new AssetRewards(account.getId(), ddoPrice), - encrypt || password ? ['access-proof'] : undefined //, + ['access'] // undefined, // undefined, // undefined, diff --git a/src/commands/assets/searchAsset.ts b/src/commands/assets/searchAsset.ts index 5de25a9..3d37e69 100644 --- a/src/commands/assets/searchAsset.ts +++ b/src/commands/assets/searchAsset.ts @@ -1,4 +1,5 @@ import { Account, Nevermined } from '@nevermined-io/nevermined-sdk-js' +import { ServiceMetadata } from '@nevermined-io/nevermined-sdk-js/dist/node/ddo/Service' import { StatusCodes, printSearchResult } from '../../utils' import chalk from 'chalk' import { Logger } from 'log4js' @@ -12,16 +13,34 @@ export const searchAsset = async ( config: ConfigEntry, logger: Logger ): Promise => { - const { verbose, network, query } = argv + const { verbose, network, query, json, onlyMetadata } = argv logger.info(chalk.dim(`Search using query: ${query}`)) - const assets = await nvm.assets.search(query, argv.offset, argv.page) + const queryResults = await nvm.assets.search(query, argv.offset, argv.page) + let metadataResult - printSearchResult(assets, logger) + if (onlyMetadata) { + metadataResult = { + page: queryResults.page, + totalPages: queryResults.page, + totalResults: queryResults.totalResults, + results: queryResults.results.map((ddo) => { + const service: ServiceMetadata = ddo.findServiceByType( + 'metadata' + ) as ServiceMetadata + service.attributes.encryptedFiles = '' + return service + }) + } + } + + if (!json) printSearchResult(queryResults, logger) return { status: StatusCodes.OK, - results: JSON.stringify(assets) + results: onlyMetadata + ? JSON.stringify(metadataResult) + : JSON.stringify(queryResults) } -} \ No newline at end of file +} diff --git a/src/commands/nfts/accessNft.ts b/src/commands/nfts/accessNft.ts index d0f4b9c..e34accb 100644 --- a/src/commands/nfts/accessNft.ts +++ b/src/commands/nfts/accessNft.ts @@ -4,6 +4,7 @@ import { ExecutionOutput } from '../../models/ExecutionOutput' import chalk from 'chalk' import { Logger } from 'log4js' import { ConfigEntry } from '../../models/ConfigDefinition' +import BigNumber from '@nevermined-io/nevermined-sdk-js/dist/node/utils/BigNumber' export const accessNft = async ( nvm: Nevermined, @@ -31,7 +32,7 @@ export const accessNft = async ( agreementId, seller, consumerAccount.getId(), - 1 + BigNumber.from(1) ) if (!isSuccessfulTransfer) { diff --git a/src/commands/nfts/burnNft.ts b/src/commands/nfts/burnNft.ts index f21afb4..5d944a5 100644 --- a/src/commands/nfts/burnNft.ts +++ b/src/commands/nfts/burnNft.ts @@ -43,11 +43,7 @@ export const burnNft = async ( if (argv.nftType === '721') { // Burning NFT (ERC-721) - const nftAddress = getNFTAddressFromInput( - argv.nftAddress, - ddo, - 'nft721-sales' - ) + const nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft-sales') const nft: Nft721 = await nvm.contracts.loadNft721(nftAddress) diff --git a/src/commands/nfts/createNft.ts b/src/commands/nfts/createNft.ts index ce19373..32e1f18 100644 --- a/src/commands/nfts/createNft.ts +++ b/src/commands/nfts/createNft.ts @@ -129,7 +129,7 @@ export const createNft = async ( DEFAULT_ENCRYPTION_METHOD, argv.cap, [config.nvm.gatewayAddress!], - 1, + BigNumber.from(1), royaltyAttributes, token ? token.getAddress() : config.erc20TokenAddress, argv.nftAddress || nvm.keeper.nftUpgradeable.getAddress(), diff --git a/src/commands/nfts/mintNft.ts b/src/commands/nfts/mintNft.ts index 53dce96..fc1e849 100644 --- a/src/commands/nfts/mintNft.ts +++ b/src/commands/nfts/mintNft.ts @@ -48,11 +48,7 @@ export const mintNft = async ( if (argv.nftType === '721') { // Minting NFT (ERC-721) - const nftAddress = getNFTAddressFromInput( - argv.nftAddress, - ddo, - 'nft721-sales' - ) + const nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft-sales') const nft: Nft721 = await nvm.contracts.loadNft721(nftAddress) if (verbose) { diff --git a/src/commands/nfts/orderNft.ts b/src/commands/nfts/orderNft.ts index 2d9665b..efdc14b 100644 --- a/src/commands/nfts/orderNft.ts +++ b/src/commands/nfts/orderNft.ts @@ -28,9 +28,7 @@ export const orderNft = async ( token !== null ? await token.decimals() : Constants.ETHDecimals const symbol = token !== null ? await token.symbol() : config.nativeToken - const serviceInDDO = argv.nftType === '721' ? 'nft721-sales' : 'nft-sales' - - const price = getAssetRewardsFromDDOByService(ddo, serviceInDDO) + const price = getAssetRewardsFromDDOByService(ddo, 'nft-sales') .getTotalPrice() .div(10) .mul(decimals) diff --git a/src/commands/nfts/showNft.ts b/src/commands/nfts/showNft.ts index 0640568..f93e8f0 100644 --- a/src/commands/nfts/showNft.ts +++ b/src/commands/nfts/showNft.ts @@ -75,7 +75,7 @@ export const showNft = async ( let nftAddress = '' // Showing ERC-721 NFT information if (argv.is721) { - nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft721-sales') + nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft-sales') const nft: Nft721 = await nvm.contracts.loadNft721(nftAddress) if (verbose) { @@ -105,7 +105,7 @@ export const showNft = async ( logger.warn(`Token Id not found`) } - const price = getAssetRewardsFromDDOByService(ddo, 'nft721-sales') + const price = getAssetRewardsFromDDOByService(ddo, 'nft-sales') .getTotalPrice() .div(10) .mul(decimals) @@ -169,7 +169,7 @@ export const showNft = async ( } catch {} try { - const price = getAssetRewardsFromDDOByService(ddo, 'nft721-sales') + const price = getAssetRewardsFromDDOByService(ddo, 'nft-sales') .getTotalPrice() .div(10) .mul(decimals) diff --git a/src/commands/nfts/transferNft.ts b/src/commands/nfts/transferNft.ts index 5a113cd..523adaa 100644 --- a/src/commands/nfts/transferNft.ts +++ b/src/commands/nfts/transferNft.ts @@ -72,7 +72,7 @@ export const transferNft = async ( const serviceInDDO = argv.nftType === '721' ? 'nft721-sales' : 'nft-sales' - const price = getAssetRewardsFromDDOByService(ddo, serviceInDDO) + const price = getAssetRewardsFromDDOByService(ddo, 'nft-sales') .getTotalPrice() .div(10) .mul(decimals) diff --git a/src/commands/utils/getNftMetadata.ts b/src/commands/utils/getNftMetadata.ts index db3b6b1..287f393 100644 --- a/src/commands/utils/getNftMetadata.ts +++ b/src/commands/utils/getNftMetadata.ts @@ -44,11 +44,11 @@ export const getNftMetadata = async ( `The DID has a ERC-1155 NFT attached with address ${nftAddress}` ) } else if ( - ddo.findServiceByType('nft721-access') || - ddo.findServiceByType('nft721-sales') + ddo.findServiceByType('nft-access') || + ddo.findServiceByType('nft-sales') ) { is1155 = false - nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft721-sales') + nftAddress = getNFTAddressFromInput(argv.nftAddress, ddo, 'nft-sales') logger.debug( `The DID has a ERC-721 NFT attached with address ${nftAddress}` ) diff --git a/src/utils/config.ts b/src/utils/config.ts index fe4ca91..55d0028 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -26,7 +26,7 @@ export const ARTIFACTS_REPOSITORY = process.env.ARTIFACTS_REPO || 'https://artifacts-nevermined-rocks.s3.amazonaws.com' -export const USE_NEW_GATEWAY = true +export const USE_NEW_GATEWAY = process.env.USE_NEW_GATEWAY === 'true' || true export const DEFAULT_ENCRYPTION_METHOD = 'PSK-RSA' // INFO: This mnemonic is only used to initialize the HDWallet in commands not requiring network connectivity