This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
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 #1803 from LiskHQ/1789-add-endpoint-to-fetch-nft-m…
…odule-constants Add endpoint to fetch NFT module constants
- Loading branch information
Showing
17 changed files
with
502 additions
and
0 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 |
---|---|---|
@@ -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: {}, | ||
}, | ||
]; |
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,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
33
services/blockchain-indexer/methods/dataService/controllers/nft.js
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,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
24
services/blockchain-indexer/methods/dataService/modules/nft.js
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,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: {}, | ||
}, | ||
]; |
41 changes: 41 additions & 0 deletions
41
services/blockchain-indexer/shared/dataService/business/nft/constants.js
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,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, | ||
}; |
20 changes: 20 additions & 0 deletions
20
services/blockchain-indexer/shared/dataService/business/nft/index.js
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,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, | ||
}; |
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
22 changes: 22 additions & 0 deletions
22
services/blockchain-indexer/shared/dataService/nft/constants.js
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,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
20
services/blockchain-indexer/shared/dataService/nft/index.js
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,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, | ||
}; |
48 changes: 48 additions & 0 deletions
48
services/gateway/apis/http-version3/methods/modules/nft/constants.js
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,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, | ||
}; |
Oops, something went wrong.