IBM Hyperledger Fabric: не удается разрешить ссылочный объект с идентификатором MyObject #

Я запускаю образец смарт-контракта в машинописном тексте с платформой VSCodeExtention IBM Blockchain.

Я просто следую этому шагу с расширением:

  1. Создать новый проект (в машинописном тексте)
  2. Упаковать этот проект
  3. Установить смарт-контракт
  4. Создайте смарт-контракт

Когда я обновляю свою модель MyClothe и запускаю 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! [email protected] 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
    }
}


person Johnny Da Costa    schedule 17.09.2019    source источник


Ответы (1)


Проблема связана с этим разделом вашей модели

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

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;
}
person david_k    schedule 17.09.2019
comment
Действительно, тип объекта, похоже, на данный момент не поддерживается ... Мое решение - использовать строку, содержащую данные json - ›"{param1: 'foo', param2: 'bar'}" и пока использовать JSON.parse (params) ... Но я попробую ваше решение! Спасибо - person Johnny Da Costa; 18.09.2019
comment
Подробнее здесь: FAB-16629 FAB-15538 - person Johnny Da Costa; 18.09.2019