【问题标题】:IBM Hyperledger Fabric : can't resolve reference Object from id MyObject#IBM Hyperledger Fabric:无法解析来自 id MyObject 的引用对象#
【发布时间】:2019-09-17 05:42:54
【问题描述】:

我正在使用 VSCodeExtention IBM 区块链平台在 typescript 中运行示例智能合约。

我只是按照这个步骤扩展:

  1. 创建新项目(在打字稿中)
  2. 打包这个项目
  3. 安装智能合约
  4. 实例化智能合约

当我更新我的模型 MyCloth 并运行 npm run build 时,一切顺利。但是当我尝试升级我的 SmartContrat 时,我收到了这个错误:

[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|  --module-path  [string] [default: "/usr/local/src"]
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|{ [Error: can't resolve reference Object from id MyClothe#]
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|  message: 'can\'t resolve reference Object from id MyClothe#',
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|  missingRef: 'Object',
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|  missingSchema: 'Object' }
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|npm ERR! code ELIFECYCLE
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|npm ERR! errno 1
[17.09.2019 à 07:28:39] [INFO] fabricvscodelocalfabric-peer0.org1.example.com-ClotheContract-0.0.4|npm ERR! ClotheContract@0.0.4 start: `fabric-chaincode-node start "--peer.address" "peer0.org1.example.com:17052"`

我的模特:

import { Object, Property } from 'fabric-contract-api';
import { Stakeholder, State } from '../enum';

@Object()
export class MyClothe {

    @Property()
    public id: string;

    @Property()
    public issuer: Stakeholder = Stakeholder.XXX; // the name or id of the company who issue the asset

    @Property()
    public owner: Stakeholder = Stakeholder.XXX; // the current owner of the asset

    @Property()
    public maturityDate: number = Date.now() + 1000 * 60 * 60 * 24 * 365; // the end date return of the asset in milisecond

    @Property()
    public additionalFee: number = 0; // Fee to charge the customer

    @Property()
    public currentState: State = State.Issued; // current state of the asset


    @Property()
    public params: any = { //new attribute added
        param1: 'param1',
        param2: 'param2',
    }; // Additional params in the future need
}

package.json

{
    "name": "ClotheContract",
    "version": "0.0.4",
    "description": "My Smart Contract",
    "main": "dist/index.js",
    "typings": "dist/index.d.ts",
    "engines": {
        "node": ">=8",
        "npm": ">=5"
    },
    "scripts": {
        "lint": "tslint -c tslint.json 'src/**/*.ts'",
        "pretest": "npm run lint",
        "test": "nyc mocha -r ts-node/register src/**/*.spec.ts",
        "start": "fabric-chaincode-node start",
        "build": "tsc",
        "build:watch": "tsc -w",
        "prepublishOnly": "npm run build"
    },
    "engineStrict": true,
    "author": "John Doe",
    "license": "Apache-2.0",
    "dependencies": {
        "fabric-contract-api": "1.4.2",
        "fabric-shim": "1.4.2"
    },
    "devDependencies": {
        "@types/chai": "^4.1.7",
        "@types/chai-as-promised": "^7.1.0",
        "@types/mocha": "^5.2.5",
        "@types/node": "^10.12.10",
        "@types/sinon": "^5.0.7",
        "@types/sinon-chai": "^3.2.1",
        "chai": "^4.2.0",
        "chai-as-promised": "^7.1.1",
        "mocha": "^5.2.0",
        "nyc": "^14.0.0",
        "sinon": "^7.1.1",
        "sinon-chai": "^3.3.0",
        "winston": "^3.2.1",
        "ts-node": "^7.0.1",
        "tslint": "^5.11.0",
        "typescript": "^3.1.6"
    },
    "nyc": {
        "extension": [
            ".ts",
            ".tsx"
        ],
        "exclude": [
            "coverage/**",
            "dist/**"
        ],
        "reporter": [
            "text-summary",
            "html"
        ],
        "all": true,
        "check-coverage": true,
        "statements": 100,
        "branches": 100,
        "functions": 100,
        "lines": 100
    }
}

【问题讨论】:

    标签: node.js typescript hyperledger-fabric ibm-blockchain ibp-vscode-extension


    【解决方案1】:

    问题是由于您的模型的这一部分

        @Property()
        public params: any = { //new attribute added
            param1: 'param1',
            param2: 'param2',
        }; //
    

    fabric-contract-api 看起来无法处理any 的类型。此外,它似乎也无法处理 object 类型,这可能更适合您的示例)。我不确定它是否应该能够处理这些类型,但最好是它提供更好的错误消息。 在您的情况下,解决方案是定义另一种类型来明确描述 params 属性。

    import {Params} from './paramdef'
    ...
    ...
        @Property()
        public params: Params = { //new attribute added
            param1: 'param1',
            param2: 'param2',
        }; //
    

    paramdef.ts

    import {Object, Property} from 'fabric-contract-api';
    
    @Object()
    export class Params {
       @Property()
       param1: string;
       @Property()
       param2: string;
    }
    

    【讨论】:

    • 确实,目前似乎不支持对象类型...我的解决方案是使用包含 json 数据的字符串 -> "{param1: 'foo', param2: 'bar'}" 并使用 JSON.parse(params) 作为暂时......但我会尝试你的解决方案!谢谢
    • 更多细节在这里:FAB-16629FAB-15538
    猜你喜欢
    • 2017-03-22
    • 1970-01-01
    • 2017-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多