1
1
import type { Prisma } from "@prisma/client" ;
2
2
import { PrismaTransaction } from "../../schema/prisma" ;
3
+ import { TransactionStatusEnum } from "../../server/schemas/transaction" ;
3
4
import { simulateTx } from "../../server/utils/simulateTx" ;
5
+ import { reportUsage , UsageEventTxActionEnum } from "../../utils/usage" ;
6
+ import { sendWebhooks } from "../../utils/webhook" ;
4
7
import { getPrismaWithPostgresTx } from "../client" ;
5
8
import { getWalletDetails } from "../wallets/getWalletDetails" ;
6
9
@@ -45,7 +48,7 @@ export const queueTxRaw = async ({
45
48
await simulateTx ( { txRaw : tx } ) ;
46
49
}
47
50
48
- return prisma . transactions . create ( {
51
+ const insertedData = await prisma . transactions . create ( {
49
52
data : {
50
53
...tx ,
51
54
fromAddress : tx . fromAddress ?. toLowerCase ( ) ,
@@ -55,4 +58,29 @@ export const queueTxRaw = async ({
55
58
accountAddress : tx . accountAddress ?. toLowerCase ( ) ,
56
59
} ,
57
60
} ) ;
61
+
62
+ // Send queued webhook.
63
+ sendWebhooks ( [
64
+ {
65
+ queueId : insertedData . id ,
66
+ status : TransactionStatusEnum . Queued ,
67
+ } ,
68
+ ] ) . catch ( ( err ) => { } ) ;
69
+
70
+ reportUsage ( [
71
+ {
72
+ input : {
73
+ chainId : tx . chainId || undefined ,
74
+ fromAddress : tx . fromAddress || undefined ,
75
+ toAddress : tx . toAddress || undefined ,
76
+ value : tx . value || undefined ,
77
+ transactionHash : tx . transactionHash || undefined ,
78
+ functionName : tx . functionName || undefined ,
79
+ extension : tx . extension || undefined ,
80
+ } ,
81
+ action : UsageEventTxActionEnum . QueueTx ,
82
+ } ,
83
+ ] ) ;
84
+
85
+ return insertedData ;
58
86
} ;
0 commit comments