Until this version, the only way to access an asset data was the field accessor operator of the form
A is the asset collection,
k the asset key and
f the asset field.
The first problem was the access to multiple fields; for example, consider the following asset declaration:
Accessing several fields would end up accessing the underlying map several times:
Here the test and fail instructions are repeated three times.
The second problem is the implicit fail of the
 operator in situations where it is implicit that the asset exists.
It is typically the case when the asset field is accessed in the
true branch of a
. operator treats the case when asset is not found while it has already been tested.
Combined with the new
?= declaration instruction, the proper way to retrieve all vehicle data presented above, is now as follows:
The declaration of
v fails with
"OPTION_IS_NONE" if vehicle is not found. It is possible to specify an error message with:
Single field access
Situations where a single asset field is accessed is very common though.
For example, the following retrieves an option of
nat to treat more specifically the case when the asset is not found:
opt_n is typed
option<nat> and is
none if the vehicle is not found.
. is still available: it fails when asset is not found, which is syntactically convenient when there is an implicit existence invariant on the asset:
It implictely fails with
("ASSET_NOT_FOUND", "vehicle") if
"1G1AF1F57A7192174" is not found.