tezos_smart_rollup_host/
input.rs

1// SPDX-FileCopyrightText: 2022-2023 TriliTech <contact@trili.tech>
2// SPDX-FileCopyrightText: 2023 Marigold <contact@marigold.dev>
3//
4// SPDX-License-Identifier: MIT
5
6//! The possible types that may be returned by [Runtime](crate::runtime::Runtime) when reading an input.
7//!
8//! *N.B.* Reading input is currently only supported when the `alloc` feature is enabled.
9#![cfg(feature = "alloc")]
10
11use alloc::vec::Vec;
12
13/// An input from Layer 1 contains the inbox level, message number, and message payload.
14#[derive(Debug, PartialEq, Eq)]
15pub struct Message {
16    /// Inbox level of this message.
17    pub level: u32,
18    /// The message index in the rollup inbox.
19    pub id: u32,
20    payload: Vec<u8>,
21}
22
23impl Message {
24    /// Create a message input.
25    pub const fn new(level: u32, id: u32, payload: Vec<u8>) -> Self {
26        Self { level, id, payload }
27    }
28}
29
30impl AsRef<[u8]> for Message {
31    fn as_ref(&self) -> &[u8] {
32        self.payload.as_ref()
33    }
34}