referrerpolicy=no-referrer-when-downgrade

snowbridge_outbound_queue_primitives/v2/
delivery_receipt.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3use crate::Log;
4use alloy_core::{primitives::B256, sol, sol_types::SolEvent};
5use codec::Decode;
6use frame_support::pallet_prelude::{Encode, TypeInfo};
7use sp_core::{RuntimeDebug, H160, H256};
8use sp_std::prelude::*;
9
10sol! {
11	event InboundMessageDispatched(uint64 indexed nonce, bytes32 topic, bool success, bytes32 reward_address);
12}
13
14/// Delivery receipt
15#[derive(Clone, RuntimeDebug)]
16pub struct DeliveryReceipt {
17	/// The address of the outbound queue on Ethereum that emitted this message as an event log
18	pub gateway: H160,
19	/// The nonce of the dispatched message
20	pub nonce: u64,
21	/// Message topic
22	pub topic: H256,
23	/// Delivery status
24	pub success: bool,
25	/// The reward address
26	pub reward_address: [u8; 32],
27}
28
29#[derive(Copy, Clone, Encode, Decode, Eq, PartialEq, Debug, TypeInfo)]
30pub enum DeliveryReceiptDecodeError {
31	DecodeLogFailed,
32	DecodeAccountFailed,
33}
34
35impl TryFrom<&Log> for DeliveryReceipt {
36	type Error = DeliveryReceiptDecodeError;
37
38	fn try_from(log: &Log) -> Result<Self, Self::Error> {
39		let topics: Vec<B256> = log.topics.iter().map(|x| B256::from_slice(x.as_ref())).collect();
40
41		let event = InboundMessageDispatched::decode_raw_log_validate(topics, &log.data)
42			.map_err(|_| DeliveryReceiptDecodeError::DecodeLogFailed)?;
43
44		Ok(Self {
45			gateway: log.address,
46			nonce: event.nonce,
47			topic: H256::from_slice(event.topic.as_ref()),
48			success: event.success,
49			reward_address: event.reward_address.0,
50		})
51	}
52}