snowbridge_pallet_inbound_queue/
envelope.rs1use snowbridge_core::ChannelId;
4use snowbridge_inbound_queue_primitives::Log;
5
6use sp_core::{RuntimeDebug, H160, H256};
7use sp_std::prelude::*;
8
9use alloy_core::{primitives::B256, sol, sol_types::SolEvent};
10
11sol! {
12 event OutboundMessageAccepted(bytes32 indexed channel_id, uint64 nonce, bytes32 indexed message_id, bytes payload);
13}
14
15#[derive(Clone, RuntimeDebug)]
17pub struct Envelope {
18 pub gateway: H160,
20 pub channel_id: ChannelId,
22 pub nonce: u64,
24 pub message_id: H256,
26 pub payload: Vec<u8>,
28}
29
30#[derive(Copy, Clone, RuntimeDebug)]
31pub struct EnvelopeDecodeError;
32
33impl TryFrom<&Log> for Envelope {
34 type Error = EnvelopeDecodeError;
35
36 fn try_from(log: &Log) -> Result<Self, Self::Error> {
37 let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect();
38
39 let event = OutboundMessageAccepted::decode_raw_log_validate(topics, &log.data)
40 .map_err(|_| EnvelopeDecodeError)?;
41
42 Ok(Self {
43 gateway: log.address,
44 channel_id: ChannelId::from(event.channel_id.as_ref()),
45 nonce: event.nonce,
46 message_id: H256::from(event.message_id.as_ref()),
47 payload: event.payload.into(),
48 })
49 }
50}