Hyperledger fabric 如何以编程方式ping网络
我可以使用以下命令ping网络:Hyperledger fabric 如何以编程方式ping网络,hyperledger-fabric,hyperledger,hyperledger-composer,Hyperledger Fabric,Hyperledger,Hyperledger Composer,我可以使用以下命令ping网络: composer network ping -c admin@university 但是如何通过编程方式对Nodejs执行相同的操作?您可以使用child\u进程在Nodejs中执行编写器的ping命令 示例Nodejs代码如下所示 // http://nodejs.org/api.html#_child_processes var sys = require('sys') var exec = require('child_process').exec; v
composer network ping -c admin@university
但是如何通过编程方式对Nodejs执行相同的操作?您可以使用child\u进程在Nodejs中执行编写器的ping命令 示例Nodejs代码如下所示
// http://nodejs.org/api.html#_child_processes
var sys = require('sys')
var exec = require('child_process').exec;
var child;
// executes `pwd`
child = exec("pwd", function (error, stdout, stderr) {
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
// or more concisely
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("composer network ping -c admin@university", puts);
发件人:
很抱歉,我尝试在Nodejs中执行该函数,而不是调用它。无论如何谢谢你
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// This is a model to Network Actions
'use strict';
const BusinessNetworkConnection = require('composer-client').BusinessNetworkConnection;
const AdminConnection = require('composer-admin').AdminConnection;
const BusinessNetworkCardStore = require('composer-common').BusinessNetworkCardStore;
const IdCard = require('composer-common').IdCard;
/** Class for the Network*/
class Network {
/**
* Need to have the mapping from bizNetwork name to the URLs to connect to.
* bizNetwork nawme will be able to be used by Composer to get the suitable model files.
*
*/
constructor(credentials) {
this.bizNetworkConnection = new BusinessNetworkConnection();
this.adminConnection = new AdminConnection();
this.credentials = credentials
}
async ping() {
const idCardData = new IdCard(this.credentials['metadata'], this.credentials['connection']);
const idCardName = BusinessNetworkCardStore.getDefaultCardName(idCardData);
try{
const imported = await this.adminConnection.importCard(idCardName, idCardData);
if (imported) {
this.businessNetworkDefinition = await this.bizNetworkConnection.connect(idCardName);
if (!this.businessNetworkDefinition) {
console.log("Error in network connection");
throw "Error in network connection";
}
let result = await this.businessNetworkDefinition.ping();
return result
} else {
console.log('null');
throw "Error in importing card";
}
}catch(error){
console.log(error);
throw error;
}
}
}
module.exports = Network;