mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
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:
parent
f38845ecab
commit
f84754ea3b
2 changed files with 10 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue