-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
Create the RELAY_TX handler following the existing transaction handler pattern.
File to modify
src/libs/omniprotocol/protocol/handlers/transaction.ts
Pattern to follow
See existing handleConfirm or handleBroadcast handlers in same file.
Handler logic
interface RelayTxRequest {
transactions: ValidityData[]
}
export const handleRelayTx: OmniHandler<Buffer> = async ({ message, context }) => {
if (!message.payload || !Buffer.isBuffer(message.payload) || message.payload.length === 0) {
return encodeResponse(errorResponse(400, "Missing payload for relay_tx"))
}
try {
const request = decodeJsonRequest<RelayTxRequest>(message.payload)
if (!request.transactions || !Array.isArray(request.transactions)) {
return encodeResponse(errorResponse(400, "transactions array is required"))
}
// Import DTRManager and call receiveRelayedTransactions
const { DTRManager } = await import("../../../network/dtr/dtrmanager")
const result = await DTRManager.receiveRelayedTransactions(request.transactions)
if (result.result === 200) {
return encodeResponse(successResponse(result.response))
} else {
return encodeResponse(errorResponse(result.result, "Relay failed", result.extra))
}
} catch (error) {
return encodeResponse(errorResponse(500, "Internal error", error))
}
}Reference
- DTR branch handler in
manageNodeCall.ts:case "RELAY_TX": return await DTRManager.receiveRelayedTransactions(data as ValidityData[])
[Beads: node-wcw]
coderabbitai
Metadata
Metadata
Assignees
Labels
No labels