Liquid unblinding: Replacing async/await with observable.
This commit is contained in:
		
							parent
							
								
									7fe9993f91
								
							
						
					
					
						commit
						f5bc9ced0a
					
				@ -58,7 +58,7 @@ export class LiquidUnblinding {
 | 
				
			|||||||
  // Lookup all transaction inputs/outputs and attach the unblinded data
 | 
					  // Lookup all transaction inputs/outputs and attach the unblinded data
 | 
				
			||||||
  tryUnblindTx(tx: Transaction) {
 | 
					  tryUnblindTx(tx: Transaction) {
 | 
				
			||||||
    if (tx) {
 | 
					    if (tx) {
 | 
				
			||||||
      if (tx._unblinded) { return tx._unblinded; }
 | 
					      if (tx._unblinded) { return tx; }
 | 
				
			||||||
      let matched = 0;
 | 
					      let matched = 0;
 | 
				
			||||||
      if (tx.vout !== undefined) {
 | 
					      if (tx.vout !== undefined) {
 | 
				
			||||||
        tx.vout.forEach(vout => matched += +this.tryUnblindOut(vout));
 | 
					        tx.vout.forEach(vout => matched += +this.tryUnblindOut(vout));
 | 
				
			||||||
@ -71,7 +71,7 @@ export class LiquidUnblinding {
 | 
				
			|||||||
          throw new Error(`Invalid blinding data.`)
 | 
					          throw new Error(`Invalid blinding data.`)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        tx._deduced = false; // invalidate cache so deduction is attempted again
 | 
					        tx._deduced = false; // invalidate cache so deduction is attempted again
 | 
				
			||||||
        return tx._unblinded;
 | 
					        return tx;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -131,8 +131,9 @@ export class LiquidUnblinding {
 | 
				
			|||||||
      const blinders = this.parseBlinders(windowLocationHash);
 | 
					      const blinders = this.parseBlinders(windowLocationHash);
 | 
				
			||||||
      if (blinders) {
 | 
					      if (blinders) {
 | 
				
			||||||
        this.commitments = await this.makeCommitmentMap(blinders);
 | 
					        this.commitments = await this.makeCommitmentMap(blinders);
 | 
				
			||||||
        this.tryUnblindTx(tx);
 | 
					        return this.tryUnblindTx(tx);
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    throw new Error('Invalid blinding data.');
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -10,7 +10,7 @@ import {
 | 
				
			|||||||
  map
 | 
					  map
 | 
				
			||||||
} from 'rxjs/operators';
 | 
					} from 'rxjs/operators';
 | 
				
			||||||
import { Transaction, Block } from '../../interfaces/electrs.interface';
 | 
					import { Transaction, Block } from '../../interfaces/electrs.interface';
 | 
				
			||||||
import { of, merge, Subscription, Observable, Subject, timer, combineLatest,  } from 'rxjs';
 | 
					import { of, merge, Subscription, Observable, Subject, timer, combineLatest, from } from 'rxjs';
 | 
				
			||||||
import { StateService } from '../../services/state.service';
 | 
					import { StateService } from '../../services/state.service';
 | 
				
			||||||
import { WebsocketService } from '../../services/websocket.service';
 | 
					import { WebsocketService } from '../../services/websocket.service';
 | 
				
			||||||
import { AudioService } from 'src/app/services/audio.service';
 | 
					import { AudioService } from 'src/app/services/audio.service';
 | 
				
			||||||
@ -154,21 +154,25 @@ export class TransactionComponent implements OnInit, OnDestroy {
 | 
				
			|||||||
            transactionObservable$,
 | 
					            transactionObservable$,
 | 
				
			||||||
            this.stateService.mempoolTransactions$
 | 
					            this.stateService.mempoolTransactions$
 | 
				
			||||||
          );
 | 
					          );
 | 
				
			||||||
 | 
					        }),
 | 
				
			||||||
 | 
					        switchMap((tx) => {
 | 
				
			||||||
 | 
					          if (this.network === 'liquid') {
 | 
				
			||||||
 | 
					            return from(this.liquidUnblinding.checkUnblindedTx(tx))
 | 
				
			||||||
 | 
					              .pipe(
 | 
				
			||||||
 | 
					                catchError((error) => {
 | 
				
			||||||
 | 
					                  this.errorUnblinded = error;
 | 
				
			||||||
 | 
					                  return of(tx);
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					              )
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
 | 
					          return of(tx);
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
      )
 | 
					      )
 | 
				
			||||||
      .subscribe(async (tx: Transaction) => {
 | 
					      .subscribe((tx: Transaction) => {
 | 
				
			||||||
          if (!tx) {
 | 
					          if (!tx) {
 | 
				
			||||||
            return;
 | 
					            return;
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
           if (this.network === 'liquid') {
 | 
					 | 
				
			||||||
             try {
 | 
					 | 
				
			||||||
               await this.liquidUnblinding.checkUnblindedTx(tx)
 | 
					 | 
				
			||||||
             } catch (error) {
 | 
					 | 
				
			||||||
               this.errorUnblinded = error;
 | 
					 | 
				
			||||||
             }
 | 
					 | 
				
			||||||
          }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
          this.tx = tx;
 | 
					          this.tx = tx;
 | 
				
			||||||
          if (tx.fee === undefined) {
 | 
					          if (tx.fee === undefined) {
 | 
				
			||||||
            this.tx.fee = 0;
 | 
					            this.tx.fee = 0;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user