Update CreateAsset txn in basic js and ts sample (#460)

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 19:10:12 +01:00 committed by GitHub
parent f38845ecab
commit f84754ea3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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,