synapsecns/sanguine

View on GitHub
packages/rest-api/src/controllers/synapseTxIdController.ts

Summary

Maintainability
B
4 hrs
Test Coverage
import { validationResult } from 'express-validator'

import { Synapse } from '../services/synapseService'
import { logger } from '../middleware/logger'

export const synapseTxIdController = async (req, res) => {
  const errors = validationResult(req)
  if (!errors.isEmpty()) {
    return res.status(400).json({ errors: errors.array() })
  }

  try {
    const { originChainId, bridgeModule, txHash } = req.query

    const synapseTxId = await Synapse.getSynapseTxId(
      Number(originChainId),
      bridgeModule,
      txHash
    )

    const payload = {
      synapseTxId,
    }

    logger.info(`Successful synapseTxIdController response`, {
      query: req.query,
      payload,
    })
    res.json(payload)
  } catch (err) {
    logger.error(`Error in synapseTxIdController`, {
      query: req.query,
      error: err.message,
      stack: err.stack,
    })
    res.status(500).json({
      error:
        'An unexpected error occurred in /synapseTxId. Please try again later.',
    })
  }
}