Skip to content

Commit 6bc83dc

Browse files
committed
Send v2 bundles to miners
1 parent 92edf68 commit 6bc83dc

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

server/handlers.js

+31-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,28 @@ const postgres = require('postgres')
77
const { writeError } = require('./utils')
88
const { checkBlacklist, checkDistinctAddresses, getParsedTransactions, MAX_DISTINCT_TO } = require('./bundle')
99

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+
1032
class Handler {
1133
constructor(MINERS, SIMULATION_RPC, SQS_URL, PSQL_DSN, promClient) {
1234
this.MINERS = MINERS
@@ -29,11 +51,10 @@ class Handler {
2951
return
3052
}
3153
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
3758

3859
try {
3960
const parsedTransactions = getParsedTransactions(txs)
@@ -51,7 +72,7 @@ class Handler {
5172
writeError(res, 400, 'unable to decode txs')
5273
return
5374
}
54-
const blockParam = req.body.params[1] || bundle.blockNumber
75+
const blockParam = bundle.blockNumber
5576
if (!blockParam) {
5677
writeError(res, 400, 'missing block param')
5778
return
@@ -60,18 +81,20 @@ class Handler {
6081
writeError(res, 400, 'block param must be a hex int')
6182
return
6283
}
63-
const minTimestamp = req.body.params[2] || bundle.minTimestamp
84+
const minTimestamp = bundle.minTimestamp
6485
if (minTimestamp && !(minTimestamp > 0)) {
6586
writeError(res, 400, 'minTimestamp must be an int')
6687
return
6788
}
68-
const maxTimestamp = req.body.params[3] || bundle.maxTimestamp
89+
const maxTimestamp = bundle.maxTimestamp
6990
if (maxTimestamp && !(maxTimestamp > 0)) {
7091
writeError(res, 400, 'maxTimestamp must be an int')
7192
return
7293
}
7394

7495
const requests = []
96+
97+
console.log('req.body', req.body)
7598
this.MINERS.forEach((minerUrl) => {
7699
try {
77100
requests.push(

0 commit comments

Comments
 (0)