我正在尝试使用IBM区块链。我已经在IBM区块链上创建了设置,现在我试图通过IBM区块链上的node-SDK来注册用户,但是,当我尝试将应用程序管理员注册到IBM区块链时遇到了问题。 >
请帮助我找出问题所在,或让我知道我做错了什么地方。
连接文件。
{
"name": "mychannel","description": "Network on IBP v2","version": "1.0.0","client": {
"organization": "org1msp"
},"organizations": {
"org1msp": {
"mspid": "org1msp","peers": [
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
],"certificateAuthorities": [
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054"
]
},"org2MSP": {
"mspid": "org2MSP","peers": [
"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051"
]
}
},"orderers": {
"n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050","tlsCACerts": {
}
},"n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050","n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg3.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050","n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg4.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050","n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050": {
"url": "grpcs://n77513f-ordererorg5.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7050","tlsCACerts": {
}
}
},"peers": {
"n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051","tlsCACerts": {
},"grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
},"n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051": {
"url": "grpcs://n77513f-peer0org2.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7051","grpcOptions": {
"ssl-target-name-override": "n77513f-peer0org1retail.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud"
}
}
},"certificateAuthorities": {
"n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054": {
"url": "https://n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054","caName": "ca","tlsCACerts": {
}
}
}
}
我的配置文件。
{
"connection_file": "connection.json","appAdmin": "admin","appAdminSecret": "org1capw","orgMSPIiD": "dFarmMSP","caName": "n77513f-org1ca.mycluster-108893-93897c9faea121bae05cda32f6fe4dd1-0000.us-south.containers.appdomain.cloud:7054","channelname": "mychannle","username":" ","role":" ","chaincodeName":"dfarmsm","gatewayDiscovery": { "enabled": true,"asLocalhost": false }
}
node.js代码,用于注册管理员
'use strict';
const FabricCAServices = require('fabric-ca-client');
const {
FileSystemWallet,Gateway,X509WalletMixin
} = require('fabric-network');
const fs = require('fs');
const path = require('path');
var MongoClient = require('mongodb').MongoClient;
var Client = require('node-rest-client').Client;
var client = new Client();
const configPath = path.resolve(__dirname,'..','config','config.json');
const configJSON = fs.readFileSync(configPath,'utf8');
const config1 = JSON.parse(configJSON);
var connection_file = config1.connection_file;
var appAdmin = config1.appAdmin;
var gatewayDiscovery = config1.gatewayDiscovery;
var appAdminSecret = config1.appAdminSecret;
var orgMSPID = config1.orgMSPID;
var caName = config1.caName;
const ccpPath = path.resolve(__dirname,'connection.json');
const ccpJSON = fs.readFileSync(ccpPath,'utf8');
const ccp = JSON.parse(ccpJSON);
let response = {};
class FabricClientRegister {
constructor() {
console.log("called constructer");
}
async RegisterAdmin() {
try {
const setasyncTimeout = (cb,timeout = 0) => new Promise(resolve => {
setTimeout(() => {
cb();
resolve();
},timeout);
});
// Create a new CA client for interacting with the CA.
const caURL = ccp.certificateAuthorities[caName].url;
const ca = new FabricCAServices(caURL);
// Create a new file system based wallet for managing identities.
const walletPath = path.join(process.cwd(),'wallet');
const wallet = new FileSystemWallet(walletPath);
console.log(`Wallet path: ${walletPath}`);
// logger.log(`Wallet path: ${walletPath}`);
// Check to see if we've already enrolled the admin user.
const adminExists = await wallet.exists(appAdmin);
// console.log('here is admin exit')
// console.log('AdminExits',adminExists);
if (adminExists) {
response.data = null;
response.httpstatus = 400;
response.message = `An identity for the admin user ${appAdmin} already exists in the wallet`
// console.log('res',response)
return response;
}
// Enroll the admin user and import the new identity into the wallet.
const enrollment = await ca.enroll({
enrollmentID: appAdmin,enrollmentSecret: appAdminSecret
});
const identity = X509WalletMixin.createIdentity(orgMSPID,enrollment.certificate,enrollment.key.toBytes());
wallet.import(appAdmin,identity);
// logger.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
console.log('msg: Successfully enrolled admin user ' + appAdmin + ' and imported it into the wallet');
response.data = identity;
response.httpstatus = 200;
response.message = "admin enrolled successfully"
return response;
} catch (error) {
response.error = error;
response.httpstatus = 500;
response.message = "Failed to enroll admin due to above error";
return response;
}
};
让我知道我是否想念任何东西。并感谢您的进步。