微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

部署链码失败链码注册失败:容器以 1 退出

如何解决部署链码失败链码注册失败:容器以 1 退出

我一直在使用 Fabric 测试网络为我的项目研究 Hyperledger Fabric。 在我成功地试验了 FabCar 示例后,我想尝试使用 Javascript 编写我自己的类似于 FabCar 链码的链码。

首先,我根据在 youtube 上看到的 javascript 链码教程实现了一个简单的属性类。

'use strict';

class Property {
    constructor(id,name,signature) {
        this.ID = id;
        this.name = name;
        this.signature = signature;
    }

    static from(bufferOrjson){
        if (Buffer.isBuffer(bufferOrjson)){
            if (!bufferOrjson.length){
                return;
            }
            bufferOrjson = JSON.parse(bufferOrjson.toString('utf8'));
        }
        return Object.assign(new property(),bufferOrjson);
    }

    toBuffer() {
        return Buffer.from(JSON.stringify(this))
    }
}

export default {Property};

然后,我尝试实现与 Fabcar 类似的 Chaincode,但使用我作为对象创建的 Property 类。

'use strict';

import { Contract } from 'fabric-contract-api';
import { Property } from 'lib/property.js';

class FabProperty extends Contract {

    async InitLedger(ctx) {
        console.info('============= START : Initialize Ledger ===========');
        const properties = [
            new Property('p1','J House','adsd'),new Property('p2','12 Condo','4xes'),new Property('p3','U Mansion','man123')
        ];

        for (let i = 0; i < properties.length; i++) {
            await ctx.stub.putState(properties[i].ID,properties[i].toBuffer());
            console.info('Added <--> ',properties[i].name);
        }
        console.info('============= END : Initialize Ledger ===========');
    }

    async createProperty(ctx,id,signature) {
        const property = new Property(id,signature);
        ctx.stub.putState(id,property.toBuffer());
        return property.toBuffer();
    }

    async readProperty(ctx,id) {
        const propertyJSON = await ctx.stub.getState(id);
        if (!propertyJSON || propertyJSON.length === 0) {
            throw new Error(`The Property ${id} does not exist`);
        }
        return propertyJSON.toString();
    }

    async propertyExists(ctx,id) {
        const assetJSON = await ctx.stub.getState(id);
        return assetJSON && assetJSON.length > 0;
    }

    async updateProperty(ctx,signature) {
        const exists = await this.propertyExists(ctx,id);
        if (!exists) {
            throw new Error(`The Property ${id} does not exist`);
        }
        const updateProperty = new Property(id,signature);
        return ctx.stub.putState(id,updateProperty.toBuffer())
    }

    async deleteProperty(ctx,id) {
        const exists = await this.propertyExists(ctx,id);
        if (!exists) {
            throw new Error(`The Property ${id} does not exist`);
        }
        return ctx.stub.deleteState(id);
    }


}

module.exports = FabProperty;

之后,我尝试使用类似于部署 fabcar 的 shell 脚本的 shell 脚本来部署此链代码

但我无法部署我的链码并收到此错误

enter image description here

错误的原因是什么以及如何解决

现在,我怀疑我的 Javascript Chaincode 中可能存在错误,因为这是我第一次使用 Javascript 语言编写程序。我在 VSCode 中编写代码,因此没有警告或代码建议。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。