@@ -92,7 +92,7 @@ pub mod pallet {
9292 /// that all other stuff (like `spec_version`) is ok. If we would try to decode
9393 /// `Call` which has been encoded using previous `spec_version`, then we might end
9494 /// up with decoding error, instead of `MessageVersionSpecMismatch`.
95- type EncodedCall : Decode + Encode + Into < Result < <Self as Config < I > >:: Call , ( ) > > ;
95+ type EncodedCall : Decode + Encode + Into < Result < <Self as Config < I > >:: Call , ( ) > > + Clone ;
9696 /// A type which can be turned into an AccountId from a 256-bit hash.
9797 ///
9898 /// Used when deriving target chain AccountIds from source chain AccountIds.
@@ -160,6 +160,16 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
160160 message. weight
161161 }
162162
163+ fn pre_dispatch (
164+ relayer_account : & T :: AccountId ,
165+ message : Result < & Self :: Message , ( ) > ,
166+ ) -> Result < ( ) , & ' static str > {
167+ let raw_message = message. map_err ( |_| "Invalid Message" ) ?;
168+ let call = raw_message. clone ( ) . call . into ( ) . map_err ( |_| "Invalid Call" ) ?;
169+
170+ T :: CallValidator :: check_receiving_before_dispatch ( relayer_account, & call)
171+ }
172+
163173 fn dispatch < P : FnOnce ( & T :: AccountId , bp_message_dispatch:: Weight ) -> Result < ( ) , ( ) > > (
164174 source_chain : ChainId ,
165175 target_chain : ChainId ,
@@ -275,8 +285,8 @@ impl<T: Config<I>, I: 'static> MessageDispatch<T::AccountId, T::BridgeMessageId>
275285 let dispatch_origin =
276286 T :: IntoDispatchOrigin :: into_dispatch_origin ( & origin_derived_account, & call) ;
277287
278- // filter the call
279- if let Err ( _ ) = T :: CallValidator :: pre_dispatch ( relayer_account, & dispatch_origin, & call) {
288+ // validate the call
289+ if let Err ( _e ) = T :: CallValidator :: call_validate ( relayer_account, & dispatch_origin, & call) {
280290 log:: trace!(
281291 target: "runtime::bridge-dispatch" ,
282292 "Message {:?}/{:?}: the call ({:?}) is rejected by filter" ,
@@ -560,7 +570,7 @@ mod tests {
560570 type TargetChainSignature = TestSignature ;
561571 }
562572
563- #[ derive( Decode , Encode ) ]
573+ #[ derive( Decode , Encode , Clone ) ]
564574 pub struct EncodedCall ( Vec < u8 > ) ;
565575
566576 impl From < EncodedCall > for Result < Call , ( ) > {
@@ -571,7 +581,14 @@ mod tests {
571581
572582 pub struct CallValidator ;
573583 impl CallValidate < AccountId , Origin , Call > for CallValidator {
574- fn pre_dispatch (
584+ fn check_receiving_before_dispatch (
585+ _relayer_account : & AccountId ,
586+ _call : & Call ,
587+ ) -> Result < ( ) , & ' static str > {
588+ Ok ( ( ) )
589+ }
590+
591+ fn call_validate (
575592 _relayer_account : & AccountId ,
576593 _origin : & Origin ,
577594 call : & Call ,
0 commit comments