From 8dd91e65d839f59b13f270f1c7e5962793e00f2f Mon Sep 17 00:00:00 2001 From: zeroXbrock <2791467+zeroXbrock@users.noreply.github.com> Date: Mon, 2 Oct 2023 17:07:55 -0700 Subject: [PATCH] auto-increment json-rpc request id --- src/client.ts | 4 +++- src/flashbots.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/client.ts b/src/client.ts index de75994..dff3ff7 100644 --- a/src/client.ts +++ b/src/client.ts @@ -32,12 +32,14 @@ import { URLSearchParams } from 'url'; const TIMEOUT_QUERY_TX_MS = 5 * 60 * 1000 export default class MevShareClient { + private requestId: number constructor( private authSigner: Wallet, private network: MevShareNetwork, ) { this.authSigner = authSigner this.network = network + this.requestId = 0 } /** Connect to Flashbots MEV-Share node on Mainnet. */ @@ -91,7 +93,7 @@ export default class MevShareClient { */ private async handleApiRequest(params: Array, method: any): Promise { try { - return this.postRpc(this.network.apiUrl, await getRpcRequest(params, method, this.authSigner)) + return this.postRpc(this.network.apiUrl, await getRpcRequest(params, method, this.requestId++, this.authSigner)) } catch (e) { if (e instanceof AxiosError) { throw new NetworkFailure(e) diff --git a/src/flashbots.ts b/src/flashbots.ts index 86e1e47..7a38410 100644 --- a/src/flashbots.ts +++ b/src/flashbots.ts @@ -14,11 +14,11 @@ export type JsonRpcData = { * @param authSigner - Wallet used to sign Flashbots auth header; for reputation * @returns Parameters of payload to send to Bundle API */ -export const getRpcRequest = async (params: any, method: string, authSigner: Wallet) => { +export const getRpcRequest = async (params: any, method: string, id: number, authSigner: Wallet) => { const body = { params, method, - id: 69, + id, jsonrpc: "2.0" } const signature = `${authSigner.address}:${await authSigner.signMessage(ethersId(JSON.stringify(body)))}`