chain.js 661 B

1234567891011121314151617181920212223242526
  1. const Chain = require("../../model/chain");
  2. module.exports = class ChainLib {
  3. static getCommandChainId() {
  4. const input = process.argv[process.argv.length - 1]
  5. const [paraName, value] = input.split('=')
  6. if (paraName !== 'chainId') {
  7. throw Error('command paras must have: chainId. like: chainId=1.')
  8. }
  9. return parseInt(value)
  10. }
  11. static async parseChainById(chainId) {
  12. const chainRst = await Chain.findById(chainId)
  13. if (!chainRst.state) {
  14. throw Error(chainRst.msg)
  15. }
  16. return chainRst.data
  17. }
  18. static async getChainFromCommand() {
  19. return await ChainLib.parseChainById(ChainLib.getCommandChainId())
  20. }
  21. }