Hyperledger面料注册Admin

时间:2018-01-25 16:01:55

标签: sdk hyperledger-fabric

我正在使用以下代码在Hyperledger结构中注册Admin

fabric_ca_client = new    fabric_CA_Client('https://localhost:3000',tlsOptions , ca.example.com',' crypto_suite);


return fabric_client.getUserContext('admin', true); }).then((user_from_store) => {
if (user_from_store && user_fro_store.isEnrolled()) {
    console.log('Successfully loaded admin from persistence');
    admin_user = user_from_store;
    return null;
} else {
    // need to enroll it with CA server
    console.log(' Trying to enroll user since it is not already enrolled')
    return fabric_ca_client.enroll({
      enrollmentID: 'admin',
      enrollmentSecret: 'adminpw'
    }).then((enrollment) => {
      console.log('Successfully enrolled admin user "admin"');
      return fabric_client.createUser(
          {   username: 'admin',
              mspid: 'Org1MSP',
              cryptoContent: { privateKeyPEM: enrollment.key.toBytes(), signedCertPEM: enrollment.certificate }
   });
    }).then((user) => {
      admin_user = user;
      console.log(admin_user)
      return fabric_client.setUserContext(admin_user);
    }).catch((err) => {
      console.error('Failed to enroll and persist admin. Error: ' + err.stack ? err.stack : err);
      throw new Error('Failed to enroll admin');
    });
}

我的user_from_store正在返回null,因此所有代码都是失败的,请告知我的错误。

0 个答案:

没有答案