Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function createAdminClient(clientName: string, ccp: CommonConnectionProfileHelper, clientOrg: string): Promise {
// check if the client already exists
const clientMap: Map | undefined = stateStore.get(Constants.CLIENTS);
if (clientMap && clientMap.has(clientName)) {
BaseUtils.logMsg(`Client named ${clientName} already exists`);
} else {
BaseUtils.logMsg(`Creating client named ${clientName} for organization ${clientOrg}`);
// Get a user
const user: User = createAdminUserForOrg(ccp, clientOrg);
// Form client with user
const client: Client = Client.newClient(clientName);
const enrollResponse: FabricCAServices.IEnrollResponse = await getTlsEnrollmentResponseForOrgUser(user, clientOrg, ccp);
client.setTlsClientCertAndKey(enrollResponse.certificate, enrollResponse.key.toBytes());
// persist client in state store for use later
if (clientMap) {
clientMap.set(clientName, { client, user, ccp, clientOrg });
} else {
const map: Map = new Map();
map.set(clientName, { client, user, ccp, clientOrg });
stateStore.set(Constants.CLIENTS, map);
}
BaseUtils.logMsg(`Created client named ${clientName} and persisted in state store`);
}
}
async (chaincode_name, channel_name) => {
const step = 'NodeSDK-Base Endorsement';
testUtil.logMsg(format('\n\n%s - STARTING\n', step));
// building a user object will be external to the new NodeSDK-Base
const user = getUser();
// This is like the old Client object in that it will be the starting point for
// building the client objects needed by the application. The result client
// instance will be used to create channels and store the client side connection
// information like the GRPC settings and the client side Mutual TLS cert and key.
const client = Client.newClient('myclient');
const tlsEnrollment = await getTLS_enrollment(user);
client.setTlsClientCertAndKey(tlsEnrollment.cert, tlsEnrollment.key);
// The channel object will be used to represent the peers and orderers
// and channel event hubs, the fabric network of the channel. Will be used
// to build any channel related protos (channel header). Will be the focal
// point for endorsements and queries on the channel. The channel object
// must be built by the client so that any peer or orderer object created
// by the discovery action on the channel will be able to get the connection
// information.
const channel = client.newChannel(channel_name);
// The peers and orderers will be built by the client so that common
// connection information will come from the client object, like the mutual TLS cert/key
const peer1 = client.newEndorser('peer1');
const peer2 = client.newEndorser('peer2');
const orderer = client.newCommitter('orderer');
async (chaincode_name, channel_name) => {
const step = 'NodeSDK-Base transient';
testUtil.logMsg(format('\n\n%s - STARTING\n', step));
const user = getUser();
const client = Client.newClient('myclient');
const tlsEnrollment = await getTLS_enrollment(user);
client.setTlsClientCertAndKey(tlsEnrollment.cert, tlsEnrollment.key);
const channel = client.newChannel(channel_name);
const peer1 = client.newEndorser('peer1');
const peer2 = client.newEndorser('peer2');
try {
const idx = client.newIdentityContext(user);
const peer1_endpoint = client.newEndpoint({
url: 'grpcs://localhost:7051',
pem: getPeer1_pem(),
'ssl-target-name-override': 'peer0.org1.example.com'
});
await peer1.connect(peer1_endpoint);
if (await peer1.checkConnection()) {
async (channel_name) => {
const step = 'NodeSDK-Base full block events with replay';
testUtil.logMsg(format('\n\n%s - STARTING\n', step));
const user = getUser();
const client = Client.newClient('myclient');
const tlsEnrollment = await getTLS_enrollment(user);
client.setTlsClientCertAndKey(tlsEnrollment.cert, tlsEnrollment.key);
const channel = client.newChannel(channel_name);
const eventer = client.newEventer('peer1-events');
try {
const idx = client.newIdentityContext(user);
const peer1_endpoint = client.newEndpoint({
url: 'grpcs://localhost:7051',
pem: getPeer1_pem(),
'ssl-target-name-override': 'peer0.org1.example.com'
});
try {
await eventer.connect(peer1_endpoint);
} catch (error) {
testUtil.logError(`Failed to connect to channel event hub ${eventer.name}`);