How to use the peer.address function in peer

To help you get started, we’ve selected a few peer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github hyperledger / fabric-chaincode-node / test / unit / chaincode.js View on Github external
process.argv.push('--grpc.max_receive_message_length');
	process.argv.push('177');
	process.argv.push('--grpc.keepalive_time_ms');
	process.argv.push('1234');
	process.argv.push('--grpc.keepalive_timeout_ms');
	process.argv.push('5678');
	process.argv.push('--grpc.http2.min_time_between_pings_ms');
	process.argv.push('7654');
	process.argv.push('--grpc.http2.max_pings_without_data');
	process.argv.push('99');
	process.argv.push('--grpc.keepalive_permit_without_calls');
	process.argv.push('2');
	delete require.cache[require.resolve('fabric-shim/lib/chaincode.js')];
	Chaincode = rewire('fabric-shim/lib/chaincode.js');
	opts = Chaincode.__get__('opts');
	t.deepEqual(opts['peer.address'], 'localhost:7051', 'Test passing only --peer.address argument is correctly picked up');
	t.equal(opts['grpc.max_send_message_length'],101, 'Test grpc.max_send_message_length can be set');
	t.equal(opts['grpc.max_receive_message_length'], 177, 'Test grpc.max_receive_message_length can be set');
	t.equal(opts['grpc.keepalive_time_ms'], 1234, 'Test grpc.keepalive_time_ms can be set');
	t.equal(opts['grpc.http2.min_time_between_pings_ms'], 7654, 'Test grpc.http2.min_time_between_pings_ms can be set');
	t.equal(opts['grpc.keepalive_timeout_ms'], 5678, 'Test grpc.keepalive_timeout_ms can be set');
	t.equal(opts['grpc.http2.max_pings_without_data'], 99, 'Test grpc.http2.max_pings_without_data can be set');
	t.equal(opts['grpc.keepalive_permit_without_calls'], 2, 'Test grpc.keepalive_permit_without_calls can be set');

	// remove the 7 parameters passed
	for (let index = 0; index < 7; index++) {
		process.argv.pop();
		process.argv.pop();
	}

	process.argv.pop();  // remove localhost:7051
	process.argv.pop();  // remove peer.address
github hyperledger / fabric-chaincode-node / libraries / fabric-shim / lib / chaincode.js View on Github external
'The client key and cert are needed when TLS is enabled, but environment ' +
                     'variables specifying the paths to these files are missing'
                );
            }

            optsCpy.key = fs.readFileSync(keyPath).toString();
            optsCpy.cert = fs.readFileSync(certPath).toString();
        }

        const chaincodeName = opts['chaincode-id-name'];
        const client = new Handler(chaincode, url, optsCpy);
        const chaincodeID = {
            name: chaincodeName
        };

        logger.info(util.format('Registering with peer %s as chaincode "%s"', opts['peer.address'], chaincodeName));

        client.chat({
            type: fabprotos.protos.ChaincodeMessage.Type.REGISTER,
            payload: fabprotos.protos.ChaincodeID.encode(chaincodeID).finish()
        });

        // return the client object to give the calling code
        // a handle to terminate pro-actively by calling client.close()
        return client;
    }
github hyperledger / fabric-chaincode-node / libraries / fabric-shim / lib / chaincode.js View on Github external
logger.debug('Starting chaincode using options', opts);

        const optsCpy  = Object.assign({}, opts);
        const expectedOpts = StartCommand.validOptions;

        for (const key in optsCpy) {
            if (!Object.prototype.hasOwnProperty.call(expectedOpts, key)) {
            // if (!expectedOpts.hasOwnProperty(key)) {
                delete optsCpy[key];
            }
        }
        delete optsCpy['chaincode-id-name'];
        delete optsCpy['module-path'];

        const url = parsePeerUrl(opts['peer.address']);
        if (isTLS()) {
            logger.debug('TLS enabled');
            optsCpy.pem = fs.readFileSync(process.env.CORE_PEER_TLS_ROOTCERT_FILE).toString();

            // the peer enforces mutual TLS, so we must have the client key and cert to proceed
            const keyPath = process.env.CORE_TLS_CLIENT_KEY_PATH;
            const certPath = process.env.CORE_TLS_CLIENT_CERT_PATH;
            if (typeof keyPath !== 'string' || typeof certPath !== 'string') {
                throw new Error(
                    'The client key and cert are needed when TLS is enabled, but environment ' +
                     'variables specifying the paths to these files are missing'
                );
            }

            optsCpy.key = fs.readFileSync(keyPath).toString();
            optsCpy.cert = fs.readFileSync(certPath).toString();
github hyperledger / fabric-chaincode-node / test / unit / chaincode.js View on Github external
test('Chaincode command line arguments tests', (t) => {
	Chaincode = rewire('fabric-shim/lib/chaincode.js');
	let opts = Chaincode.__get__('opts');
	t.deepEqual(opts['peer.address'], undefined, 'Test zero argument');

	process.argv.push('--peer.address');
	process.argv.push('localhost:7051');
	delete require.cache[require.resolve('fabric-shim/lib/chaincode.js')];
	Chaincode = rewire('fabric-shim/lib/chaincode.js');
	opts = Chaincode.__get__('opts');
	t.deepEqual(opts['peer.address'], 'localhost:7051', 'Test passing only --peer.address argument is correctly picked up');
	t.equal(opts['grpc.max_send_message_length'], -1, 'Test grpc.max_send_message_length defaults to -1');
	t.equal(opts['grpc.max_receive_message_length'], -1, 'Test grpc.max_receive_message_length defaults to -1');
	t.equal(opts['grpc.keepalive_time_ms'], 110000, 'Test grpc.keepalive_time_ms defaults to 110000');
	t.equal(opts['grpc.http2.min_time_between_pings_ms'], 110000, 'Test grpc.http2.min_time_between_pings_ms defaults to 110000');
	t.equal(opts['grpc.keepalive_timeout_ms'], 20000, 'Test grpc.keepalive_timeout_ms defaults to 20000');
	t.equal(opts['grpc.http2.max_pings_without_data'], 0, 'Test grpc.http2.max_pings_without_data defaults to 0');
	t.equal(opts['grpc.keepalive_permit_without_calls'], 1, 'Test grpc.keepalive_permit_without_calls defaults to 1');

	process.argv.push('--test.another');

peer

PeerJS server component

MIT
Latest version published 5 months ago

Package Health Score

83 / 100
Full package analysis