From 8e9023afc5afa82b9efeb0b4610d291274ec0920 Mon Sep 17 00:00:00 2001 From: kompotkot Date: Wed, 18 Oct 2023 11:59:47 +0000 Subject: [PATCH] JSON RPC request ID now support uint64, string and null --- nodebalancer/cmd/nodebalancer/blockchain.go | 37 ++++++++++----------- nodebalancer/cmd/nodebalancer/middleware.go | 12 +++++++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/nodebalancer/cmd/nodebalancer/blockchain.go b/nodebalancer/cmd/nodebalancer/blockchain.go index b0d8c57e..82598995 100644 --- a/nodebalancer/cmd/nodebalancer/blockchain.go +++ b/nodebalancer/cmd/nodebalancer/blockchain.go @@ -38,25 +38,24 @@ var ( "web3_clientVersion": true, // zksync methods - "zks_estimateFee": true, - "zks_estimateGasL1ToL2": true, - "zks_getAllAccountBalances": true, - "zks_getBlockDetails": true, - "zks_getBridgeContracts": true, - "zks_getBytecodeByHash": true, - "zks_getConfirmedTokens": true, - "zks_getL1BatchBlockRange": true, - "zks_getL1BatchDetails": true, - "zks_getL2ToL1LogProof": true, - "zks_getL2ToL1MsgProof": true, - "zks_getMainContract": true, + "zks_estimateFee": true, + "zks_estimateGasL1ToL2": true, + "zks_getAllAccountBalances": true, + "zks_getBlockDetails": true, + "zks_getBridgeContracts": true, + "zks_getBytecodeByHash": true, + "zks_getConfirmedTokens": true, + "zks_getL1BatchBlockRange": true, + "zks_getL1BatchDetails": true, + "zks_getL2ToL1LogProof": true, + "zks_getL2ToL1MsgProof": true, + "zks_getMainContract": true, "zks_getRawBlockTransactions": true, - "zks_getTestnetPaymaster": true, - "zks_getTokenPrice": true, - "zks_getTransactionDetails": true, - "zks_L1BatchNumber": true, - "zks_L1ChainId": true, - + "zks_getTestnetPaymaster": true, + "zks_getTokenPrice": true, + "zks_getTransactionDetails": true, + "zks_L1BatchNumber": true, + "zks_L1ChainId": true, } ) @@ -64,7 +63,7 @@ type JSONRPCRequest struct { Jsonrpc string `json:"jsonrpc"` Method string `json:"method"` Params []interface{} `json:"params"` - ID uint64 `json:"id"` + ID interface{} `json:"id"` // According to the JSON-RPC specification, the id can be a string, number, or null } type BlockchainConfig struct { diff --git a/nodebalancer/cmd/nodebalancer/middleware.go b/nodebalancer/cmd/nodebalancer/middleware.go index e5068909..e99ec037 100644 --- a/nodebalancer/cmd/nodebalancer/middleware.go +++ b/nodebalancer/cmd/nodebalancer/middleware.go @@ -390,6 +390,7 @@ func jsonrpcRequestParser(body []byte) ([]JSONRPCRequest, error) { var jsonrpcRequest []JSONRPCRequest firstByte := bytes.TrimLeft(body, " \t\r\n") + switch { case len(firstByte) > 0 && firstByte[0] == '[': err := json.Unmarshal(body, &jsonrpcRequest) @@ -407,6 +408,17 @@ func jsonrpcRequestParser(body []byte) ([]JSONRPCRequest, error) { return nil, fmt.Errorf("incorrect first byte in JSON RPC request") } + for _, req := range jsonrpcRequest { + switch v := req.ID.(type) { + case float64: + req.ID = uint64(v) + case string: + case nil: + default: + return nil, fmt.Errorf("unexpected type for id: %T", v) + } + } + return jsonrpcRequest, nil }