I am developing a chaincode written in Typescript using fabric-contract-api
and the IBM Blockchain Platform plugin for Visual Studio Code. My asset is called Order
and, though tests pass perfectly, I am unable to instantiate it. The error I get is the following one:
[6/3/2020 10:51:34] [INFO] fabricvscodelocalfabric-Org1Peer1-06-chaincode-1.0.0|{ [Error: can't resolve reference Object from id Order#]
[6/3/2020 10:51:34] [INFO] fabricvscodelocalfabric-Org1Peer1-06-chaincode-1.0.0| message: 'can\'t resolve reference Object from id Order#',
[6/3/2020 10:51:34] [INFO] fabricvscodelocalfabric-Org1Peer1-06-chaincode-1.0.0| missingRef: 'Object',
[6/3/2020 10:51:34] [INFO] fabricvscodelocalfabric-Org1Peer1-06-chaincode-1.0.0| missingSchema: 'Object' }
I think that the log is not clear enough and I am unable to locate the problem. I understand, as seen in other issues, that the problem is related to fabric-contract-api
being unable to handle types like any
or Object
. However, I am not using that in my code. Everything is declared.
I have started commenting the code function by function to locate the problem and, for example, I get that error if this function is not commented:
@Transaction()
public async createAsset(ctx: Context, assetConfigStringified: string): Promise<string> {
const assetConfig: IAssetConfig = JSON.parse(assetConfigStringified);
const assetId: string = await this.generateInternAssetId(ctx);
const exists = await this.assetExists(ctx, assetId);
if (exists) {
throw new Error(`The asset ${assetId} already exists`);
}
const asset: Asset = new Asset(assetConfig);
const buffer: Buffer = Buffer.from(JSON.stringify(asset));
await ctx.stub.putState(assetId, buffer);
return assetId;
}
These are the the declarations of the interfaces used:
@Object
export interface IComplexType {
propertyA: string;
propertyB: string;
propertyC: string;
propertyD: number;
propertyE?: string;
}
@Object
export interface IAssetConfig {
propertyA: string;
propertyB: IComplexType;
propertyC: IComplexType;
propertyD: string;
propertyE?: string;
}
And this is the asset class:
@Object()
export class Asset {
@Property()
public propertyA: string;
@Property()
public propertyB: IComplexType;
@Property()
public propertyC: IComplexType;
@Property()
public propertyD: string;
@Property()
public propertyE?: string;
constructor(assetConfig: IAssetConfig) {
this.propertyA = assetConfig.propertyA;
this.propertyB = assetConfig.propertyB;
this.propertyC = assetConfig.propertyB;
this.propertyD = assetConfig.propertyD;
if (assetConfig.hasOwnProperty('propertyE')) {
this.propertyE = assetConfig.propertyE;
}
}
}
Thank you very much.