0

I'm running a sample smartcontract in typescript with the VSCodeExtention IBM Blockchain Platform.

I just follow this step with the extention :

  1. Create new project (in typescript)
  2. Package this project
  3. Install the smart contract
  4. Instantiate the smart contract

When I update my model MyClothe and I run npm run build everything is going well. But when I tried to upgrade my SmartContrat I got this error :

[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"`

My Model :

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
    }
}

jdc
  • 384
  • 4
  • 15

1 Answers1

1

The problem is due to this section of your model

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

The fabric-contract-api looks like it can't handle the type of any. Also it would appear it cannot handle the type object either which would probably be more appropriate for your example). Whether it should be able to handle those types I'm not sure but what would be good is for it to provide a better error message. In your case the solution would be to define another type to explicitly describe the params property.

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;
}
david_k
  • 5,843
  • 2
  • 9
  • 16
  • Indeed, the object type does not seem to be supported for the moment ... My solution is to use string who contain json data -> `"{param1: 'foo', param2: 'bar'}"` and use JSON.parse(params) for the time being... But I'll try your solution ! Thks – jdc Sep 18 '19 at 06:28
  • More details here : [FAB-16629](https://jira.hyperledger.org/browse/FAB-16629) [FAB-15538](https://jira.hyperledger.org/browse/FAB-15538) – jdc Sep 18 '19 at 06:43