@fabric-es/operator
Version:
Network operator
35 lines • 1.58 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getGateway = void 0;
const util_1 = __importDefault(require("util"));
const fabric_network_1 = require("fabric-network");
const js_yaml_1 = __importDefault(require("js-yaml"));
const getLogger_1 = require("./getLogger");
const promiseToReadFile_1 = require("./promiseToReadFile");
const getGateway = async (option) => {
const logger = getLogger_1.getLogger({ name: '[operator] getGateway.js' });
const { connectionProfile, identity, asLocalhost, wallet } = option;
const gateway = new fabric_network_1.Gateway();
try {
const connection = await promiseToReadFile_1.promiseToReadFile(connectionProfile);
const ccp = js_yaml_1.default.safeLoad(connection);
await gateway.connect(ccp, {
identity,
wallet,
eventHandlerOptions: { strategy: fabric_network_1.DefaultEventHandlerStrategies.MSPID_SCOPE_ALLFORTX },
queryHandlerOptions: { strategy: fabric_network_1.DefaultQueryHandlerStrategies.MSPID_SCOPE_SINGLE },
discovery: { asLocalhost, enabled: true },
});
}
catch (e) {
logger.error(util_1.default.format('fail to connect gateway, %j', e));
throw new Error(e);
}
logger.info(util_1.default.format('gateway connected: %s'));
return gateway;
};
exports.getGateway = getGateway;
//# sourceMappingURL=getGateway.js.map