-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathroute.ts
More file actions
42 lines (35 loc) · 1.15 KB
/
route.ts
File metadata and controls
42 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { NextRequest, NextResponse } from 'next/server'
import { applyInterpreterServer } from '@/lib/interpreter-server'
import type { DecodedTransaction } from '@3loop/transaction-decoder'
export const runtime = 'nodejs'
export const dynamic = 'force-dynamic'
interface InterpretRequest {
decodedTx: DecodedTransaction
interpreter: {
id: string
schema: string
}
interpretAsUserAddress?: string
}
export const POST = async (request: NextRequest) => {
try {
const body: InterpretRequest = await request.json()
const { decodedTx, interpreter, interpretAsUserAddress } = body
if (!decodedTx || !interpreter) {
return NextResponse.json(
{ error: 'Missing required fields: decodedTx and interpreter are required' },
{ status: 400 },
)
}
const result = await applyInterpreterServer(decodedTx, interpreter, interpretAsUserAddress)
return NextResponse.json(result)
} catch (error) {
console.error('Interpreter API error:', error)
return NextResponse.json(
{
error: error instanceof Error ? error.message : 'Failed to interpret transaction',
},
{ status: 500 },
)
}
}