@siglesiasg/node-red-hyperledger-fabric-gateway
Version:
Hyperledger Fabric 2.x nodes for node-red with latest fabric-gateway library
50 lines • 2.62 kB
JavaScript
;
const fabric_functions_1 = require("../../libs/fabric-functions");
const node_red_utils_1 = require("../../libs/node-red-utils");
const connection_config_model_1 = require("../../models/connection-config.model");
const fabric_decoder_1 = require("./../../libs/fabric-decoder");
const fabric_error_handler_1 = require("./../../libs/fabric-error-handler");
module.exports = (RED) => {
RED.nodes.registerType('fabric-block-info', fabricGetBlockNode);
function fabricGetBlockNode(config) {
RED.nodes.createNode(this, config);
const connection = (0, connection_config_model_1.buildConnectionConfig)(RED, config);
const fabricChannelDef = (0, node_red_utils_1.getConfigValidate)(RED, config.channelSelector);
const blockDecoder = (0, fabric_decoder_1.buildBlockDecoder)(fabricChannelDef.channel);
this.debug('Fabric Get Block By Number Node Created');
this.status({ fill: 'green', shape: 'dot', text: 'Ready' });
this.on('input', async (msg, send, done) => {
try {
this.status({ fill: 'yellow', shape: 'dot', text: 'Querying...' });
let transactionName;
let transactionArgs;
if (config.method === 'number') {
transactionName = 'GetBlockByNumber';
transactionArgs = [fabricChannelDef.channel, config.blockNumber];
}
else if (config.method === 'hash') {
transactionName = 'GetBlockByHash';
transactionArgs = [fabricChannelDef.channel, config.blockHash];
}
else if (config.method === 'txId') {
transactionName = 'GetBlockByTxID';
transactionArgs = [fabricChannelDef.channel, config.txId];
}
else {
throw new Error('Config method invalid: ' + config.method);
}
await (0, fabric_functions_1.invokeChaincodeGeneric)(RED, this, msg, blockDecoder, 'evaluate', connection, config.channelSelector, 'qscc', transactionName, transactionArgs);
this.status({ fill: 'green', shape: 'dot', text: 'Done' });
send(msg);
done();
}
catch (error) {
(0, fabric_error_handler_1.handleError)(this, done, error);
}
});
this.on('close', async (removed, done) => {
await fabric_functions_1.closeConnection.call(this, connection, done);
});
}
};
//# sourceMappingURL=fabric-block-info.js.map