All files / src/command/dappServer index.js

100% Statements 13/13
100% Branches 1/1
100% Functions 2/2
100% Lines 13/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60            3x               3x                     7x                   2x 2x 2x 2x 2x 2x 2x               1x   1x   1x            
import AElf from 'aelf-sdk';
import BaseSubCommand from '../baseSubCommand.js';
import { getWallet } from '../../utils/wallet.js';
import { logger } from '../../utils/myLogger.js';
import Socket from './socket.js';
 
const commandOptions = [
  {
    flag: '--port [port]',
    name: 'port',
    description: 'Which port to listen on, the default port is 35443'
  }
];
 
const commandUsage = ['-port port', ''];
/**
 * @typedef {import('commander').Command} Command
 * @typedef {import('../../../types/rc/index.js').default} Registry
 */
class DeployCommand extends BaseSubCommand {
  /**
   * Creates an instance of DeployCommand.
   * @param {Registry} rc - The registry instance.
   */
  constructor(rc) {
    super('dapp-server', [], 'Start a dAPP SOCKET.IO server', commandOptions, commandUsage, rc);
  }
  /**
   * Runs the dappServer command.
   * @param {Command} commander - The commander instance.
   * @param {...any} args - Additional arguments.
   * @returns {Promise<void>} A promise that resolves when the command is complete.
   */
  async run(commander, ...args) {
    // @ts-ignore
    const { options, localOptions } = await super.run(commander, ...args);
    const { endpoint, datadir, account, password } = options;
    const { port = 35443 } = localOptions;
    try {
      const aelf = new AElf(new AElf.providers.HttpProvider(endpoint));
      const wallet = getWallet(datadir, account, password);
      const socket = new Socket({
        port,
        endpoint,
        aelf,
        wallet,
        address: account
      });
      // @ts-ignore
      logger.info(`DApp server is listening on port ${port}`);
    } catch (e) {
      this.oraInstance.fail('Failed!');
      // @ts-ignore
      logger.error(e);
    }
  }
}
 
export default DeployCommand;