1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// SPDX-FileCopyrightText: 2022-2023 TriliTech <contact@trili.tech>
// SPDX-FileCopyrightText: 2023 Marigold <contact@marigold.dev>
//
// SPDX-License-Identifier: MIT

//! The possible types that may be returned by [Runtime](crate::runtime::Runtime) when reading an input.
//!
//! *N.B.* Reading input is currently only supported when the `alloc` feature is enabled.
#![cfg(feature = "alloc")]

use alloc::vec::Vec;

/// An input from Layer 1 contains the inbox level, message number, and message payload.
#[derive(Debug, PartialEq, Eq)]
pub struct Message {
    /// Inbox level of this message.
    pub level: u32,
    /// The message index in the rollup inbox.
    pub id: u32,
    payload: Vec<u8>,
}

impl Message {
    /// Create a message input.
    pub const fn new(level: u32, id: u32, payload: Vec<u8>) -> Self {
        Self { level, id, payload }
    }
}

impl AsRef<[u8]> for Message {
    fn as_ref(&self) -> &[u8] {
        self.payload.as_ref()
    }
}