-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from nevermined-io/feature/balance
Adding NFT balance command
- Loading branch information
Showing
14 changed files
with
225 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@nevermined-io/cli", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"main": "index.js", | ||
"repository": "[email protected]:nevermined-io/cli.git", | ||
"author": "Nevermined", | ||
|
@@ -24,8 +24,8 @@ | |
"ncli": "./dist/src/index.js" | ||
}, | ||
"dependencies": { | ||
"@nevermined-io/sdk": "1.3.3", | ||
"@nevermined-io/sdk-dtp": "0.4.4", | ||
"@nevermined-io/sdk": "1.3.6", | ||
"@nevermined-io/sdk-dtp": "0.4.7", | ||
"@truffle/hdwallet-provider": "^2.0.9", | ||
"chalk": "^4.1.2", | ||
"cross-fetch": "~3.1.5", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Account, didZeroX, Nevermined, zeroX } from '@nevermined-io/sdk' | ||
import { StatusCodes } from '../../utils' | ||
import { ExecutionOutput } from '../../models/ExecutionOutput' | ||
import chalk from 'chalk' | ||
import { Logger } from 'log4js' | ||
import { ConfigEntry } from '../../models/ConfigDefinition' | ||
|
||
export const balanceNft = async ( | ||
nvm: Nevermined, | ||
consumerAccount: Account, | ||
argv: any, | ||
config: ConfigEntry, | ||
logger: Logger | ||
): Promise<ExecutionOutput> => { | ||
const { nftAddress } = argv | ||
|
||
const nftType = Number(argv.nftType) | ||
|
||
let balance | ||
const userAddress = argv.address ? argv.address : consumerAccount.getId() | ||
|
||
logger.info( | ||
chalk.dim(`Gets the balance of the account ${userAddress} for the NFT-${nftType} with address ${chalk.whiteBright(nftAddress)}`) | ||
) | ||
|
||
if (nftType === 721) { | ||
const nft = await nvm.contracts.loadNft721(nftAddress) | ||
balance = await nft.balanceOf(userAddress) | ||
logger.info(`The user holds ${balance} token/s of the ERC-${nftType} NFT`) | ||
} else { | ||
const nft = await nvm.contracts.loadNft1155Contract(nftAddress) | ||
balance = await nft.balance(userAddress, zeroX(didZeroX(argv.did))) | ||
logger.info(`The user holds ${balance} edition/s of the ERC-${nftType} NFT`) | ||
} | ||
|
||
return { | ||
status: StatusCodes.OK, | ||
results: JSON.stringify({ | ||
balance | ||
}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.