laconicd/server/util.go
Federico Kunze Küllmer d068f5b331
server: logger handler (#343)
* Problem: verbose logs display with FATAL option (fix #320)
add my script

increase amount for metamask

add run

amount ok

hide log

show info

my logger

hook log

revive eth log

tidy up

use suplog

log replace ok

removed suplog

tidy up

tidy up

fix compile

remove sh

tidy up

tidy up

* logger handler

* fix

* fix eth log override (#371)

remove redundant log

tidy up

* log test

* c++

Co-authored-by: jongwhan lee <jonghwan@crypto.com>
Co-authored-by: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com>
2021-08-19 16:55:13 +00:00

99 lines
2.4 KiB
Go

package server
import (
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/improbable-eng/grpc-web/go/grpcweb"
"github.com/spf13/cobra"
sdkserver "github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/version"
tmlog "github.com/tendermint/tendermint/libs/log"
rpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client"
"github.com/tharsis/ethermint/app"
)
// add server commands
func AddCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport types.AppExporter, addStartFlags types.ModuleInitFlags) {
tendermintCmd := &cobra.Command{
Use: "tendermint",
Short: "Tendermint subcommands",
}
tendermintCmd.AddCommand(
sdkserver.ShowNodeIDCmd(),
sdkserver.ShowValidatorCmd(),
sdkserver.ShowAddressCmd(),
sdkserver.VersionCmd(),
)
startCmd := StartCmd(appCreator, defaultNodeHome)
addStartFlags(startCmd)
rootCmd.AddCommand(
startCmd,
sdkserver.UnsafeResetAllCmd(),
tendermintCmd,
sdkserver.ExportCmd(appExport, app.DefaultNodeHome),
version.NewVersionCommand(),
)
}
func ConnectTmWS(tmRPCAddr, tmEndpoint string, logger tmlog.Logger) *rpcclient.WSClient {
tmWsClient, err := rpcclient.NewWS(tmRPCAddr, tmEndpoint,
rpcclient.MaxReconnectAttempts(256),
rpcclient.ReadWait(120*time.Second),
rpcclient.WriteWait(120*time.Second),
rpcclient.PingPeriod(50*time.Second),
rpcclient.OnReconnect(func() {
logger.Debug("EVM RPC reconnects to Tendermint WS", "address", tmRPCAddr+tmEndpoint)
}),
)
if err != nil {
logger.Error(
"Tendermint WS client could not be created",
"address", tmRPCAddr+tmEndpoint,
"error", err,
)
} else if err := tmWsClient.OnStart(); err != nil {
logger.Error(
"Tendermint WS client could not start",
"address", tmRPCAddr+tmEndpoint,
"error", err,
)
}
return tmWsClient
}
func MountGRPCWebServices(
router *mux.Router,
grpcWeb *grpcweb.WrappedGrpcServer,
grpcResources []string,
logger tmlog.Logger,
) {
for _, res := range grpcResources {
logger.Info("[GRPC Web] HTTP POST mounted", "resource", res)
s := router.Methods("POST").Subrouter()
s.HandleFunc(res, func(resp http.ResponseWriter, req *http.Request) {
if grpcWeb.IsGrpcWebSocketRequest(req) {
grpcWeb.HandleGrpcWebsocketRequest(resp, req)
return
}
if grpcWeb.IsGrpcWebRequest(req) {
grpcWeb.HandleGrpcWebRequest(resp, req)
return
}
})
}
}