Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1803 from LiskHQ/1789-add-endpoint-to-fetch-nft-m…
Browse files Browse the repository at this point in the history
…odule-constants

Add endpoint to fetch NFT module constants
  • Loading branch information
priojeetpriyom authored Aug 17, 2023
2 parents 9708d01 + 83aefb0 commit c5929d7
Show file tree
Hide file tree
Showing 17 changed files with 502 additions and 0 deletions.
44 changes: 44 additions & 0 deletions docs/api/version3.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ The Lisk Service API is compatible with RESTful guidelines. The specification be
- [Annual Inflation](#annual-inflation)
- [Legacy](#legacy)
- [Legacy Account Details](#legacy-account-details)
- [Non-fungible Token](#non-fungible-token)
- [Module Constants](#module-constants-3)
- [Network](#network)
- [Network peers](#network-peers)
- [Network status](#network-status)
Expand Down Expand Up @@ -2049,6 +2051,48 @@ Get legacy account details by publicKey
https://service.lisk.com/api/v3/legacy?publicKey=b1d6bc6c7edd0673f5fed0681b73de6eb70539c21278b300f07ade277e1962cd
```

## Non-fungible Token

### Module Constants

Retrieves module constants from the NFT module.

#### Endpoints

- HTTP GET `/api/v3/nft/constants`
- RPC `get.nft.constants`

#### Request parameters

No parameters are required.

#### Response example

200 OK

```jsonc
{
"data": {
"feeCreateNFT": "5000000",
},
"meta": {}
}
```

400 Bad Request
```jsonc
{
"error": true,
"message": "Unknown input parameter(s): <param_name>"
}
```

#### Examples

Get module constants from the NFT module
```
https://service.lisk.com/api/v3/nft/constants
```
## Network

### Network peers
Expand Down
24 changes: 24 additions & 0 deletions services/blockchain-connector/methods/nft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { getNFTConstants } = require('../shared/sdk');

module.exports = [
{
name: 'getNFTConstants',
controller: async () => getNFTConstants(),
params: {},
},
];
4 changes: 4 additions & 0 deletions services/blockchain-connector/shared/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const {
const { cacheCleanup } = require('./cache');
const { formatTransaction } = require('./formatter');
const { encodeCCM } = require('./encoder');
const { getNFTConstants } = require('./nft');

const init = async () => {
// Initialize the local cache
Expand Down Expand Up @@ -242,4 +243,7 @@ module.exports = {

// Cache
cacheCleanup,

// NFT
getNFTConstants,
};
42 changes: 42 additions & 0 deletions services/blockchain-connector/shared/sdk/nft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { Exceptions: { TimeoutException }, Logger } = require('lisk-service-framework');
const { timeoutMessage } = require('./client');

const logger = Logger();

let moduleConstants;

const getNFTConstants = async () => {
try {
if (!moduleConstants) {
// TODO: Fetch feeCreateNFT directly from node when implemented
// moduleConstants = await invokeEndpoint('nft_getConstants');
moduleConstants = { feeCreateNFT: 5000000 };
}
return moduleConstants;
} catch (err) {
if (err.message.includes(timeoutMessage)) {
throw new TimeoutException('Request timed out when calling \'getConstants\'.');
}
logger.warn(`Error returned when invoking 'nft_getConstants'.\n${err.stack}`);
throw err;
}
};

module.exports = {
getNFTConstants,
};
33 changes: 33 additions & 0 deletions services/blockchain-indexer/methods/dataService/controllers/nft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const dataService = require('../../../shared/dataService');

const getNFTConstants = async () => {
const constants = {
data: {},
meta: {},
};

const response = await dataService.getNFTConstants();
if (response.data) constants.data = response.data;
if (response.meta) constants.meta = response.meta;

return constants;
};

module.exports = {
getNFTConstants,
};
24 changes: 24 additions & 0 deletions services/blockchain-indexer/methods/dataService/modules/nft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { getNFTConstants } = require('../controllers/nft');

module.exports = [
{
name: 'nft.constants',
controller: getNFTConstants,
params: {},
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { Logger } = require('lisk-service-framework');
const { requestConnector } = require('../../../utils/request');

const logger = Logger();

let moduleConstants;

const getNFTConstants = async () => {
try {
if (typeof moduleConstants === 'undefined') moduleConstants = await requestConnector('getNFTConstants');

return {
data: moduleConstants,
meta: {},
};
} catch (err) {
const errMessage = `Unable to fetch the NFT constants from connector due to: ${err.message}.`;
logger.warn(errMessage);
logger.trace(err.stack);
throw new Error(errMessage);
}
};

module.exports = {
getNFTConstants,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { getNFTConstants } = require('./constants');

module.exports = {
getNFTConstants,
};
7 changes: 7 additions & 0 deletions services/blockchain-indexer/shared/dataService/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ const { getValidator, validateBLSKey } = require('./validator');
const { getGenerators } = require('./generators');
const { invokeEndpoint } = require('./invoke');

const {
getNFTConstants,
} = require('./nft');

module.exports = {
// Blocks
getBlocks,
Expand Down Expand Up @@ -201,4 +205,7 @@ module.exports = {
resolveMainchainServiceURL,

invokeEndpoint,

// NFT
getNFTConstants,
};
22 changes: 22 additions & 0 deletions services/blockchain-indexer/shared/dataService/nft/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const business = require('../business');

const getNFTConstants = async () => business.getNFTConstants();

module.exports = {
getNFTConstants,
};
20 changes: 20 additions & 0 deletions services/blockchain-indexer/shared/dataService/nft/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const { getNFTConstants } = require('./constants');

module.exports = {
getNFTConstants,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* LiskHQ/lisk-service
* Copyright © 2023 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/

const nftConstantsSource = require('../../../../../sources/version3/nftConstants');
const envelope = require('../../../../../sources/version3/mappings/stdEnvelope');
const { response, getSwaggerDescription } = require('../../../../../shared/utils');

module.exports = {
version: '2.0',
swaggerApiPath: '/nft/constants',
rpcMethod: 'get.nft.constants',
tags: ['NFT'],
get schema() {
const constantsSchema = {};
constantsSchema[this.swaggerApiPath] = { get: {} };
constantsSchema[this.swaggerApiPath].get.tags = this.tags;
constantsSchema[this.swaggerApiPath].get.summary = 'Requests NFT module constants.';
constantsSchema[this.swaggerApiPath].get.description = getSwaggerDescription({
rpcMethod: this.rpcMethod,
description: 'Requests all the configured constants for the NFT module.',
});
constantsSchema[this.swaggerApiPath].get.responses = {
200: {
description: 'Returns all the configured constants for the NFT module.',
schema: {
$ref: '#/definitions/nftConstantsWithEnvelope',
},
},
};
Object.assign(constantsSchema[this.swaggerApiPath].get.responses, response);
return constantsSchema;
},
source: nftConstantsSource,
envelope,
};
Loading

0 comments on commit c5929d7

Please sign in to comment.