-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Paro/rfq indexer updates suggs #3243
Changes from all commits
1a06439
b40bc84
7dae54e
a5c04eb
61eaef5
fec7090
22a5008
560bae9
13c30aa
35dfa81
dd9d3a8
9fe08f8
27b6d78
df0e800
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Request, Response } from 'express' | ||
|
||
import { db } from '../db' | ||
import { qDisputes } from '../queries' | ||
import { nest_results } from '../utils/nestResults' | ||
|
||
export const disputesController = async (req: Request, res: Response) => { | ||
try { | ||
const query = db | ||
.with('disputes', () => qDisputes({activeOnly: true})) | ||
.selectFrom('disputes') | ||
.selectAll() | ||
.orderBy('blockTimestamp_dispute', 'desc') | ||
|
||
const results = await query.execute() | ||
const disputes = nest_results(results) | ||
|
||
if (disputes && disputes.length > 0) { | ||
res.json(disputes) | ||
} else { | ||
res.status(200).json({ message: 'No active disputes found' }) | ||
} | ||
} catch (error) { | ||
console.error('Error fetching active disputes:', error) | ||
res.status(500).json({ message: 'Internal server error' }) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { Request, Response } from 'express' | ||
|
||
import { db } from '../db' | ||
import { qDeposits, qRelays, qProofs, qClaims, qRefunds } from '../queries' | ||
import { | ||
qDeposits, | ||
qRelays, | ||
qProofs, | ||
qClaims, | ||
qRefunds, | ||
qDisputes, | ||
} from '../queries' | ||
import { nest_results } from '../utils/nestResults' | ||
|
||
const sevenDaysAgo = Math.floor(Date.now() / 1000) - 7 * 24 * 60 * 60 | ||
|
||
export const pendingTransactionsMissingClaimController = async ( | ||
req: Request, | ||
res: Response | ||
|
@@ -12,7 +21,7 @@ export const pendingTransactionsMissingClaimController = async ( | |
const query = db | ||
.with('deposits', () => qDeposits()) | ||
.with('relays', () => qRelays()) | ||
.with('proofs', () => qProofs()) | ||
.with('proofs', () => qProofs({activeOnly: true})) | ||
.with('claims', () => qClaims()) | ||
.with('combined', (qb) => | ||
qb | ||
|
@@ -45,7 +54,6 @@ export const pendingTransactionsMissingClaimController = async ( | |
} | ||
} | ||
|
||
|
||
export const pendingTransactionsMissingProofController = async ( | ||
req: Request, | ||
res: Response | ||
|
@@ -54,7 +62,7 @@ export const pendingTransactionsMissingProofController = async ( | |
const query = db | ||
.with('deposits', () => qDeposits()) | ||
.with('relays', () => qRelays()) | ||
.with('proofs', () => qProofs()) | ||
.with('proofs', () => qProofs({activeOnly: true})) | ||
.with('combined', (qb) => | ||
qb | ||
.selectFrom('deposits') | ||
|
@@ -111,6 +119,52 @@ export const pendingTransactionsMissingRelayController = async ( | |
.selectFrom('combined') | ||
.selectAll() | ||
.orderBy('blockTimestamp_deposit', 'desc') | ||
.where('blockTimestamp_deposit', '>', sevenDaysAgo) | ||
|
||
const results = await query.execute() | ||
const nestedResults = nest_results(results) | ||
|
||
if (nestedResults && nestedResults.length > 0) { | ||
res.json(nestedResults) | ||
} else { | ||
res | ||
.status(404) | ||
.json({ message: 'No pending transactions missing relay found' }) | ||
} | ||
} catch (error) { | ||
console.error('Error fetching pending transactions missing relay:', error) | ||
res.status(500).json({ message: 'Internal server error' }) | ||
} | ||
} | ||
Comment on lines
+122
to
+138
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Refactor controllers to eliminate code duplication The controllers Here's how you might refactor the code:
const getPendingTransactionsMissingRelay = async (
timeOperator: '>' | '<=',
timestamp: number
) => {
return await db
.with('deposits', () => qDeposits())
.with('relays', () => qRelays())
.with('refunds', () => qRefunds())
.with(
'combined',
(qb) =>
qb
.selectFrom('deposits')
.selectAll('deposits')
.leftJoin('relays', 'transactionId_deposit', 'transactionId_relay')
.leftJoin('refunds', 'transactionId_deposit', 'transactionId_refund')
.where('transactionId_relay', 'is', null) // not relayed
.where('transactionId_refund', 'is', null) // not refunded
)
.selectFrom('combined')
.selectAll()
.orderBy('blockTimestamp_deposit', 'desc')
.where('blockTimestamp_deposit', timeOperator, timestamp)
.execute()
}
export const pendingTransactionsMissingRelayController = async (
req: Request,
res: Response
) => {
try {
const results = await getPendingTransactionsMissingRelay('>', sevenDaysAgo)
const nestedResults = nest_results(results)
if (nestedResults && nestedResults.length > 0) {
res.json(nestedResults)
} else {
res
.status(404)
.json({ message: 'No pending transactions missing relay found' })
}
} catch (error) {
console.error('Error fetching pending transactions missing relay:', error)
res.status(500).json({ message: 'Internal server error' })
}
}
export const pendingTransactionsMissingRelayExceedDeadlineController = async (
req: Request,
res: Response
) => {
try {
const results = await getPendingTransactionsMissingRelay('<=', sevenDaysAgo)
const nestedResults = nest_results(results)
if (nestedResults && nestedResults.length > 0) {
res.json(nestedResults)
} else {
res
.status(404)
.json({
message:
'No pending transactions missing relay exceeding deadline found',
})
}
} catch (error) {
console.error(
'Error fetching pending transactions exceeding relay deadline:',
error
)
res.status(500).json({ message: 'Internal server error' })
}
} This refactoring enhances maintainability by centralizing shared logic. Also applies to: 140-167 |
||
|
||
export const pendingTransactionsMissingRelayExceedDeadlineController = async ( | ||
req: Request, | ||
res: Response | ||
) => { | ||
try { | ||
const query = db | ||
.with('deposits', () => qDeposits()) | ||
.with('relays', () => qRelays()) | ||
.with('refunds', () => qRefunds()) | ||
.with( | ||
'combined', | ||
(qb) => | ||
qb | ||
.selectFrom('deposits') | ||
.selectAll('deposits') | ||
.leftJoin('relays', 'transactionId_deposit', 'transactionId_relay') | ||
.leftJoin( | ||
'refunds', | ||
'transactionId_deposit', | ||
'transactionId_refund' | ||
) | ||
.where('transactionId_relay', 'is', null) // is not relayed | ||
.where('transactionId_refund', 'is', null) // is not refunded | ||
) | ||
.selectFrom('combined') | ||
.selectAll() | ||
.orderBy('blockTimestamp_deposit', 'desc') | ||
.where('blockTimestamp_deposit', '<=', sevenDaysAgo) | ||
|
||
const results = await query.execute() | ||
const nestedResults = nest_results(results) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update error messages to reflect the correct controller context
In the
pendingTransactionsMissingRelayExceedDeadlineController
, both the console error message and the 404 response message are the same as those inpendingTransactionsMissingRelayController
. This could cause confusion during debugging or when clients receive responses.Update the error messages to accurately reflect the context of the new controller.
Apply this diff to correct the error messages:
Also applies to: 165-167