@@ -43,6 +43,29 @@ use sp_std::{fmt::Debug, prelude::*};
4343use sp_trie:: { record_all_keys, trie_types:: TrieDBMutV1 , LayoutV1 , MemoryDB , Recorder , TrieMut } ;
4444use sp_version:: RuntimeVersion ;
4545
46+ /// Return this chain account, used to dispatch message.
47+ pub fn dispatch_account < B > ( ) -> AccountIdOf < ThisChain < B > >
48+ where
49+ B : MessageBridge ,
50+ SignerOf < ThisChain < B > > :
51+ From < sp_core:: ed25519:: Public > + IdentifyAccount < AccountId = AccountIdOf < ThisChain < B > > > ,
52+ {
53+ let this_raw_public = PublicKey :: from ( & dispatch_account_secret ( ) ) ;
54+ let this_public: SignerOf < ThisChain < B > > =
55+ sp_core:: ed25519:: Public :: from_raw ( this_raw_public. to_bytes ( ) ) . into ( ) ;
56+ this_public. into_account ( )
57+ }
58+
59+ /// Return public key of this chain account, used to dispatch message.
60+ pub fn dispatch_account_secret ( ) -> SecretKey {
61+ // key from the repo example (https://docs.rs/ed25519-dalek/1.0.1/ed25519_dalek/struct.SecretKey.html)
62+ SecretKey :: from_bytes ( & [
63+ 157 , 097 , 177 , 157 , 239 , 253 , 090 , 096 , 186 , 132 , 074 , 244 , 146 , 236 , 044 , 196 , 068 , 073 ,
64+ 197 , 105 , 123 , 050 , 105 , 025 , 112 , 059 , 172 , 003 , 028 , 174 , 127 , 096 ,
65+ ] )
66+ . expect ( "harcoded key is valid" )
67+ }
68+
4669/// Prepare outbound message for the `send_message` call.
4770pub fn prepare_outbound_message < B > (
4871 params : MessageParams < AccountIdOf < ThisChain < B > > > ,
82105 FI : ' static ,
83106 BH : Header < Hash = HashOf < BridgedChain < B > > > ,
84107 BHH : Hasher < Out = HashOf < BridgedChain < B > > > ,
108+ AccountIdOf < ThisChain < B > > : PartialEq + sp_std:: fmt:: Debug ,
85109 AccountIdOf < BridgedChain < B > > : From < [ u8 ; 32 ] > ,
86110 BalanceOf < ThisChain < B > > : Debug + MaybeSerializeDeserialize ,
87111 CallOf < ThisChain < B > > : From < frame_system:: Call < R > > + GetDispatchInfo ,
@@ -116,6 +140,7 @@ where
116140
117141 // if dispatch fee is paid at this chain, endow relayer account
118142 if params. dispatch_fee_payment == DispatchFeePayment :: AtTargetChain {
143+ assert_eq ! ( this_public. clone( ) . into_account( ) , dispatch_account:: <B >( ) ) ;
119144 pallet_balances:: Pallet :: < R , BI > :: make_free_balance_be (
120145 & this_public. clone ( ) . into_account ( ) ,
121146 endow_amount,
@@ -298,12 +323,7 @@ fn ed25519_sign(
298323 source_chain_id : ChainId ,
299324 target_chain_id : ChainId ,
300325) -> ( [ u8 ; 32 ] , [ u8 ; 64 ] ) {
301- // key from the repo example (https://docs.rs/ed25519-dalek/1.0.1/ed25519_dalek/struct.SecretKey.html)
302- let target_secret = SecretKey :: from_bytes ( & [
303- 157 , 097 , 177 , 157 , 239 , 253 , 090 , 096 , 186 , 132 , 074 , 244 , 146 , 236 , 044 , 196 , 068 , 073 ,
304- 197 , 105 , 123 , 050 , 105 , 025 , 112 , 059 , 172 , 003 , 028 , 174 , 127 , 096 ,
305- ] )
306- . expect ( "harcoded key is valid" ) ;
326+ let target_secret = dispatch_account_secret ( ) ;
307327 let target_public: PublicKey = ( & target_secret) . into ( ) ;
308328
309329 let mut target_pair_bytes = [ 0u8 ; KEYPAIR_LENGTH ] ;
0 commit comments