|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +pragma solidity ^0.8.20; |
| 4 | + |
| 5 | +/** |
| 6 | + * @dev The log passed from L2 |
| 7 | + * @param l2ShardId The shard identifier, 0 - rollup, 1 - porter. All other values are not used but are reserved for |
| 8 | + * the future |
| 9 | + * @param isService A boolean flag that is part of the log along with `key`, `value`, and `sender` address. |
| 10 | + * This field is required formally but does not have any special meaning. |
| 11 | + * @param txNumberInBatch The L2 transaction number in the batch, in which the log was sent |
| 12 | + * @param sender The L2 address which sent the log |
| 13 | + * @param key The 32 bytes of information that was sent in the log |
| 14 | + * @param value The 32 bytes of information that was sent in the log |
| 15 | + * Both `key` and `value` are arbitrary 32-bytes selected by the log sender |
| 16 | + */ |
| 17 | +struct L2Log { |
| 18 | + uint8 l2ShardId; |
| 19 | + bool isService; |
| 20 | + uint16 txNumberInBatch; |
| 21 | + address sender; |
| 22 | + bytes32 key; |
| 23 | + bytes32 value; |
| 24 | +} |
| 25 | + |
| 26 | +type L2LogLocator is uint256; |
| 27 | + |
| 28 | +function L2LogLocatorFrom(uint256 _batchNumber, uint256 _messageIndex, uint256 _txNumber) pure returns (L2LogLocator) { |
| 29 | + return L2LogLocator.wrap(_batchNumber << 128 | _messageIndex << 16 | _txNumber); |
| 30 | +} |
| 31 | + |
| 32 | +function batchNumber(L2LogLocator self) pure returns (uint256) { |
| 33 | + return L2LogLocator.unwrap(self) >> 128; |
| 34 | +} |
| 35 | + |
| 36 | +function messageIndex(L2LogLocator self) pure returns (uint256) { |
| 37 | + return uint112(L2LogLocator.unwrap(self) >> 16); |
| 38 | +} |
| 39 | + |
| 40 | +function txNumber(L2LogLocator self) pure returns (uint256) { |
| 41 | + return uint16(L2LogLocator.unwrap(self)); |
| 42 | +} |
| 43 | + |
| 44 | +using {batchNumber, txNumber, messageIndex} for L2LogLocator global; |
0 commit comments