@@ -78,6 +78,14 @@ export const GET_ROUTES = asyncHandler(async (_req, res) => {
78
78
r . push ( routes . contractInstance + "NOT FOUND" ) ;
79
79
}
80
80
81
+ const statsRoutes = [
82
+ routes . statsTotalTxEffects ,
83
+ routes . statsTotalTxEffectsLast24h ,
84
+ routes . statsTotalContracts ,
85
+ routes . statsAverageFees ,
86
+ routes . statsAverageBlockTime ,
87
+ ] ;
88
+
81
89
const html = `
82
90
<html>
83
91
<head>
@@ -87,6 +95,9 @@ export const GET_ROUTES = asyncHandler(async (_req, res) => {
87
95
<ul>
88
96
${ r . map ( ( route ) => `<li><a href=${ SUB_PATH + route } >${ route } </a></li>` ) . join ( "" ) }
89
97
</ul>
98
+ <br>
99
+ <ul>
100
+ ${ statsRoutes . map ( ( route ) => `<li><a href=${ SUB_PATH + route } >${ route } </a></li>` ) . join ( "" ) }
90
101
</body>
91
102
</html>
92
103
` ;
@@ -175,3 +186,33 @@ export const GET_L2_CONTRACT_INSTANCES_BY_BLOCK_HASH = asyncHandler(
175
186
res . status ( 200 ) . send ( JSON . stringify ( instances ) ) ;
176
187
}
177
188
) ;
189
+
190
+ export const GET_STATS_TOTAL_TX_EFFECTS = asyncHandler ( async ( _req , res ) => {
191
+ const total = await db . l2TxEffect . getTotalTxEffects ( ) ;
192
+ if ( ! total ) throw new Error ( "Total tx effects not found" ) ;
193
+ res . status ( 200 ) . send ( JSON . stringify ( total ) ) ;
194
+ } ) ;
195
+
196
+ export const GET_STATS_TOTAL_TX_EFFECTS_LAST_24H = asyncHandler ( ( _req , res ) => {
197
+ const txEffects = db . l2TxEffect . getTotalTxEffectsLast24h ( ) ;
198
+ if ( ! txEffects ) throw new Error ( "Tx effects not found" ) ;
199
+ res . status ( 200 ) . send ( JSON . stringify ( txEffects ) ) ;
200
+ } ) ;
201
+
202
+ export const GET_STATS_TOTAL_CONTRACTS = asyncHandler ( async ( _req , res ) => {
203
+ const total = await db . l2Contract . getTotalContracts ( ) ;
204
+ if ( ! total ) throw new Error ( "Total contracts not found" ) ;
205
+ res . status ( 200 ) . send ( JSON . stringify ( total ) ) ;
206
+ } ) ;
207
+
208
+ export const GET_STATS_AVERAGE_FEES = asyncHandler ( async ( _req , res ) => {
209
+ const average = await db . l2Block . getAverageFees ( ) ;
210
+ if ( ! average ) throw new Error ( "Average fees not found" ) ;
211
+ res . status ( 200 ) . send ( JSON . stringify ( average ) ) ;
212
+ } ) ;
213
+
214
+ export const GET_STATS_AVERAGE_BLOCK_TIME = asyncHandler ( async ( _req , res ) => {
215
+ const average = await db . l2Block . getAverageBlockTime ( ) ;
216
+ if ( ! average ) throw new Error ( "Average block time not found" ) ;
217
+ res . status ( 200 ) . send ( JSON . stringify ( average ) ) ;
218
+ } ) ;
0 commit comments