简体   繁体   English

部署自定义链码时出现 Hyperledger 结构错误

[英]Hyperledger fabric error while deploying a custom chaincode

I tried to deploy a chaincode to test-network(fabric sample/hyperledger fabric 2.2).我尝试将链代码部署到测试网络(结构示例/超级账本结构 2.2)。 I followed these steps mentioned in documentations https://hyperledger-fabric.readthedocs.io/en/release-2.0/deploy_chaincode.html .我按照文档https://hyperledger-fabric.readthedocs.io/en/release-2.0/deploy_chaincode.html中提到的这些步骤进行操作。

this is the smart contract::这是智能合约::

 'use strict';

const { Contract } = require('fabric-contract-api'); const { Contract } = require('fabric-contract-api');

class RegisterUser extends Contract { class RegisterUser 扩展合同 {

async initLedger(ctx) {
    console.info('============= START : Initialize Ledger ===========');
    const users = [
        {
            UserId: 'admin',
            
            FirstName : 'network',
            LastName : 'supervisor',
            BillFold : 'none',
        },
       
    ];

    for (let i = 0; i < users.length; i++) {
        users[i].docType = 'user';
        await ctx.stub.putState('USER' + i, Buffer.from(JSON.stringify(users[i])));
        console.info('Added <--> ', users[i]);
    }
    console.info('============= END : Initialize Ledger ===========');
}


async queryUser(ctx, userId) {
    const userAsBytes = await ctx.stub.getState(userId); e
    if (!userAsBytes || userAsBytes.length === 0) {
        throw new Error(`${userId} does not exist`);
    }
    console.log(userAsBytes.toString());
    return userAsBytes.toString();
}

async createUser(ctx, userId, first_name, last_name,billfoldId) {
    console.info('============= START : Create User ===========');

    const user = {
        UserId: userId,
        doctype : 'user',
        FirstName : first_name,
        LastName : last_name,
        BillFold : billfoldId,
    };

    await ctx.stub.putState(userId, Buffer.from(JSON.stringify(user)));
    console.info('============= END : Create User ===========');
}

} module.exports = RegisterUser; } module.exports = 注册用户;

Runing a node application that implement the chaincode gives this error:运行实现链码的节点应用程序会出现此错误:

2021-03-30T10:55:42.115Z - error: [Transaction]: Error: No valid responses from any peers. Errors:
peer=peer0.org1.example.com:7051, status=500, message=error in simulation: failed to execute transaction 112a4c6dbf49bdea7aaa4ca5e24a03eeebf89a0989d278319cf6aecae061d310: could not launch chaincode usercontract_1.0:995a82a19e6a5e211d6ca52dff9eccb5cfd79249418657e0c9f599c9b1ffe9f0: chaincode registration failed: container exited with 1
peer=peer0.org2.example.com:9051, status=500, message=error in simulation: failed to execute transaction 112a4c6dbf49bdea7aaa4ca5e24a03eeebf89a0989d278319cf6aecae061d310: could not launch chaincode usercontract_1.0:995a82a19e6a5e211d6ca52dff9eccb5cfd79249418657e0c9f599c9b1ffe9f0: chaincode registration failed: container exited with 1

During installation, a docker container would be spun off based on your chaincode language.在安装过程中,docker 容器将根据您的链码语言进行分离。 Monitor this docker container's logs and you'll see the reason for failure.监控这个 docker 容器的日志,你会看到失败的原因。 All the best.一切顺利。 If you are running all this on windows, then docker desktop would give you realtime view of the containers that are UP and with mouse clicks you can see the docker container logs too.如果您在 windows 上运行所有这些,那么 docker 桌面将为您提供已启动的容器的实时视图,并且通过鼠标单击您也可以看到 Z05B6053C41A2130AFD6FC3B158BDA4EZ 容器日志。

Without monitoring the docker container logs it is hard to tell why something is failing.如果不监视 docker 容器日志,就很难判断出故障的原因。 All the best.一切顺利。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM