I have a routine on my nodejs server which monitors blockchain events and displays selected information when chain events occur. The code for this routine follows. This code does not work in the kube cluster and I expect that the reason is that the pem file used for admin in the original docker container is no longer valid. Is there are recommended way for me to now connect to hyperledger fabric to monitor events similar to the code below? This is part of a demonstration environment and the blockchain event data is used to display what's happening during the demo.
Appreciate any insight into resolving this.
exports.getChainEvents = function(req, res, next)
{
if (chainEvents) {res.send({'port': svc.cs_socketAddr});}
else
{
let channel = {};
let client = null;
let wallet_path = path.join(__dirname, 'creds');
Promise.resolve().then(() => {
client = new hfc();
return hfc.newDefaultKeyValueStore({ path: wallet_path })
.then((wallet) => {
client.setStateStore(wallet);
return client.getUserContext(config.composer.PeerAdmin, true);})
.then((user) => {
if (user === null || user === undefined || user.isEnrolled() === false)
{console.error('User not defined, or not enrolled - error');}
channel = client.newChannel(config.fabric.channelName);
channel.addPeer(client.newPeer(config.fabric.peerRequestURL));
channel.addOrderer(client.newOrderer(config.fabric.ordererURL));
// change Admin in following line to admin
let pemPath = path.join(__dirname,'creds','admin@org.hyperledger.composer.system-cert.pem');
let adminPEM = fs.readFileSync(pemPath);
let bcEvents = new hfcEH(client);
bcEvents.setPeerAddr(config.fabric.peerEventURL, {pem: adminPEM});
bcEvents.connect();
svc.createChainSocket();
bcEvents.registerBlockEvent(function(event) {svc.cs_connection.sendUTF(JSON.stringify(event));});
chainEvents = true;
res.send({'port': svc.cs_socketAddr});
});
});
}
};
The root cause of the problem for this issue turns out to be a combination of
(1) Configuration changes between the Docker deploy and the Kubernetes deploy. the changes are:
certificate authority name change from ca.example.org to CA
channel name change from composer to channel1
(2) An ongoing issue with hyperledger fabric which prevents the fabric from using the program-defined key store and, instead, only uses ~/.hfc-key-store
I have a routine on my nodejs server which monitors blockchain events and displays selected information when chain events occur. The code for this routine follows. This code does not work in the kube cluster and I expect that the reason is that the pem file used for admin in the original docker container is no longer valid. Is there are recommended way for me to now connect to hyperledger fabric to monitor events similar to the code below? This is part of a demonstration environment and the blockchain event data is used to display what's happening during the demo.
Appreciate any insight into resolving this.