IBM Hyperledger Fabric: не удается разрешить ссылочный объект с идентификатором MyObject#
Я запускаю образец смарт-контракта в машинописном тексте с платформой VSCodeExtention IBM Blockchain.
Я просто следую этому шагу с расширением:
- Создать новый проект (в машинописном тексте)
- Упаковать этот проект
- Установить смарт-контракт
- Создайте смарт-контракт
Когда я обновляю свою модель 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! 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
}
}
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;
}