|
| 1 | +.. _CIS-6: |
| 2 | + |
| 3 | +=============================== |
| 4 | +CIS-6: Track-and-Trace Standard |
| 5 | +=============================== |
| 6 | + |
| 7 | +.. list-table:: |
| 8 | + :stub-columns: 1 |
| 9 | + |
| 10 | + * - Created |
| 11 | + - Apr 25, 2024 |
| 12 | + * - Final |
| 13 | + - Apr 26, 2024 |
| 14 | + * - Supported versions |
| 15 | + - | Smart contract version 1 or newer |
| 16 | + | (Protocol version 4 or newer) |
| 17 | + * - Standard identifier |
| 18 | + - ``CIS-6`` |
| 19 | + * - Requires |
| 20 | + - :ref:`CIS-0<CIS-0>` |
| 21 | + |
| 22 | + |
| 23 | +Abstract |
| 24 | +======== |
| 25 | + |
| 26 | +A standard interface that defines the logged events for tracking items in a smart contract. |
| 27 | +The interface defines two events: |
| 28 | + |
| 29 | +- *ItemCreatedEvent* logs the ``item_id``, ``metadata_url``, and the ``initial_status``; |
| 30 | +- *ItemStatusChangedEvent* logs the ``item_id``, ``new_status``, and the ``additional_data``; |
| 31 | + |
| 32 | +Specification |
| 33 | +============= |
| 34 | + |
| 35 | +The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in :rfc:`2119`. |
| 36 | + |
| 37 | + |
| 38 | +General types and serialization |
| 39 | +------------------------------- |
| 40 | + |
| 41 | +.. _CIS-6-ItemId: |
| 42 | + |
| 43 | +``ItemId`` |
| 44 | +^^^^^^^^^^ |
| 45 | + |
| 46 | +Each item MUST have a unique ``ItemId``. |
| 47 | +An ``ItemId`` is a variable-length ASCII string up to 255 characters. |
| 48 | + |
| 49 | +The identifier is serialized as: 1 byte for the length (``n``) followed by this many bytes for the ASCII encoding of the identifier:: |
| 50 | + |
| 51 | + ItemId ::= (n: Byte) (id: Byteⁿ) |
| 52 | + |
| 53 | +.. _CIS-6-MetadataUrl: |
| 54 | + |
| 55 | +``MetadataUrl`` |
| 56 | +^^^^^^^^^^^^^^^ |
| 57 | + |
| 58 | +A URL and optional checksum for metadata stored outside of this contract. |
| 59 | + |
| 60 | +It is serialized as: 2 bytes for the length (``n``) of the metadata URL in little-endian and then this many bytes for the URL to the metadata (``url``) followed by an optional checksum. |
| 61 | +The checksum is serialized by 1 byte to indicate whether a hash of the metadata is included. |
| 62 | +If its value is 0, then there is no hash; if the value is 1, then 32 bytes for a SHA256 hash (``hash``) follows:: |
| 63 | + |
| 64 | + MetadataChecksum ::= (0: Byte) |
| 65 | + | (1: Byte) (hash: Byte³²) |
| 66 | + |
| 67 | + MetadataUrl ::= (n: Byte²) (url: Byteⁿ) (checksum: MetadataChecksum) |
| 68 | + |
| 69 | +.. _CIS-6-Status: |
| 70 | + |
| 71 | +``Status`` |
| 72 | +^^^^^^^^^^ |
| 73 | + |
| 74 | +The status defined by this specification is serialized using one byte to discriminate the different statuses that an item can have. |
| 75 | +The smart contract can have up to 255 different statuses defined for an item. |
| 76 | + |
| 77 | +It is serialized as: a byte of value (``n``):: |
| 78 | + |
| 79 | + Status ::= (n: Byte) |
| 80 | + |
| 81 | +.. _CIS-6-AdditionalData: |
| 82 | + |
| 83 | +``AdditionalData`` |
| 84 | +^^^^^^^^^^^^^^^^^^ |
| 85 | + |
| 86 | +Additional bytes to include in the event ``ItemStatusChangedEvent``, which can be used to add additional use-case-specific data (e.g. temperature, longitude, latitude, ...) to the event. |
| 87 | + |
| 88 | +It is serialized as: the first 2 bytes encode the length (``n``) of the data, followed by this many bytes for the data (``data``):: |
| 89 | + |
| 90 | + AdditionalData ::= (n: Byte²) (data: Byteⁿ) |
| 91 | + |
| 92 | +Logged events |
| 93 | +------------- |
| 94 | + |
| 95 | +The events defined by this specification are serialized using one byte to discriminate the different events. |
| 96 | +A custom event SHOULD NOT have a first byte colliding with any of the events defined by this specification. |
| 97 | + |
| 98 | +.. _CIS-6-events-ItemCreatedEvent: |
| 99 | + |
| 100 | +``ItemCreatedEvent`` |
| 101 | +^^^^^^^^^^^^^^^^^^^^ |
| 102 | + |
| 103 | +A ``ItemCreatedEvent`` event MUST be logged when a new item is created in the smart contract. |
| 104 | + |
| 105 | +The ``ItemCreatedEvent`` event is serialized as: first a byte with the value of 237, followed by the :ref:`CIS-6-ItemId` (``id``), the :ref:`CIS-6-MetadataUrl` (``metadata``), and then the :ref:`CIS-6-Status` (``initial_status``):: |
| 106 | + |
| 107 | + ItemCreatedEvent ::= (237: Byte) (item_id: ItemId) (metadata: MetadataUrl) (initial_status: Status) |
| 108 | + |
| 109 | +.. _CIS-6-events-ItemStatusChangedEvent: |
| 110 | + |
| 111 | +``ItemStatusChangedEvent`` |
| 112 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 113 | + |
| 114 | +A ``ItemStatusChangedEvent`` event MUST be logged when an item status is updated in the smart contract state. |
| 115 | + |
| 116 | +The ``ItemStatusChangedEvent`` event is serialized as: first a byte with the value of 236, followed by the :ref:`CIS-6-ItemId` (``id``), the :ref:`CIS-6-Status` (``new_status``), and then the :ref:`CIS-6-AdditionalData` (``additional_data``):: |
| 117 | + |
| 118 | + ItemStatusChangedEvent ::= (236: Byte) (item_id: ItemId) (new_status: Status) (additional_data: AdditionalData) |
0 commit comments