All files / fabric-shim/lib/cmds startCommand.js

100% Statements 31/31
100% Branches 14/14
100% Functions 4/4
100% Lines 31/31

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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85                2x   2x                           2x   2x 2x 2x 1x   1x   1x   2x 1x 1x     2x 9x   9x   3x   3x   3x 33x 24x     33x 6x       3x               3x 3x     3x 2x     3x 6x 1x         8x    
/*
 * Copyright contributors to Hyperledger Fabric.
 *
 * SPDX-License-Identifier: Apache-2.0
 */
 
'use strict';
 
const YargsParser = require('yargs-parser');
 
const validOptions = {
    'peer.address': {type: 'string', required: true},
    'grpc.max_send_message_length': {type: 'number', default: -1},
    'grpc.max_receive_message_length': {type: 'number', default: -1},
    'grpc.keepalive_time_ms': {type: 'number', default: 110000},
    'grpc.http2.min_time_between_pings_ms': {type: 'number', default: 110000},
    'grpc.keepalive_timeout_ms': {type: 'number', default: 20000},
    'grpc.http2.max_pings_without_data': {type: 'number', default: 0},
    'grpc.keepalive_permit_without_calls': {type: 'number', default: 1},
    'ssl-target-name-override': {type: 'string'},
    'chaincode-id-name': {type: 'string', required: true},
    'module-path': {type: 'string', default: process.cwd()}
};
 
module.exports.validOptions = validOptions;
 
exports.command = 'start [options]';
exports.desc = 'Start an empty chaincode';
exports.builder = (yargs) => {
    yargs.options(validOptions);
 
    yargs.usage('fabric-chaincode-node start --peer.address localhost:7051 --chaincode-id-name mycc');
 
    return yargs;
};
exports.handler = async function (argv) {
    const Bootstrap = require('../contract-spi/bootstrap');
    await Bootstrap.bootstrap();
};
 
exports.getArgs = function (yargs) {
    let argv = yargs.argv;
 
    if (argv.$0 !== 'fabric-chaincode-node') {
 
        const defaults = {};
 
        const required = [];
 
        for (const key in validOptions) {
            if (validOptions[key].hasOwnProperty('default')) {   // eslint-disable-line no-prototype-builtins
                defaults[key] = validOptions[key].default;
            }
 
            if (validOptions[key].hasOwnProperty('required') && validOptions[key].required) {  // eslint-disable-line no-prototype-builtins
                required.push(key);
            }
        }
 
        argv = YargsParser(process.argv.slice(2), {
            default: defaults,
            configuration: {
                'dot-notation': false
            },
            envPrefix: 'CORE'
        });
 
        argv['chaincode-id-name'] = argv.chaincodeIdName;
        argv['module-path'] = argv.modulePath;
 
        // eslint-disable-next-line eqeqeq
        if (argv.CORE_PEER_ADDRESS != null) {
            argv['peer.address'] = argv.CORE_PEER_ADDRESS;
        }
 
        required.forEach((argName) => {
            if (!argv.hasOwnProperty(argName) || typeof(argv[argName]) === 'undefined') {  // eslint-disable-line no-prototype-builtins
                throw new Error('Missing required argument ' + argName);
            }
        });
    }
 
    return argv;
};