mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
* Switched private data JS app to commons util Reusing JS app & ca utils Refactored for Org1 & Org2 assettransfer-basic JS app update for commons util refactor Signed-off-by: Sijo Cherian <sijo@ibm.com> * fixed assettransfer-ledgerqueries & private usage of commons util refactor Signed-off-by: Sijo Cherian <sijo@ibm.com> Co-authored-by: Sijo Cherian <sijo@ibm.com>
57 lines
1.7 KiB
JavaScript
57 lines
1.7 KiB
JavaScript
/*
|
|
* Copyright IBM Corp. All Rights Reserved.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
exports.buildCCPOrg1 = () => {
|
|
// load the common connection configuration file
|
|
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network', 'organizations', 'peerOrganizations', 'org1.example.com', 'connection-org1.json');
|
|
const fileExists = fs.existsSync(ccpPath);
|
|
if (!fileExists) {
|
|
throw new Error(`no such file or directory: ${ccpPath}`);
|
|
}
|
|
const contents = fs.readFileSync(ccpPath, 'utf8');
|
|
|
|
// build a JSON object from the file contents
|
|
const ccp = JSON.parse(contents);
|
|
|
|
console.log(`Loaded the network configuration located at ${ccpPath}`);
|
|
return ccp;
|
|
};
|
|
|
|
exports.buildCCPOrg2 = () => {
|
|
// load the common connection configuration file
|
|
const ccpPath = path.resolve(__dirname, '..', '..', 'test-network',
|
|
'organizations', 'peerOrganizations', 'org2.example.com', 'connection-org2.json');
|
|
const fileExists = fs.existsSync(ccpPath);
|
|
if (!fileExists) {
|
|
throw new Error(`no such file or directory: ${ccpPath}`);
|
|
}
|
|
const contents = fs.readFileSync(ccpPath, 'utf8');
|
|
|
|
// build a JSON object from the file contents
|
|
const ccp = JSON.parse(contents);
|
|
|
|
console.log(`Loaded the network configuration located at ${ccpPath}`);
|
|
return ccp;
|
|
};
|
|
|
|
exports.buildWallet = async (Wallets, walletPath) => {
|
|
// Create a new wallet : Note that wallet is for managing identities.
|
|
let wallet;
|
|
if (walletPath) {
|
|
wallet = await Wallets.newFileSystemWallet(walletPath);
|
|
console.log(`Built a file system wallet at ${walletPath}`);
|
|
} else {
|
|
wallet = await Wallets.newInMemoryWallet();
|
|
console.log('Built an in memory wallet');
|
|
}
|
|
|
|
return wallet;
|
|
};
|