JSON RPC request ID now support uint64, string and null

pull/937/head
kompotkot 2023-10-18 11:59:47 +00:00
rodzic 3bc6070768
commit 8e9023afc5
2 zmienionych plików z 30 dodań i 19 usunięć

Wyświetl plik

@ -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 {

Wyświetl plik

@ -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
}