referrerpolicy=no-referrer-when-downgrade

snowbridge_pallet_outbound_queue/
types.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
3use codec::{Decode, Encode};
4use ethabi::Token;
5use frame_support::traits::ProcessMessage;
6use scale_info::TypeInfo;
7use snowbridge_core::ChannelId;
8use sp_core::H256;
9use sp_runtime::RuntimeDebug;
10use sp_std::prelude::*;
11
12use super::Pallet;
13
14pub type ProcessMessageOriginOf<T> = <Pallet<T> as ProcessMessage>::Origin;
15
16pub const LOG_TARGET: &str = "snowbridge-outbound-queue";
17
18/// Message which has been assigned a nonce and will be committed at the end of a block
19#[derive(Encode, Decode, Clone, PartialEq, RuntimeDebug, TypeInfo)]
20pub struct CommittedMessage {
21	/// Message channel
22	pub channel_id: ChannelId,
23	/// Unique nonce to prevent replaying messages
24	#[codec(compact)]
25	pub nonce: u64,
26	/// Command to execute in the Gateway contract
27	pub command: u8,
28	/// Params for the command
29	pub params: Vec<u8>,
30	/// Maximum gas allowed for message dispatch
31	#[codec(compact)]
32	pub max_dispatch_gas: u64,
33	/// Maximum fee per gas
34	#[codec(compact)]
35	pub max_fee_per_gas: u128,
36	/// Reward in ether for delivering this message, in addition to the gas refund
37	#[codec(compact)]
38	pub reward: u128,
39	/// Message ID (Used for tracing messages across route, has no role in consensus)
40	pub id: H256,
41}
42
43/// Convert message into an ABI-encoded form for delivery to the InboundQueue contract on Ethereum
44impl From<CommittedMessage> for Token {
45	fn from(x: CommittedMessage) -> Token {
46		Token::Tuple(vec![
47			Token::FixedBytes(Vec::from(x.channel_id.as_ref())),
48			Token::Uint(x.nonce.into()),
49			Token::Uint(x.command.into()),
50			Token::Bytes(x.params.to_vec()),
51			Token::Uint(x.max_dispatch_gas.into()),
52			Token::Uint(x.max_fee_per_gas.into()),
53			Token::Uint(x.reward.into()),
54			Token::FixedBytes(Vec::from(x.id.as_ref())),
55		])
56	}
57}