|
|
@@ -4,6 +4,7 @@ import (
|
|
|
"context"
|
|
|
"crypto/ecdsa"
|
|
|
"encoding/hex"
|
|
|
+ "errors"
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
"time"
|
|
|
@@ -30,12 +31,12 @@ func FetchCurrentGuardianSet(rpcUrl, coreAddr string) (*common.GuardianSet, erro
|
|
|
ethContract := eth_common.HexToAddress(coreAddr)
|
|
|
rawClient, err := ethRpc.DialContext(ctx, rpcUrl)
|
|
|
if err != nil {
|
|
|
- return nil, fmt.Errorf("failed to connect to ethereum")
|
|
|
+ return nil, errors.New("failed to connect to ethereum")
|
|
|
}
|
|
|
client := ethClient.NewClient(rawClient)
|
|
|
caller, err := ethAbi.NewAbiCaller(ethContract, client)
|
|
|
if err != nil {
|
|
|
- return nil, fmt.Errorf("failed to create caller")
|
|
|
+ return nil, errors.New("failed to create caller")
|
|
|
}
|
|
|
currentIndex, err := caller.GetCurrentGuardianSetIndex(ðBind.CallOpts{Context: ctx})
|
|
|
if err != nil {
|
|
|
@@ -57,7 +58,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
|
|
|
if !exists {
|
|
|
logger.Debug("invalid api key", zap.String("apiKey", apiKey))
|
|
|
invalidQueryRequestReceived.WithLabelValues("invalid_api_key").Inc()
|
|
|
- return http.StatusForbidden, nil, fmt.Errorf("invalid api key")
|
|
|
+ return http.StatusForbidden, nil, errors.New("invalid api key")
|
|
|
}
|
|
|
|
|
|
// TODO: Should we verify the signatures?
|
|
|
@@ -70,7 +71,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
|
|
|
zap.Bool("signerKeyConfigured", signerKey != nil),
|
|
|
)
|
|
|
invalidQueryRequestReceived.WithLabelValues("request_not_signed").Inc()
|
|
|
- return http.StatusBadRequest, nil, fmt.Errorf("request not signed")
|
|
|
+ return http.StatusBadRequest, nil, errors.New("request not signed")
|
|
|
}
|
|
|
|
|
|
// Sign the request using our key.
|
|
|
@@ -117,7 +118,7 @@ func validateRequest(logger *zap.Logger, env common.Environment, perms *Permissi
|
|
|
default:
|
|
|
logger.Debug("unsupported query type", zap.String("userName", permsForUser.userName), zap.Any("type", pcq.Query))
|
|
|
invalidQueryRequestReceived.WithLabelValues("unsupported_query_type").Inc()
|
|
|
- return http.StatusBadRequest, nil, fmt.Errorf("unsupported query type")
|
|
|
+ return http.StatusBadRequest, nil, errors.New("unsupported query type")
|
|
|
}
|
|
|
|
|
|
if err != nil {
|
|
|
@@ -142,7 +143,7 @@ func validateCallData(logger *zap.Logger, permsForUser *permissionEntry, callTag
|
|
|
if len(cd.Data) < ETH_CALL_SIG_LENGTH {
|
|
|
logger.Debug("eth call data must be at least four bytes", zap.String("userName", permsForUser.userName), zap.String("data", hex.EncodeToString(cd.Data)))
|
|
|
invalidQueryRequestReceived.WithLabelValues("bad_call_data").Inc()
|
|
|
- return http.StatusBadRequest, fmt.Errorf("eth call data must be at least four bytes")
|
|
|
+ return http.StatusBadRequest, errors.New("eth call data must be at least four bytes")
|
|
|
}
|
|
|
if !permsForUser.allowAnything {
|
|
|
call := hex.EncodeToString(cd.Data[0:ETH_CALL_SIG_LENGTH])
|