Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function joinChannel(org) {
console.log(util.format('Calling peers in organization "%s" to join the channel'));
//
// Create and configure the test chain
//
let client = new hfc();
let chain = client.newChain(channel);
if (useTls) {
let caRootsPath = ORGS.orderer.tls_cacerts;
let data = fs.readFileSync(path.join(__dirname, caRootsPath));
let caroots = Buffer.from(data).toString();
chain.addOrderer(
new Orderer(
ORGS.orderer.url,
{
'pem': caroots,
'ssl-target-name-override': ORGS.orderer['server-hostname']
}
)
);
}
else {
chain.addOrderer(new Orderer(ORGS.orderer));
}
let targets = [];
for (let key in ORGS[org]) {
if (ORGS[org].hasOwnProperty(key)) {
if (key.indexOf('peer') === 0) {
}).then(function (submitter) {
channel.addOrderer(new Orderer(options.orderer_url, options.orderer_tls_opts));
channel.addPeer(new Peer(options.peer_urls[0], options.peer_tls_opts));
logger.debug('added peer', options.peer_urls[0]);
// --- Success --- //
logger.debug('[fcw] Successfully got enrollment ' + options.uuid);
if (cb) cb(null, { client: client, channel: channel, submitter: submitter });
return;
}).catch(function (err) {
if (TLS.toUpperCase() == 'ENABLED') {
var caRootsPath = ORGS['orderer'][ordererID].tls_cacerts;
let data = fs.readFileSync(caRootsPath);
let caroots = Buffer.from(data).toString();
chain.addOrderer(
new Orderer(
ORGS['orderer'][ordererID].url,
{
'pem': caroots,
'ssl-target-name-override': ORGS['orderer'][ordererID]['server-hostname']
}
)
);
} else {
chain.addOrderer( new Orderer(ORGS['orderer'][ordererID].url));
console.log('[Nid:id:chan:org=%d:%d:%s:%s channelAddOrderer] orderer url: ', Nid, pid, channelName, org, ORGS['orderer'][ordererID].url);
}
console.log('[Nid:id:chan:org=%d:%d:%s:%s channelAddOrderer] orderer in the chain: ', Nid, pid, channelName, org, chain.getOrderers());
}
test('orderer bad address test', function(t) {
testUtil.resetDefaults();
try {
new Orderer('xxxxx');
t.fail('Orderer allowed setting a bad URL.');
}
catch(err) {
t.pass('Orderer did not allow setting bad URL.');
}
t.end();
});
function channelAddOrderer(chain, client, org) {
var ordererID = ORGS[org].ordererID;
console.log('[Nid:id:chan:org:ordererID=%d:%d:%s:%s:%s channelAddOrderer] chain name: ', Nid, pid, channelName, org, ordererID, chain.getName());
if (TLS.toUpperCase() == 'ENABLED') {
var caRootsPath = ORGS['orderer'][ordererID].tls_cacerts;
let data = fs.readFileSync(caRootsPath);
let caroots = Buffer.from(data).toString();
chain.addOrderer(
new Orderer(
ORGS['orderer'][ordererID].url,
{
'pem': caroots,
'ssl-target-name-override': ORGS['orderer'][ordererID]['server-hostname']
}
)
);
} else {
chain.addOrderer( new Orderer(ORGS['orderer'][ordererID].url));
console.log('[Nid:id:chan:org=%d:%d:%s:%s channelAddOrderer] orderer url: ', Nid, pid, channelName, org, ORGS['orderer'][ordererID].url);
}
console.log('[Nid:id:chan:org=%d:%d:%s:%s channelAddOrderer] orderer in the chain: ', Nid, pid, channelName, org, chain.getOrderers());
}
test('orderer unknown address test', function(t) {
var client = new Orderer('grpc://127.0.0.1:51006');
client.sendBroadcast('some data')
.then(
function() {
t.fail('Should have noticed a bad address.');
t.end();
},
function(err) {
t.equal(err.message, 'Failed to connect before the deadline',
'sendBroadcast to unreachable orderer should response connection failed');
t.pass('Successfully found bad address!');
t.end();
}
).catch(function(err) {
t.fail('Caught Error: should not be here if we defined promise error function: '
+ err);
() => {
const orderer = new Orderer('grpc://somehost.com:1234');
_channel.addOrderer(orderer);
},
/^DuplicateOrderer: Orderer/,
() => {
channel._getOrderer('bad');
},
/Orderer bad not assigned to the channel/,
'Channel _getOrderer test: using bad name and no orderers assigned to channel'
);
t.throws(
() => {
channel._getOrderer({});
},
/Orderer is not a valid orderer object instance/,
'Channel _getOrderer test: using bad object and no orderers assigned to channel'
);
const orderer = new Orderer('grpc://somehost.com:1234');
t.doesNotThrow(
() => {
const test_orderer = channel._getOrderer(orderer);
t.equal(test_orderer.getName(), 'somehost.com:1234', 'Checking able to get correct name');
},
'Channel _getOrderer: checking able to find orderer by name'
);
channel.addOrderer(orderer);
t.doesNotThrow(
() => {
channel._getOrderer('somehost.com:1234');
},
'Channel _getOrderer: checking able to find orderer by name'
);
function init() {
chain = client.newChain(config.chainName);
chain.addOrderer(new Orderer(config.orderer.orderer_url));
eventhub = new EventHub();
eventhub.setPeerAddr(config.events[0].event_url);
eventhub.connect();
for (var i = 0; i < config.peers.length; i++) {
chain.addPeer(new Peer(config.peers[i].peer_url));
}
}
function init () {
chain = client.newChain(config.chainName)
chain.addOrderer(new Orderer(config.orderer.orderer_url))
eventhub = new EventHub()
eventhub.setPeerAddr(config.events[0].event_url)
eventhub.connect()
for (var i = 0; i < config.peers.length; i++) {
chain.addPeer(new Peer(config.peers[i].peer_url))
}
}