Skip to content

Commit

Permalink
Merge pull request #937 from moonstream-to/nb-metamask-support
Browse files Browse the repository at this point in the history
Nb metamask support and small fixes
  • Loading branch information
kompotkot authored Oct 23, 2023
2 parents 6949a4d + 1439fb1 commit 78ea9b8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 19 deletions.
37 changes: 18 additions & 19 deletions nodebalancer/cmd/nodebalancer/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,33 +38,32 @@ 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,
}
)

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 {
Expand Down
12 changes: 12 additions & 0 deletions nodebalancer/cmd/nodebalancer/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}

Expand Down
5 changes: 5 additions & 0 deletions nodebalancer/cmd/nodebalancer/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ func Server() {
r.URL.RawQuery = ""
r.Header.Del(strings.Title(NB_ACCESS_ID_HEADER))
r.Header.Del(strings.Title(NB_DATA_SOURCE_HEADER))

r.URL.Scheme = endpoint.Scheme
r.URL.Host = endpoint.Host
r.URL.Path = endpoint.Path

// Change r.Host from nodebalancer's to end host so TLS check will be passed
r.Host = r.URL.Host
}
Expand Down

0 comments on commit 78ea9b8

Please sign in to comment.