@@ -336,22 +336,31 @@ pub fn accept_trades_interactive(wallet: &Wallet) -> Result<(), Box<std::error::
336336 hex:: encode ( & trade. tx_id . iter ( ) . cloned ( ) . rev ( ) . collect :: < Vec < _ > > ( ) )
337337 } ) . collect :: < Vec < _ > > ( ) ;
338338
339- let trades_validity: Vec < SlpTxValidity > = reqwest:: Client :: new ( )
340- . post ( "https://rest.bitcoin.com/v2/slp/validateTxid" )
341- . json ( & vec ! [ ( "txids" , tx_hashes) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
342- . send ( ) ?
343- . json ( ) ?;
339+ let trades_validity = tx_hashes. chunks ( 20 ) . flat_map ( |chunk| {
340+ reqwest:: Client :: new ( )
341+ . post ( "https://rest.bitcoin.com/v2/slp/validateTxid" )
342+ . json ( & vec ! [ ( "txids" , chunk) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
343+ . send ( ) . unwrap ( )
344+ . json :: < Vec < SlpTxValidity > > ( ) . unwrap ( )
345+ } ) . collect :: < Vec < _ > > ( ) ;
344346
345347 let valid_txs = trades_validity. into_iter ( )
346348 . filter ( |validity| validity. valid )
347349 . map ( |validity| validity. txid )
348350 . collect :: < HashSet < _ > > ( ) ;
349351
350- let tx_details: Vec < TxDetails > = reqwest:: Client :: new ( )
351- . post ( "https://rest.bitcoin.com/v2/transaction/details" )
352- . json ( & vec ! [ ( "txids" , & valid_txs) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
353- . send ( ) ?
354- . json ( ) ?;
352+ let tx_details = valid_txs
353+ . iter ( )
354+ . collect :: < Vec < _ > > ( )
355+ . chunks ( 20 )
356+ . flat_map ( |chunk| {
357+ reqwest:: Client :: new ( )
358+ . post ( "https://rest.bitcoin.com/v2/transaction/details" )
359+ . json ( & vec ! [ ( "txids" , chunk) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
360+ . send ( ) . unwrap ( )
361+ . json :: < Vec < TxDetails > > ( ) . unwrap ( )
362+ } )
363+ . collect :: < Vec < _ > > ( ) ;
355364
356365 let token_ids = tx_details. into_iter ( ) . filter_map ( |tx| {
357366 let mut p2sh_amount = None ;
@@ -388,16 +397,23 @@ pub fn accept_trades_interactive(wallet: &Wallet) -> Result<(), Box<std::error::
388397 Some ( ( tx_id?, ( token_id?, p2sh_amount?) ) )
389398 } ) . collect :: < HashMap < _ , _ > > ( ) ;
390399
391- let token_details = reqwest:: Client :: new ( )
392- . post ( "https://rest.bitcoin.com/v2/slp/list" )
393- . json ( & vec ! [ (
394- "tokenIds" ,
395- token_ids. values( ) . map( |( x, _) | x. clone( ) ) . collect:: <HashSet <_>>( ) ,
396- ) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
397- . send ( ) ?
398- . json :: < Vec < TokenEntry > > ( ) ?
400+ let token_id_set = token_ids. values ( ) . map ( |( x, _) | x) . collect :: < HashSet < _ > > ( ) ;
401+ let token_details = token_id_set
399402 . into_iter ( )
400- . map ( |token_details| ( token_details. id . clone ( ) , token_details) )
403+ . collect :: < Vec < _ > > ( )
404+ . chunks ( 20 )
405+ . flat_map ( |chunk| {
406+ reqwest:: Client :: new ( )
407+ . post ( "https://rest.bitcoin.com/v2/slp/list" )
408+ . json ( & vec ! [ (
409+ "tokenIds" ,
410+ chunk,
411+ ) ] . into_iter ( ) . collect :: < HashMap < _ , _ > > ( ) )
412+ . send ( ) . unwrap ( )
413+ . json :: < Vec < TokenEntry > > ( ) . unwrap ( )
414+ . into_iter ( )
415+ . map ( |token_details| ( token_details. id . clone ( ) , token_details) )
416+ } )
401417 . collect :: < HashMap < _ , _ > > ( ) ;
402418
403419 let valid_trades = trades. into_iter ( )
0 commit comments