| 1234567891011121314151617181920212223242526 |
- const Chain = require("../../model/chain");
- module.exports = class ChainLib {
- static getCommandChainId() {
- const input = process.argv[process.argv.length - 1]
- const [paraName, value] = input.split('=')
- if (paraName !== 'chainId') {
- throw Error('command paras must have: chainId. like: chainId=1.')
- }
- return parseInt(value)
- }
- static async parseChainById(chainId) {
- const chainRst = await Chain.findById(chainId)
- if (!chainRst.state) {
- throw Error(chainRst.msg)
- }
- return chainRst.data
- }
- static async getChainFromCommand() {
- return await ChainLib.parseChainById(ChainLib.getCommandChainId())
- }
- }
|