This is a smart contract for a property asset management system.
CreateAsset(ctx, propertyId, name, quantity, price, image)
Creates a new asset in the ledger with the specified properties. Each asset is assigned a unique UUID.
- Parameters:
propertyId
: The ID of the property this asset belongs toname
: Name of the assetquantity
: Number of items in stockprice
: Price per unitimage
: Image filename/URL for the asset
- Returns: JSON string of the created asset
ReadAsset(ctx, id)
Retrieves an asset from the ledger by its ID.
- Parameters:
id
: Unique identifier of the asset
- Returns: JSON string of the requested asset
- Throws: Error if asset doesn't exist
UpdateAsset(ctx, id, propertyId, name, quantity, price, image)
Updates an existing asset in the ledger with new values.
- Parameters:
id
: Unique identifier of the asset to updatepropertyId
: The ID of the property this asset belongs toname
: Updated name of the assetquantity
: Updated quantityprice
: Updated priceimage
: Updated image filename/URL
- Returns: JSON string of the updated asset
- Throws: Error if asset doesn't exist
DeleteAsset(ctx, id)
Removes an asset from the ledger.
- Parameters:
id
: Unique identifier of the asset to delete
- Throws: Error if asset doesn't exist
GetAllAssets(ctx, propertyId?)
Retrieves all assets from the ledger with optional filtering by property ID.
- Parameters:
propertyId
(optional): Filter assets by property ID
- Returns: JSON string array of assets
- Behavior:
- If
propertyId
is provided: Returns only assets belonging to that property - If
propertyId
is not provided: Returns all assets in the ledger
- If
- Example response:
zip -r chaincode-javascript.zip . -x "node_modules/*"
then import the zip file to the Kaleido app