pallet_bridge_relayers/extension/
messages_adapter.rs1use crate::{extension::verify_messages_call_succeeded, Config as BridgeRelayersConfig};
21
22use bp_relayers::{ExtensionCallData, ExtensionCallInfo, ExtensionConfig};
23use bp_runtime::StaticStrProvider;
24use core::marker::PhantomData;
25use frame_support::dispatch::{DispatchInfo, PostDispatchInfo};
26use pallet_bridge_messages::{
27 CallSubType as BridgeMessagesCallSubType, Config as BridgeMessagesConfig, LaneIdOf,
28};
29use sp_runtime::{
30 traits::{Dispatchable, Get},
31 transaction_validity::{TransactionPriority, TransactionValidityError},
32};
33
34pub struct WithMessagesExtensionConfig<
37 IdProvider,
38 Runtime,
39 BridgeMessagesPalletInstance,
40 BridgeRelayersPalletInstance,
41 PriorityBoostPerMessage,
42>(
43 PhantomData<(
44 IdProvider,
46 Runtime,
48 BridgeMessagesPalletInstance,
50 BridgeRelayersPalletInstance,
52 PriorityBoostPerMessage,
54 )>,
55);
56
57impl<ID, R, MI, RI, P> ExtensionConfig for WithMessagesExtensionConfig<ID, R, MI, RI, P>
58where
59 ID: StaticStrProvider,
60 R: BridgeRelayersConfig<RI> + BridgeMessagesConfig<MI>,
61 MI: 'static,
62 RI: 'static,
63 P: Get<TransactionPriority>,
64 R::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>
65 + BridgeMessagesCallSubType<R, MI>,
66{
67 type IdProvider = ID;
68 type Runtime = R;
69 type BridgeMessagesPalletInstance = MI;
70 type BridgeRelayersPalletInstance = RI;
71 type PriorityBoostPerMessage = P;
72 type RemoteGrandpaChainBlockNumber = ();
73 type LaneId = LaneIdOf<R, Self::BridgeMessagesPalletInstance>;
74
75 fn parse_and_check_for_obsolete_call(
76 call: &R::RuntimeCall,
77 ) -> Result<
78 Option<ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber, Self::LaneId>>,
79 TransactionValidityError,
80 > {
81 let call = Self::check_obsolete_parsed_call(call)?;
82 Ok(call.call_info().map(ExtensionCallInfo::Msgs))
83 }
84
85 fn check_obsolete_parsed_call(
86 call: &R::RuntimeCall,
87 ) -> Result<&R::RuntimeCall, TransactionValidityError> {
88 call.check_obsolete_call()?;
89 Ok(call)
90 }
91
92 fn check_call_result(
93 call_info: &ExtensionCallInfo<Self::RemoteGrandpaChainBlockNumber, Self::LaneId>,
94 call_data: &mut ExtensionCallData,
95 relayer: &R::AccountId,
96 ) -> bool {
97 verify_messages_call_succeeded::<Self>(call_info, call_data, relayer)
98 }
99}