@@ -115,7 +115,7 @@ fn main() -> Result<(), Box<dyn Error>> {
115115
116116 let sender_accounts = funder_lib:: derive_accounts ( n_tx_sender, SENDER_SEED . to_owned ( ) ) ;
117117 let receiver_accounts = funder_lib:: derive_accounts ( n_tx_sender, RECEIVER_SEED . to_owned ( ) ) ;
118-
118+
119119 async fn create_api ( node_url : String ) -> OnlineClient < PolkadotConfig > {
120120 let node_url = url:: Url :: parse ( & node_url) . unwrap ( ) ;
121121 let ( node_sender, node_receiver) =
@@ -131,61 +131,58 @@ fn main() -> Result<(), Box<dyn Error>> {
131131 OnlineClient :: from_backend ( backend) . await . unwrap ( )
132132 }
133133
134-
135- fn seed_senders ( node_url : String , sender_accounts : & [ SrPair ] ) {
134+ async fn seed_senders ( node_url : String , sender_accounts : & [ SrPair ] ) {
136135 let alice = <SrPair as Pair >:: from_string ( & ALICE_SEED , None ) . unwrap ( ) ;
137-
136+
138137 let alice_signer = PairSigner :: new ( alice. clone ( ) ) ;
139138
140139 log:: info!( "Seeding accounts" ) ;
141-
140+ let node_url = node_url. clone ( ) ;
141+ let api = create_api ( node_url. clone ( ) ) . await ;
142+ let mut best_block_stream =
143+ api. blocks ( ) . subscribe_best ( ) . await . expect ( "Subscribe to best block failed" ) ;
144+ let best_block = best_block_stream. next ( ) . await . unwrap ( ) . unwrap ( ) ;
145+ let block_ref: BlockRef < subxt:: utils:: H256 > = BlockRef :: from_hash ( best_block. hash ( ) ) ;
146+ let mut nonce = get_account_nonce ( & api, block_ref. clone ( ) , & alice) . await ;
147+ for sender in sender_accounts. iter ( ) {
148+ let payload = subxt:: dynamic:: tx (
149+ "Balances" ,
150+ "transfer_keep_alive" ,
151+ vec ! [
152+ Value :: unnamed_variant( "Id" , [ Value :: from_bytes( sender. public( ) ) ] ) ,
153+ Value :: u128 ( 100000000000000000000 ) ,
154+ ] ,
155+ ) ;
156+ let tx_params = Params :: new ( ) . nonce ( nonce as u64 ) . build ( ) ;
157+ let tx: SubmittableTransaction < _ , OnlineClient < _ > > = api
158+ . tx ( )
159+ . create_partial ( & payload, & alice_signer. account_id ( ) , tx_params)
160+ . await
161+ . unwrap ( )
162+ . sign ( & alice_signer) ;
163+ let _ = match tx. submit_and_watch ( ) . await {
164+ Ok ( watch) => {
165+ log:: info!( "Seeded account" ) ;
166+ nonce += 1 ;
167+ watch
168+ } ,
169+ Err ( err) => {
170+ log:: warn!( "{:?}" , err) ;
171+ continue ;
172+ } ,
173+ } ;
174+ }
175+ }
176+ fn seed_senders_sync ( node_url : String , sender_accounts : & [ SrPair ] ) {
142177 tokio:: runtime:: Builder :: new_multi_thread ( )
143178 . enable_all ( )
144179 . build ( )
145180 . unwrap ( )
146- . block_on ( async {
147- let node_url = node_url. clone ( ) ;
148- let api = create_api ( node_url. clone ( ) ) . await ;
149- let mut best_block_stream =
150- api. blocks ( ) . subscribe_best ( ) . await . expect ( "Subscribe to best block failed" ) ;
151- let best_block = best_block_stream. next ( ) . await . unwrap ( ) . unwrap ( ) ;
152- let block_ref: BlockRef < subxt:: utils:: H256 > =
153- BlockRef :: from_hash ( best_block. hash ( ) ) ;
154- let mut nonce = get_account_nonce ( & api, block_ref. clone ( ) , & alice) . await ;
155- for sender in sender_accounts. iter ( ) {
156- let payload = subxt:: dynamic:: tx (
157- "Balances" ,
158- "transfer_keep_alive" ,
159- vec ! [
160- Value :: unnamed_variant( "Id" , [ Value :: from_bytes( sender. public( ) ) ] ) ,
161- Value :: u128 ( 100000000000000000000 ) ,
162- ] ,
163- ) ;
164- let tx_params = Params :: new ( ) . nonce ( nonce as u64 ) . build ( ) ;
165- let tx: SubmittableTransaction < _ , OnlineClient < _ > > = api
166- . tx ( )
167- . create_partial ( & payload, & alice_signer. account_id ( ) , tx_params)
168- . await
169- . unwrap ( )
170- . sign ( & alice_signer) ;
171- let _ = match tx. submit_and_watch ( ) . await {
172- Ok ( watch) => {
173- log:: info!( "Seeded account" ) ;
174- nonce += 1 ;
175- watch
176- } ,
177- Err ( err) => {
178- log:: warn!( "{:?}" , err) ;
179- continue ;
180- } ,
181- } ;
182- }
183- } ) ;
181+ . block_on ( async { seed_senders ( node_url, sender_accounts) . await } ) ;
184182 }
185183
186-
187184 if args. seed {
188- seed_senders ( args. node_url . clone ( ) , & sender_accounts) ;
185+ seed_senders_sync ( args. node_url . clone ( ) , & sender_accounts) ;
189186 }
190187
191188 while !args. seed {
@@ -325,6 +322,8 @@ fn main() -> Result<(), Box<dyn Error>> {
325322
326323 log:: info!( "All senders started" ) ;
327324
325+ seed_senders ( args. node_url . clone ( ) , & sender_accounts) . await ;
326+
328327 let mut tps_window = VecDeque :: new ( ) ;
329328 let loop_start = Instant :: now ( ) ;
330329
0 commit comments