A collection of assets is a convenient way to store indexed records of data; it comes with a rich API to read and write data to:
- add, remove, update, addupdate
- head, tail, sort, select
A detailed presentation of the asset API is available here.
In this exercise, a vehicle dealer manages his stock of rental cars on-chain for maximal transparency with customers and mechanical service suppliers:
- a car has a unique identifier, the vin, and is described with a color, the number of repairs and the last repair date.
- each time a car is repaired, the
repairentry point is called to update the vehicle's repair data; it increments the number of repairs and updates the last date of repair.
- a mechanical service supplier specializes on repairing the 3 cars with olded repair dates; a dedicated entry point
repair_oldesthas been designed to ease the update process.
- a nother mechanical service supplier is specialised in repainting cars which have been repaired at least once. A dedicated entry point
repaint_repairedhas been designed.
addvehicle entry point, the only necessary data to create the new asset is the vin because all other data have a default value. If no default value was set, the following would be necessary to create a new asset:
repaint_repaired entry point, this update syntax is adapted when a single field is updated; otherwize the
update operator is preferred for performance reason:
At last, note that the
sort function sorts in ascending order. Another way to implement that is:
The following Completium CLI command deploys the contract on the Tezos network:
The following command adds a vehicle:
The following command repairs vehicle with vin
The following repairs the 3 oldest vehicles:
Finally, repaint repaired vehicles in blue:
Enums are implemented with integer values starting from 0.
Open '8-1-contract_called.arl' and click on "Next: Call a Contract" below.