Update CreateAsset txn in basic js and ts sample

The Golang and Java sample chaincode returned an error when trying to create an asset which already exists

JavaScript and TypeScript samples should now do the same

Signed-off-by: James Taylor <jamest@uk.ibm.com>
This commit is contained in:
James Taylor 2021-07-16 15:54:54 +01:00
parent f38845ecab
commit fb2bcb309e
2 changed files with 10 additions and 0 deletions

View file

@ -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,

View file

@ -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<void> {
const exists = await this.AssetExists(ctx, id);
if (exists) {
throw new Error(`The asset ${id} already exists`);
}
const asset = {
ID: id,
Color: color,