message: indexer-service: Make paid query processing easier to read
diff: @@ -160,12 +160,8 @@ export class QueryProcessor implements QueryProcessorInterface {
  }
  }
  - private async processQueryIfReady(paymentId: string): Promise<QueryResponse> {
  - let query = this.queries.get(paymentId)!
  -
  - // The query is ready when both the query and the payment were received
  - if (query.payment !== undefined && query.query !== undefined) {
  - const processNow = async () => {
  + private async processNow(query: PendingQuery): Promise<void> {
  + let { paymentId } = query
  let { subgraphId } = query.query!
  this.logger.debug(
  @@ -188,6 +184,10 @@ export class QueryProcessor implements QueryProcessorInterface {
  // help of the payment manager)
  let attestation = hexlify(randomBytes(32))
  + this.logger.debug(
  + `Emit query result for subgraph '${subgraphId}' and payment '${paymentId}'`,
  + )
  +
  // Send the result to the client...
  query.emitter.emit('resolve', {
  status: 200,
  @@ -199,16 +199,21 @@ export class QueryProcessor implements QueryProcessorInterface {
  },
  })
  + this.logger.debug(`Unlock payment '${paymentId}'`)
  +
  // ...and unlock the payment
  - let stateChannel = this.paymentManager.stateChannelForSubgraph(subgraphId)
  - if (stateChannel !== undefined) {
  + let stateChannel = this.paymentManager.stateChannelForSubgraph(subgraphId)!
  await stateChannel.unlockPayment(query.payment!.payment, attestation)
  }
  - }
  + private async processQueryIfReady(paymentId: string): Promise<QueryResponse> {
  + let query = this.queries.get(paymentId)!
  +
  + // The query is ready when both the query and the payment were received
  + if (query.payment !== undefined && query.query !== undefined) {
  // Don't await the result of the future; the even emitter
  // will take care of resolving the future created below
  - processNow()
  + this.processNow(query)
  }
  return new Promise((resolve, reject) => {
  