diff --git a/asset-transfer-basic/chaincode-javascript/lib/assetTransfer.js b/asset-transfer-basic/chaincode-javascript/lib/assetTransfer.js index 821e413a..a1a27aa4 100644 --- a/asset-transfer-basic/chaincode-javascript/lib/assetTransfer.js +++ b/asset-transfer-basic/chaincode-javascript/lib/assetTransfer.js @@ -65,6 +65,11 @@ class AssetTransfer extends Contract { // CreateAsset issues a new asset to the world state with given details. async CreateAsset(ctx, id, color, size, owner, appraisedValue) { + const exists = await this.AssetExists(ctx, id); + if (exists) { + throw new Error(`The asset ${id} already exists`); + } + const asset = { ID: id, Color: color, diff --git a/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts b/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts index b21f12ec..55b19b77 100644 --- a/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts +++ b/asset-transfer-basic/chaincode-typescript/src/assetTransfer.ts @@ -65,6 +65,11 @@ export class AssetTransferContract extends Contract { // CreateAsset issues a new asset to the world state with given details. @Transaction() public async CreateAsset(ctx: Context, id: string, color: string, size: number, owner: string, appraisedValue: number): Promise { + const exists = await this.AssetExists(ctx, id); + if (exists) { + throw new Error(`The asset ${id} already exists`); + } + const asset = { ID: id, Color: color,