Я пытаюсь использовать блокчейн IBM. Я создал установку для блокчейна IBM, и теперь я пытаюсь зарегистрировать пользователя с помощью node-SDK в блокчейне IBM, однако при попытке зарегистрировать app-admin в блокчейне 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",
"tlsCACerts": {
}
},
"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",
"tlsCACerts": {
}
},
"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",
"tlsCACerts": {
}
},
"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",
"tlsCACerts": {
},
"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, '..', 'config', '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;
}
};
Дайте мне знать, если что-то мне не хватает. и спасибо за продвижение.