Skip to content

Commit

Permalink
Merge pull request #67 from nevermined-io/feature/get_onlymetadata_se…
Browse files Browse the repository at this point in the history
…arch

Feature/get onlymetadata search
  • Loading branch information
aaitor authored Oct 11, 2022
2 parents 51a42aa + 0e4d880 commit 1e8b4ae
Show file tree
Hide file tree
Showing 18 changed files with 64 additions and 52 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/cli",
"version": "0.5.0",
"version": "0.5.2",
"main": "index.js",
"repository": "[email protected]:nevermined-io/cli.git",
"author": "Nevermined",
Expand All @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion resources/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 6 additions & 6 deletions resources/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
"verbose": true
},
"nativeToken": "ETH",
"networkId": "8998",
"networkId": "1337",
"networkName": "geth-localnet",
"etherscanUrl": "",
"erc20TokenAddress": "0x0000000000000000000000000000000000000000",
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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}`)
Expand Down Expand Up @@ -198,4 +199,4 @@ commandsParser.commands.map((_cmd) => {
})
})
})
y.argv
y.argv
3 changes: 1 addition & 2 deletions src/commands/assets/downloadAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`))
Expand Down
6 changes: 1 addition & 5 deletions src/commands/assets/getAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/assets/registerAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
29 changes: 24 additions & 5 deletions src/commands/assets/searchAsset.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -12,16 +13,34 @@ export const searchAsset = async (
config: ConfigEntry,
logger: Logger
): Promise<ExecutionOutput> => {
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)
}
}
}
3 changes: 2 additions & 1 deletion src/commands/nfts/accessNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -31,7 +32,7 @@ export const accessNft = async (
agreementId,
seller,
consumerAccount.getId(),
1
BigNumber.from(1)
)

if (!isSuccessfulTransfer) {
Expand Down
6 changes: 1 addition & 5 deletions src/commands/nfts/burnNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion src/commands/nfts/createNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 1 addition & 5 deletions src/commands/nfts/mintNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions src/commands/nfts/orderNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/nfts/showNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/nfts/transferNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/commands/utils/getNftMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e8b4ae

Please sign in to comment.