@@ -44,6 +44,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
44
44
var _bundlesToTailsMap = new Map ( )
45
45
var _proofTx = null
46
46
var _revealTx = null
47
+ var _proofTails = [ ]
48
+ var _revealTails = [ ]
47
49
var _proofTxConfirmed = false
48
50
var _revealTxConfirmed = false
49
51
var _proofAddress = ''
@@ -146,6 +148,7 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
146
148
recoveryNextBtn . loadingReset ( 'recovery_next' )
147
149
return
148
150
}
151
+ _proofTails = tails
149
152
_proofTx = [ txs . filter ( tx => tx . lastIndex === 0 ) . sort ( ( a , b ) => a . timestamp - b . timestamp ) [ 0 ] ]
150
153
_step ++
151
154
$ ( '#recovery-step-1' ) . hide ( )
@@ -205,12 +208,13 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
205
208
$ ( '#recovery-transaction-hash-clipboard' ) . html ( UI . formatForClipboard ( tx [ 0 ] . hash ) )
206
209
_bundlesToTailsMap . set ( tx [ 0 ] . bundle , tx [ 0 ] )
207
210
_step ++
211
+ _proofTx = tx
208
212
checkInclusionStates ( tx , CONFIRMATION_CHECK_TIMEOUT , false , ( err , confirmed , tails ) => {
209
213
if ( err ) {
210
214
UI . formError ( 'recover' , err . message , { initial : 'recovery_next' } )
211
215
return
212
216
}
213
- _proofTx = tx
217
+ _proofTails = tails
214
218
if ( confirmed ) {
215
219
_proofTxConfirmed = true
216
220
UI . formSuccess ( 'recover' , 'recovery_proof_transaction_confirmed' )
@@ -266,12 +270,6 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
266
270
e . preventDefault ( )
267
271
e . stopPropagation ( )
268
272
} )
269
- if ( ! _proofTx ) {
270
- UI . formError ( 'recover' , 'reattach_not_required' , { initial : 'reattach' } )
271
- reattachBtn . loadingReset ( 'reattach' )
272
- $ ( '.remodal-close' ) . off ( 'click' )
273
- return
274
- }
275
273
reattach ( _proofTx [ 0 ] . hash ) . then ( res => {
276
274
reattachBtn . loadingReset ( 'reattach' )
277
275
UI . formSuccess ( 'recover' , 'reattach_completed' , { initial : 'reattach' } )
@@ -294,14 +292,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
294
292
e . preventDefault ( )
295
293
e . stopPropagation ( )
296
294
} )
297
- if ( ! _proofTx ) {
298
- UI . formError ( 'recover' , 'promote_not_required' , { initial : 'promote' } )
299
- promoteBtn . loadingReset ( 'promote' )
300
- $ ( '.remodal-close' ) . off ( 'click' )
301
- return
302
- }
303
295
const tail = _bundlesToTailsMap . get ( _proofTx [ 0 ] . bundle ) || _proofTx [ 0 ]
304
- promote ( tail , _bundlesToTailsMap , 5 , 1 , ( err , res ) => {
296
+ promote ( tail , _proofTails , _bundlesToTailsMap , 5 , 1 , ( err , res ) => {
305
297
if ( err ) {
306
298
if ( err . message . indexOf ( 'Inconsistent subtangle' ) > - 1 ) {
307
299
UI . formError ( 'recover' , 'promote_inconsistent_subtangle_error' )
@@ -325,14 +317,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
325
317
e . preventDefault ( )
326
318
e . stopPropagation ( )
327
319
} )
328
- if ( ! _revealTx ) {
329
- UI . formError ( 'recover' , 'promote_not_required' , { initial : 'promote' } )
330
- recoverySubmitSeedPromoteBtn . loadingReset ( 'promote' )
331
- $ ( '.remodal-close' ) . off ( 'click' )
332
- return
333
- }
334
320
const tail = _bundlesToTailsMap . get ( _revealTx [ 0 ] . bundle ) || _revealTx [ 0 ]
335
- promote ( tail , _bundlesToTailsMap , 5 , 1 , ( err , res ) => {
321
+ promote ( tail , _revealTails , _bundlesToTailsMap , 5 , 1 , ( err , res ) => {
336
322
if ( err ) {
337
323
if ( err . message . indexOf ( 'Inconsistent subtangle' ) > - 1 ) {
338
324
UI . formError ( 'recover' , 'promote_inconsistent_subtangle_error' )
@@ -357,12 +343,6 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
357
343
e . preventDefault ( )
358
344
e . stopPropagation ( )
359
345
} )
360
- if ( ! _revealTx ) {
361
- UI . formError ( 'recover' , 'reattach_not_required' , { initial : 'reattach' } )
362
- recoverySubmitSeedReattachBtn . loadingReset ( 'reattach' )
363
- $ ( '.remodal-close' ) . off ( 'click' )
364
- return
365
- }
366
346
reattach ( _revealTx [ 0 ] . hash ) . then ( res => {
367
347
recoverySubmitSeedReattachBtn . loadingReset ( 'reattach' )
368
348
_pauseConfCheck = false
@@ -415,12 +395,13 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
415
395
$ ( '#recovery-proof-confirmed-status' ) . hide ( )
416
396
$ ( '#recovery-reveal-confirmed-status' ) . fadeIn ( )
417
397
$ ( '#recovery-transaction-hash-clipboard' ) . html ( UI . formatForClipboard ( txs [ 0 ] . hash ) )
398
+ _revealTx = txs
418
399
checkInclusionStates ( txs , CONFIRMATION_CHECK_TIMEOUT , false , ( err , confirmed , tails ) => {
419
400
if ( err ) {
420
401
UI . formError ( 'recover' , err . message , { initial : 'recovery_next' } )
421
402
return
422
403
}
423
- _revealTx = txs
404
+ _revealTails = tails
424
405
if ( confirmed ) {
425
406
UI . formSuccess ( 'recover' , 'recovery_completed' , { initial : 'recovery_submit_seed' } )
426
407
$ ( '.remodal-close' ) . off ( 'click' )
@@ -493,6 +474,8 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
493
474
_bundlesToTailsMap = new Map ( )
494
475
_proofTx = null
495
476
_revealTx = null
477
+ _proofTails = [ ]
478
+ _revealTails = [ ]
496
479
_proofTxConfirmed = false
497
480
_revealTxConfirmed = false
498
481
_proofAddress = ''
@@ -590,27 +573,40 @@ WHGl/N/YlZ/p38kb7ZXtuRca7VUPxRzqv3FrUBg
590
573
)
591
574
}
592
575
593
- function promote ( tail , bundlesToTailsMap , count , i , cb ) {
594
- iota . api . promoteTransaction (
595
- tail . hash ,
596
- connection . depth ,
597
- connection . minWeightMagnitude ,
598
- [ { address : '9' . repeat ( 81 ) , value : 0 , message : '' , tag : '' } ] ,
599
- { interrupt : false , delay : 0 } ,
600
- ( err , res ) => {
601
- if ( err ) {
602
- if ( err . message . indexOf ( 'Inconsistent subtangle' ) > - 1 ) {
603
- bundlesToTailsMap . delete ( tail . bundle )
576
+ function promote ( tail , tails , bundlesToTailsMap , count , i , cb ) {
577
+ if ( ! tails || ! tails . length ) {
578
+ tails = [ tail ]
579
+ }
580
+ iota . api . getLatestInclusion ( tails . map ( tx => tx . hash ) , ( err , states ) => {
581
+ if ( err ) {
582
+ return cb ( err )
583
+ }
584
+
585
+ if ( states . some ( state => state ) ) {
586
+ return cb ( null , true )
587
+ }
588
+
589
+ iota . api . promoteTransaction (
590
+ tail . hash ,
591
+ connection . depth ,
592
+ connection . minWeightMagnitude ,
593
+ [ { address : '9' . repeat ( 81 ) , value : 0 , message : '' , tag : '' } ] ,
594
+ { interrupt : false , delay : 0 } ,
595
+ ( err , res ) => {
596
+ if ( err ) {
597
+ if ( err . message . indexOf ( 'Inconsistent subtangle' ) > - 1 ) {
598
+ bundlesToTailsMap . delete ( tail . bundle )
599
+ }
600
+ return cb ( err )
601
+ }
602
+ if ( i < count ) {
603
+ setTimeout ( ( ) => promote ( tail , tails , bundlesToTailsMap , count , ++ i , cb ) , 1000 )
604
+ } else {
605
+ cb ( null , res )
604
606
}
605
- return cb ( err )
606
- }
607
- if ( i < count ) {
608
- setTimeout ( ( ) => promote ( tail , bundlesToTailsMap , count , ++ i , cb ) )
609
- } else {
610
- cb ( null , res )
611
607
}
612
- }
613
- )
608
+ )
609
+ } )
614
610
}
615
611
616
612
function generateProofBundle ( address , pepperAndProof , tag ) {
0 commit comments