@@ -4,32 +4,122 @@ const db = require('../lib/firebase');
4
4
const logger = require ( '../lib/logger' ) ;
5
5
const workspaceAuthMiddleware = require ( '../middlewares/workspaceAuth' ) ;
6
6
7
- router . get ( '/wallets ' , workspaceAuthMiddleware , async ( req , res ) => {
7
+ router . get ( '/transactions ' , workspaceAuthMiddleware , async ( req , res ) => {
8
8
const data = req . query ;
9
9
try {
10
- if ( ! data . workspace )
10
+ if ( ! data . workspace || ! data . from || ! data . to )
11
11
throw new Error ( 'Missing parameters.' ) ;
12
12
13
- const wallets = await db . getWalletVolume ( data . workspace . id ) ;
13
+ const transactions = await db . getTransactionVolume ( data . workspace . id , data . from , data . to ) ;
14
14
15
- res . status ( 200 ) . json ( wallets ) ;
15
+ res . status ( 200 ) . json ( transactions ) ;
16
16
} catch ( error ) {
17
- logger . error ( error . message , { location : 'get.api.stats.wallets ' , error : error , data : data } ) ;
17
+ logger . error ( error . message , { location : 'get.api.stats.transactions ' , error : error , data : data } ) ;
18
18
res . status ( 400 ) . send ( error . message ) ;
19
19
}
20
20
} ) ;
21
21
22
- router . get ( '/transactions ' , workspaceAuthMiddleware , async ( req , res ) => {
22
+ router . get ( '/tokenTransferVolume ' , workspaceAuthMiddleware , async ( req , res ) => {
23
23
const data = req . query ;
24
24
try {
25
- if ( ! data . workspace )
25
+ if ( ! data . workspace || ! data . from || ! data . to )
26
26
throw new Error ( 'Missing parameters.' ) ;
27
27
28
- const transactions = await db . getTransactionVolume ( data . workspace . id ) ;
28
+ const transfers = await db . getTokenTransferVolume ( data . workspace . id , data . from , data . to , data . address , data . type ) ;
29
29
30
- res . status ( 200 ) . json ( transactions ) ;
30
+ res . status ( 200 ) . json ( transfers ) ;
31
31
} catch ( error ) {
32
- logger . error ( error . message , { location : 'get.api.stats.transactions' , error : error , data : data } ) ;
32
+ logger . error ( error . message , { location : 'get.api.stats.tokenTransferVolume' , error : error , data : data } ) ;
33
+ res . status ( 400 ) . send ( error . message ) ;
34
+ }
35
+ } ) ;
36
+
37
+ router . get ( '/uniqueWalletCount' , workspaceAuthMiddleware , async ( req , res ) => {
38
+ const data = req . query ;
39
+ try {
40
+ if ( ! data . workspace || ! data . from || ! data . to )
41
+ throw new Error ( 'Missing parameters.' ) ;
42
+
43
+ const uniqueWalletCount = await db . getUniqueWalletCount ( data . workspace . id , data . from , data . to ) ;
44
+
45
+ res . status ( 200 ) . json ( uniqueWalletCount ) ;
46
+ } catch ( error ) {
47
+ logger . error ( error . message , { location : 'get.api.stats.uniqueWalletCount' , error : error , data : data } ) ;
48
+ res . status ( 400 ) . send ( error . message ) ;
49
+ }
50
+ } ) ;
51
+
52
+ router . get ( '/cumulativeWalletCount' , workspaceAuthMiddleware , async ( req , res ) => {
53
+ const data = req . query ;
54
+ try {
55
+ if ( ! data . workspace || ! data . from || ! data . to )
56
+ throw new Error ( 'Missing parameters.' ) ;
57
+
58
+ const cumulativeWalletCount = await db . getCumulativeWalletCount ( data . workspace . id , data . from , data . to ) ;
59
+
60
+ res . status ( 200 ) . json ( cumulativeWalletCount ) ;
61
+ } catch ( error ) {
62
+ logger . error ( error . message , { location : 'get.api.stats.cumulativeWalletCount' , error : error , data : data } ) ;
63
+ res . status ( 400 ) . send ( error . message ) ;
64
+ }
65
+ } ) ;
66
+
67
+ router . get ( '/deployedContractCount' , workspaceAuthMiddleware , async ( req , res ) => {
68
+ const data = req . query ;
69
+ try {
70
+ if ( ! data . workspace || ! data . from || ! data . to )
71
+ throw new Error ( 'Missing parameters.' ) ;
72
+
73
+ const deployedContractCount = await db . getDeployedContractCount ( data . workspace . id , data . from , data . to ) ;
74
+
75
+ res . status ( 200 ) . json ( deployedContractCount ) ;
76
+ } catch ( error ) {
77
+ logger . error ( error . message , { location : 'get.api.stats.deployedContractCount' , error : error , data : data } ) ;
78
+ res . status ( 400 ) . send ( error . message ) ;
79
+ }
80
+ } ) ;
81
+
82
+ router . get ( '/cumulativeDeployedContractCount' , workspaceAuthMiddleware , async ( req , res ) => {
83
+ const data = req . query ;
84
+ try {
85
+ if ( ! data . workspace || ! data . from || ! data . to )
86
+ throw new Error ( 'Missing parameters.' ) ;
87
+
88
+ const cumulativeDeployedContractCount = await db . getCumulativeDeployedContractCount ( data . workspace . id , data . from , data . to ) ;
89
+
90
+ res . status ( 200 ) . json ( cumulativeDeployedContractCount ) ;
91
+ } catch ( error ) {
92
+ logger . error ( error . message , { location : 'get.api.stats.getCumulativeDeployedContractCount' , error : error , data : data } ) ;
93
+ res . status ( 400 ) . send ( error . message ) ;
94
+ }
95
+ } ) ;
96
+
97
+ router . get ( '/averageGasPrice' , workspaceAuthMiddleware , async ( req , res ) => {
98
+ const data = req . query ;
99
+ try {
100
+ if ( ! data . workspace || ! data . from || ! data . to )
101
+ throw new Error ( 'Missing parameters.' ) ;
102
+
103
+ const avgGasPrice = await db . getAverageGasPrice ( data . workspace . id , data . from , data . to ) ;
104
+
105
+ res . status ( 200 ) . json ( avgGasPrice ) ;
106
+ } catch ( error ) {
107
+ logger . error ( error . message , { location : 'get.api.stats.averageGasPrice' , error : error , data : data } ) ;
108
+ res . status ( 400 ) . send ( error . message ) ;
109
+ }
110
+ } ) ;
111
+
112
+ router . get ( '/averageTransactionFee' , workspaceAuthMiddleware , async ( req , res ) => {
113
+ const data = req . query ;
114
+ try {
115
+ if ( ! data . workspace || ! data . from || ! data . to )
116
+ throw new Error ( 'Missing parameters.' ) ;
117
+
118
+ const avgTransactionFee = await db . getAverageTransactionFee ( data . workspace . id , data . from , data . to ) ;
119
+
120
+ res . status ( 200 ) . json ( avgTransactionFee ) ;
121
+ } catch ( error ) {
122
+ logger . error ( error . message , { location : 'get.api.stats.averageTransactionFee' , error : error , data : data } ) ;
33
123
res . status ( 400 ) . send ( error . message ) ;
34
124
}
35
125
} ) ;
@@ -41,7 +131,7 @@ router.get('/global', workspaceAuthMiddleware, async (req, res) => {
41
131
throw new Error ( 'Missing parameters.' ) ;
42
132
43
133
const ts24hago = new Date ( new Date ( ) . getTime ( ) - ( 24 * 3600 * 1000 ) ) ;
44
- const txCount24h = await db . getTxCount ( data . workspace . id , ts24hago ) ;
134
+ const txCount24h = await db . getTotalTxCount ( data . workspace . id , ts24hago ) ;
45
135
const txCountTotal = await db . getTotalTxCount ( data . workspace . id ) ;
46
136
const activeWalletCount = await db . getActiveWalletCount ( data . workspace . id ) ;
47
137
0 commit comments