@@ -12,32 +12,31 @@ class Utility {
1212
1313 @checkConnection
1414 async batch < T > ( extrinsics : ExtrinsicResult < T > [ ] ) : Promise < T [ ] > {
15- extrinsics = extrinsics . filter ( Boolean ) ;
16- if ( extrinsics . length > 0 ) {
17- let result : T [ ] = [ ] ;
18- for ( let i = 0 ; i < extrinsics . length ; i += BATCH_SIZE ) {
19- const batch = extrinsics . slice ( i , i + BATCH_SIZE ) ;
20- const { resultSections, resultEvents, map } = this . extractResultSectionsAndEvents ( batch ) ;
21- const batchExtrinsic = await this . client . api . tx . utility . batch ( batch ) ;
22- const res = await this . client . applyExtrinsic < T > ( batchExtrinsic , resultSections , resultEvents , map ) ;
23- result = result . concat ( res ) ;
24- }
25-
26- return result ;
27- }
28- return [ ] ;
15+ return this . applyBatch ( extrinsics , batch => this . client . api . tx . utility . batch ( batch ) ) ;
2916 }
3017
3118 @checkConnection
3219 async batchAll < T > ( extrinsics : ExtrinsicResult < T > [ ] ) : Promise < T [ ] > {
20+ return this . applyBatch ( extrinsics , batch => this . client . api . tx . utility . batchAll ( batch ) ) ;
21+ }
22+
23+ @checkConnection
24+ async forceBatch < T > ( extrinsics : ExtrinsicResult < T > [ ] ) : Promise < T [ ] > {
25+ return this . applyBatch ( extrinsics , batch => this . client . api . tx . utility . forceBatch ( batch ) ) ;
26+ }
27+
28+ private async applyBatch < T > (
29+ extrinsics : ExtrinsicResult < T > [ ] ,
30+ buildExtrinsic : ( batch : ExtrinsicResult < T > [ ] ) => any ,
31+ ) : Promise < T [ ] > {
3332 extrinsics = extrinsics . filter ( Boolean ) ;
3433 if ( extrinsics . length > 0 ) {
3534 let result : T [ ] = [ ] ;
3635 for ( let i = 0 ; i < extrinsics . length ; i += BATCH_SIZE ) {
3736 const batch = extrinsics . slice ( i , i + BATCH_SIZE ) ;
3837 const { resultSections, resultEvents, map } = this . extractResultSectionsAndEvents ( batch ) ;
39- const batchAllExtrinsic = await this . client . api . tx . utility . batchAll ( batch ) ;
40- const res = await this . client . applyExtrinsic < T > ( batchAllExtrinsic , resultSections , resultEvents , map ) ;
38+ const extrinsic = await buildExtrinsic ( batch ) ;
39+ const res = await this . client . applyExtrinsic < T > ( extrinsic , resultSections , resultEvents , map ) ;
4140 result = result . concat ( res ) ;
4241 }
4342
0 commit comments