Commit 18abe83b authored by inphi's avatar inphi

casing

parent f7b98838
...@@ -3,7 +3,6 @@ package proxyd ...@@ -3,7 +3,6 @@ package proxyd
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"strings"
"github.com/golang/snappy" "github.com/golang/snappy"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
...@@ -17,10 +16,10 @@ type Cache interface { ...@@ -17,10 +16,10 @@ type Cache interface {
const memoryCacheLimit = 1024 * 1024 const memoryCacheLimit = 1024 * 1024
var supportedRPCMethods = map[string]bool{ var supportedRPCMethods = map[string]bool{
"eth_chainid": true, "eth_chainId": true,
"net_version": true, "net_version": true,
"eth_getblockbynumber": true, "eth_getBlockByNumber": true,
"eth_getblockrange": true, "eth_getBlockRange": true,
} }
type cache struct { type cache struct {
...@@ -92,8 +91,7 @@ func (c *RPCCache) PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error { ...@@ -92,8 +91,7 @@ func (c *RPCCache) PutRPC(ctx context.Context, req *RPCReq, res *RPCRes) error {
} }
func (c *RPCCache) isCacheable(req *RPCReq) bool { func (c *RPCCache) isCacheable(req *RPCReq) bool {
method := strings.ToLower(req.Method) if !supportedRPCMethods[req.Method] {
if !supportedRPCMethods[method] {
return false return false
} }
...@@ -102,8 +100,8 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool { ...@@ -102,8 +100,8 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool {
return false return false
} }
switch method { switch req.Method {
case "eth_getblockbynumber": case "eth_getBlockByNumber":
if len(params) != 2 { if len(params) != 2 {
return false return false
} }
...@@ -111,11 +109,11 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool { ...@@ -111,11 +109,11 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool {
if !ok { if !ok {
return false return false
} }
if isDefaultBlockParam(blockNum) { if isBlockDependentParam(blockNum) {
return false return false
} }
case "eth_getblockrange": case "eth_getBlockRange":
if len(params) != 3 { if len(params) != 3 {
return false return false
} }
...@@ -127,7 +125,7 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool { ...@@ -127,7 +125,7 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool {
if !ok { if !ok {
return false return false
} }
if isDefaultBlockParam(startBlockNum) || isDefaultBlockParam(endBlockNum) { if isBlockDependentParam(startBlockNum) || isBlockDependentParam(endBlockNum) {
return false return false
} }
} }
...@@ -135,6 +133,6 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool { ...@@ -135,6 +133,6 @@ func (c *RPCCache) isCacheable(req *RPCReq) bool {
return true return true
} }
func isDefaultBlockParam(s string) bool { func isBlockDependentParam(s string) bool {
return s == "earliest" || s == "latest" || s == "pending" return s == "latest" || s == "pending"
} }
...@@ -15,8 +15,7 @@ type ServerConfig struct { ...@@ -15,8 +15,7 @@ type ServerConfig struct {
} }
type CacheConfig struct { type CacheConfig struct {
Enabled bool `toml:"enabled"` Enabled bool `toml:"enabled"`
RPCMethods []string `toml:"rpc_methods"`
} }
type RedisConfig struct { type RedisConfig struct {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment