How to use the fabric-client.loadFromConfig function in fabric-client

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

github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / utility / adminUtils.ts View on Github external
export async function isChaincodeInstantiatedOnChannel(orgName: string, ccp: CommonConnectionProfileHelper, channelName: string, chaincodeName: string, chaincodeVersion: string): Promise<boolean> {
	BaseUtils.logMsg(`Checking if smart contract ${chaincodeName} has been instantiated on channel ${channelName}`);
	const clientPath: string = path.join(__dirname, Constants.UTIL_TO_CONFIG, orgName + '.json');
	const orgClient: Client = await Client.loadFromConfig(clientPath);

	// Augment it with full CCP
	await assignOrgAdmin(orgClient, orgName, ccp);

	// Get the channel and a peer
	const channel: Client.Channel = orgClient.getChannel(channelName);
	const peer: Client.Peer = orgClient.getPeersForOrg(orgName + 'MSP')[0];

	BaseUtils.logMsg(`Querying channel ${channel.getName()} for instantiated chaincode`);
	const message: Client.ChaincodeQueryResponse = await channel.queryInstantiatedChaincodes(peer, true);

	// loop over message array if present
	let isInstantiated: boolean = false;
	for (const chaincode of message.chaincodes) {
		if ( (chaincode.name.localeCompare(chaincodeName) === 0) && (chaincode.version.localeCompare(chaincodeVersion) === 0)) {
			isInstantiated = true;
github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / chaincode.ts View on Github external
export async function installPackagedContractForOrg(orgName: string, contractName: string, ccp: CommonConnectionProfileHelper): Promise<void> {
	const contractSaveName: string = `contract-${orgName}-${contractName}`;

	// Get the Client for passed Org
	const orgClient: Client = await Client.loadFromConfig(ccp.getProfile());

	// Get the first target peer for our org
	const peer: Client.Peer = orgClient.getPeersForOrg(orgName + 'MSP')[0];

	const chaincode: Client.Chaincode = Client.getConfigSetting(contractSaveName).value;

	const request: Client.ChaincodeInstallRequest = {
		request_timeout: Constants.INSTALL_TIMEOUT as number,
		target: peer,
	};

	// Install
	try {
		BaseUtils.logMsg(`About to perform install for the smart contract named ${contractName} on org ${orgName}`);
		const packageId: string = await chaincode.install(request);
		BaseUtils.logMsg(`Installed the smart contract with package ID of ${packageId} on org ${orgName}`);
github hyperledger / fabric-sdk-node / test / ts-scenario / steps / lib / chaincode.ts View on Github external
export async function queryCommitReadinessAsOrgOnChannel(orgName: string, contractName: string, channelName: string, ccp: CommonConnectionProfileHelper, expectedStatus: any): Promise<void> {
	const contractSaveName: string = `contract-${orgName}-${contractName}`;

	// Get the Client for passed Org
	const orgClient: Client = await Client.loadFromConfig(ccp.getProfile());
	await AdminUtils.getSubmitter(orgClient, true, orgName, ccp);

	// Get the first target peer for our org
	const target: Client.Peer = orgClient.getPeersForOrg(orgName + 'MSP')[0];
	const channel: Client.Channel = orgClient.getChannel(channelName);

	const chaincode: Client.Chaincode = Client.getConfigSetting(contractSaveName).value;

	const txId: Client.TransactionId = orgClient.newTransactionID(true);

	const request: Client.QueryApprovalStatusRequest = {
		chaincode,
		target,
		txId,
	};
github IBM / monitoring_ui / react-backend / routes / index.js View on Github external
//         'Accept': 'application/json',
    //         'Content-Type': 'application/json',
    //         'Accept-Charset': 'utf-8',
    //         "Authorization": "Basic " + new Buffer(req.body.key + ":" + req.body.secret, "utf8").toString("base64")
    //     }
    // }
    // request(options, function(err, res, body) {
    //   let json = JSON.parse(body);
    //   fs.writeFile('./connection_profile.json', body, 'utf8', function(err){
    //     if (err) {console.log(err)}
    //   })
    //   config = hfc.loadFromConfig(json)
    // });
    client = hfc.loadFromConfig('./connection_profile.json')
  } else {
    client = hfc.loadFromConfig(requestConnectionProfile(req))
  }

  org = Object.keys(client._network_config._network_config.organizations)[0]
  certificateAuthorities = client._network_config._network_config.certificateAuthorities
  certificateAuthorityName = Object.keys(certificateAuthorities)[0]
  certificateAuthObj = certificateAuthorities[certificateAuthorityName]
  mspId = client._network_config._network_config.organizations[org]['mspid']
  storePath = './'
  client_crypto_suite = hfc.newCryptoSuite()
  crypto_store = hfc.newCryptoKeyStore({path: storePath})
  crypto_suite = hfc.newCryptoSuite()
  crypto_suite.setCryptoKeyStore(crypto_store)
  username = "monitoring_admin"
  // var crypto_store = hfc.newCryptoKeyStore({path: storePath})
  // crypto_suite.setCryptoKeyStore(crypto_store)
  client.setCryptoSuite(crypto_suite)
github olegabu / fabric-starter-rest / fabric-starter-client.js View on Github external
constructor(networkConfig) {
        this.networkConfig = networkConfig || require('./network')();
        logger.info('constructing with network config', JSON.stringify(this.networkConfig));
        this.client = Client.loadFromConfig(this.networkConfig); // or networkConfigFile
        this.ordererClient = Client.loadFromConfig(this.networkConfig); // or networkConfigFile
        this.peer = this.client.getPeersForOrg()[0];
        this.org = this.networkConfig.client.organization;
        this.affiliation = this.org;
        this.channelsInitializationMap = new Map();
        this.registerQueue = new Map();
    }
github hyperledger / fabric-sdk-node / test / unit / network-config.js View on Github external
async () => {
			const client = await Client.loadFromConfig(network_config);
			const suite = await Client.newCryptoSuite();
			client.setCryptoSuite(suite);
			client.setUserContext(new User('testUser'), true);
			const channel = client.getChannel('mychannel');
			channel._getTargetForQuery(['peer1']);
		},
		/array/,
github IBM / securitization_blockchain / sc-ui / react-backend / routes / index.js View on Github external
function loadConnectionProfile() {
  if (fs.existsSync('./connection_profile.json')) {
    console.log("Local connection profile loading")
    client = hfc.loadFromConfig('../connection_profile.json')
    var username = "monitoring_admin"
    client.loadUserFromStateStore("./hfc-key-store/hosted/")
    client.getUserContext(username, true).then((user) => {
      console.log("Loading user context")
      console.log(user)
      if (user && user.isEnrolled()) {
        console.log("Client Loaded From Persistence")
      }
    })
  }
}
loadConnectionProfile()
github IBM / securitization_blockchain / sc-ui / react-backend / routes / index.js View on Github external
function initializeLocalClient() {
  var endpoint = "http://ca.example.com"
  console.log("Initializing Local HFC client")
  client = hfc.loadFromConfig('../local/connection.json')
  ca = new CAClient(endpoint + ":7054", {
    trustedRoots: [],
    verify: false
  }, 'ca.example.com', client_crypto_suite)
  var storePath = './hfc-key-store/local'
  var client_crypto_suite = hfc.newCryptoSuite()
  var crypto_store = hfc.newCryptoKeyStore({
    path: storePath
  })
  var crypto_suite = hfc.newCryptoSuite()
  var username = "monitoring_admin"
  sec_chaincode = {
    name: "securitization",
    version: "1.0"
  }
  async.series([