Skip to content

Commit

Permalink
adding new function to return status and information at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses committed Sep 12, 2024
1 parent 5d772f0 commit eb72eef
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/rest-api/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,72 @@ app.get('/getBridgeTxStatus', async (req, res) => {
}
})

// Get Destination Transaction Hash
app.get('/getDestinationTx', async (req, res) => {
try {
const query = req.query
const originChainId = Number(query.originChainId)
const txHash = String(query.txHash)

if (!originChainId || !txHash) {
res.status(400).send({
message: 'Invalid request: Missing required parameters',
})
return
}

try {
const graphqlEndpoint = 'https://explorer.omnirpc.io/graphql'
const graphqlQuery = `
{
bridgeTransactions(
useMv: true
chainIDFrom: ${originChainId}
txnHash: "${txHash}"
) {
toInfo {
chainID
address
txnHash
USDValue
tokenSymbol
blockNumber
formattedTime
}
}
}
`

const graphqlResponse = await fetch(graphqlEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ query: graphqlQuery }),
})

const graphqlData = await graphqlResponse.json()
const toInfo = graphqlData.data.bridgeTransactions[0]?.toInfo || null

if (toInfo === null) {
res.json({ status: 'pending' })
} else {
res.json({ status: 'completed', toInfo })
}
} catch (err) {
res.status(400).send({
message: 'Error fetching bridge transaction status',
error: err.message,
})
}
} catch (err) {
res.status(400).send({
message: 'Invalid request',
error: err.message,
})
}
})

export const server = app.listen(port, () => {
console.log(`Server listening at ${port}`)
})
Expand Down

0 comments on commit eb72eef

Please sign in to comment.