@@ -7,6 +7,28 @@ const postgres = require('postgres')
7
7
const { writeError } = require ( './utils' )
8
8
const { checkBlacklist, checkDistinctAddresses, getParsedTransactions, MAX_DISTINCT_TO } = require ( './bundle' )
9
9
10
+ function convertBundleFormat ( bundle ) {
11
+ if ( ! Array . isArray ( bundle [ 0 ] ) ) {
12
+ // is already v2 bundle, just return
13
+ return bundle [ 0 ]
14
+ }
15
+
16
+ const newBundle = {
17
+ txs : bundle [ 0 ] ,
18
+ blockNumber : bundle [ 1 ]
19
+ }
20
+
21
+ if ( bundle [ 2 ] ) {
22
+ newBundle . minTimestamp = bundle [ 2 ]
23
+ }
24
+
25
+ if ( bundle [ 3 ] ) {
26
+ newBundle . maxTimestamp = bundle [ 3 ]
27
+ }
28
+
29
+ return newBundle
30
+ }
31
+
10
32
class Handler {
11
33
constructor ( MINERS , SIMULATION_RPC , SQS_URL , PSQL_DSN , promClient ) {
12
34
this . MINERS = MINERS
@@ -29,11 +51,10 @@ class Handler {
29
51
return
30
52
}
31
53
this . bundleCounter . inc ( )
32
- const bundle = req . body . params [ 0 ]
33
- let txs = bundle
34
- if ( ! Array . isArray ( txs ) ) {
35
- txs = bundle . txs
36
- }
54
+ const bundle = convertBundleFormat ( req . body . params )
55
+ req . body . params = [ bundle ]
56
+
57
+ const txs = bundle . txs
37
58
38
59
try {
39
60
const parsedTransactions = getParsedTransactions ( txs )
@@ -51,7 +72,7 @@ class Handler {
51
72
writeError ( res , 400 , 'unable to decode txs' )
52
73
return
53
74
}
54
- const blockParam = req . body . params [ 1 ] || bundle . blockNumber
75
+ const blockParam = bundle . blockNumber
55
76
if ( ! blockParam ) {
56
77
writeError ( res , 400 , 'missing block param' )
57
78
return
@@ -60,18 +81,20 @@ class Handler {
60
81
writeError ( res , 400 , 'block param must be a hex int' )
61
82
return
62
83
}
63
- const minTimestamp = req . body . params [ 2 ] || bundle . minTimestamp
84
+ const minTimestamp = bundle . minTimestamp
64
85
if ( minTimestamp && ! ( minTimestamp > 0 ) ) {
65
86
writeError ( res , 400 , 'minTimestamp must be an int' )
66
87
return
67
88
}
68
- const maxTimestamp = req . body . params [ 3 ] || bundle . maxTimestamp
89
+ const maxTimestamp = bundle . maxTimestamp
69
90
if ( maxTimestamp && ! ( maxTimestamp > 0 ) ) {
70
91
writeError ( res , 400 , 'maxTimestamp must be an int' )
71
92
return
72
93
}
73
94
74
95
const requests = [ ]
96
+
97
+ console . log ( 'req.body' , req . body )
75
98
this . MINERS . forEach ( ( minerUrl ) => {
76
99
try {
77
100
requests . push (
0 commit comments