@@ -39,7 +39,7 @@ use messages_relay::{
39
39
message_lane_loop:: { BatchTransaction , NoncesSubmitArtifacts , TargetClient , TargetClientState } ,
40
40
} ;
41
41
use relay_substrate_client:: {
42
- AccountIdOf , AccountKeyPairOf , BalanceOf , Chain , ChainWithMessages , Client ,
42
+ AccountIdOf , AccountKeyPairOf , BalanceOf , CallOf , Chain , ChainWithMessages , Client ,
43
43
Error as SubstrateError , HashOf , HeaderIdOf , IndexOf , SignParam , TransactionEra ,
44
44
TransactionTracker , UnsignedTransaction ,
45
45
} ;
@@ -303,38 +303,86 @@ impl<P: SubstrateMessageLane>
303
303
TransactionTracker < P :: TargetChain , Client < P :: TargetChain > > ,
304
304
SubstrateError ,
305
305
> for BatchDeliveryTransaction < P >
306
+ where
307
+ AccountIdOf < P :: TargetChain > : From < <AccountKeyPairOf < P :: TargetChain > as Pair >:: Public > ,
306
308
{
307
309
fn required_header_id ( & self ) -> SourceHeaderIdOf < MessageLaneAdapter < P > > {
308
310
self . required_source_header_on_target . clone ( )
309
311
}
310
312
311
313
async fn append_proof_and_send (
312
314
self ,
313
- _proof : <MessageLaneAdapter < P > as MessageLane >:: MessagesProof ,
315
+ proof : <MessageLaneAdapter < P > as MessageLane >:: MessagesProof ,
314
316
) -> Result < TransactionTracker < P :: TargetChain , Client < P :: TargetChain > > , SubstrateError > {
315
- unimplemented ! ( "TODO" )
317
+ let mut calls = self
318
+ . messages_target
319
+ . source_to_target_headers_relay
320
+ . as_ref ( )
321
+ . expect ( "BatchDeliveryTransaction is only created when source_to_target_headers_relay is Some; qed" )
322
+ . prove_header ( self . required_source_header_on_target . 0 )
323
+ . await ?;
324
+ calls. push ( make_messages_delivery_call :: < P > (
325
+ self . messages_target . relayer_id_at_source ,
326
+ proof. 1 . nonces_start ..=proof. 1 . nonces_end ,
327
+ proof,
328
+ false ,
329
+ ) ) ;
330
+ let batch_call = P :: TargetBatchCallBuilder :: build_batch_call ( calls) ;
331
+
332
+ let ( spec_version, transaction_version) =
333
+ self . messages_target . target_client . simple_runtime_version ( ) . await ?;
334
+ self . messages_target
335
+ . target_client
336
+ . submit_and_watch_signed_extrinsic (
337
+ self . messages_target . transaction_params . signer . public ( ) . into ( ) ,
338
+ SignParam :: < P :: TargetChain > {
339
+ spec_version,
340
+ transaction_version,
341
+ genesis_hash : * self . messages_target . target_client . genesis_hash ( ) ,
342
+ signer : self . messages_target . transaction_params . signer . clone ( ) ,
343
+ } ,
344
+ move |best_block_id, transaction_nonce| {
345
+ Ok ( UnsignedTransaction :: new ( batch_call. into ( ) , transaction_nonce) . era (
346
+ TransactionEra :: new (
347
+ best_block_id,
348
+ self . messages_target . transaction_params . mortality ,
349
+ ) ,
350
+ ) )
351
+ } ,
352
+ )
353
+ . await
316
354
}
317
355
}
318
356
319
- /// Make messages delivery transaction from given proof.
320
- fn make_messages_delivery_transaction < P : SubstrateMessageLane > (
321
- target_transaction_params : & TransactionParams < AccountKeyPairOf < P :: TargetChain > > ,
322
- target_best_block_id : HeaderIdOf < P :: TargetChain > ,
323
- transaction_nonce : IndexOf < P :: TargetChain > ,
357
+ /// Make messages delivery call from given proof.
358
+ fn make_messages_delivery_call < P : SubstrateMessageLane > (
324
359
relayer_id_at_source : AccountIdOf < P :: SourceChain > ,
325
360
nonces : RangeInclusive < MessageNonce > ,
326
361
proof : SubstrateMessagesProof < P :: SourceChain > ,
327
362
trace_call : bool ,
328
- ) -> Result < UnsignedTransaction < P :: TargetChain > , SubstrateError > {
363
+ ) -> CallOf < P :: TargetChain > {
329
364
let messages_count = nonces. end ( ) - nonces. start ( ) + 1 ;
330
365
let dispatch_weight = proof. 0 ;
331
- let call = P :: ReceiveMessagesProofCallBuilder :: build_receive_messages_proof_call (
366
+ P :: ReceiveMessagesProofCallBuilder :: build_receive_messages_proof_call (
332
367
relayer_id_at_source,
333
368
proof,
334
369
messages_count as _ ,
335
370
dispatch_weight,
336
371
trace_call,
337
- ) ;
372
+ )
373
+ }
374
+
375
+ /// Make messages delivery transaction from given proof.
376
+ fn make_messages_delivery_transaction < P : SubstrateMessageLane > (
377
+ target_transaction_params : & TransactionParams < AccountKeyPairOf < P :: TargetChain > > ,
378
+ target_best_block_id : HeaderIdOf < P :: TargetChain > ,
379
+ transaction_nonce : IndexOf < P :: TargetChain > ,
380
+ relayer_id_at_source : AccountIdOf < P :: SourceChain > ,
381
+ nonces : RangeInclusive < MessageNonce > ,
382
+ proof : SubstrateMessagesProof < P :: SourceChain > ,
383
+ trace_call : bool ,
384
+ ) -> Result < UnsignedTransaction < P :: TargetChain > , SubstrateError > {
385
+ let call = make_messages_delivery_call :: < P > ( relayer_id_at_source, nonces, proof, trace_call) ;
338
386
Ok ( UnsignedTransaction :: new ( call. into ( ) , transaction_nonce)
339
387
. era ( TransactionEra :: new ( target_best_block_id, target_transaction_params. mortality ) ) )
340
388
}
0 commit comments