@@ -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,9 @@ 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
+
56
+ const txs = bundle . txs
37
57
38
58
try {
39
59
const parsedTransactions = getParsedTransactions ( txs )
@@ -51,7 +71,7 @@ class Handler {
51
71
writeError ( res , 400 , 'unable to decode txs' )
52
72
return
53
73
}
54
- const blockParam = req . body . params [ 1 ] || bundle . blockNumber
74
+ const blockParam = bundle . blockNumber
55
75
if ( ! blockParam ) {
56
76
writeError ( res , 400 , 'missing block param' )
57
77
return
@@ -60,12 +80,12 @@ class Handler {
60
80
writeError ( res , 400 , 'block param must be a hex int' )
61
81
return
62
82
}
63
- const minTimestamp = req . body . params [ 2 ] || bundle . minTimestamp
83
+ const minTimestamp = bundle . minTimestamp
64
84
if ( minTimestamp && ! ( minTimestamp > 0 ) ) {
65
85
writeError ( res , 400 , 'minTimestamp must be an int' )
66
86
return
67
87
}
68
- const maxTimestamp = req . body . params [ 3 ] || bundle . maxTimestamp
88
+ const maxTimestamp = bundle . maxTimestamp
69
89
if ( maxTimestamp && ! ( maxTimestamp > 0 ) ) {
70
90
writeError ( res , 400 , 'maxTimestamp must be an int' )
71
91
return
0 commit comments