Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #40
Browse files Browse the repository at this point in the history
Release v0.3.2
  • Loading branch information
bsrinivas8687 authored Jun 1, 2021
2 parents df6c8fc + 17c92b7 commit 9cf8785
Show file tree
Hide file tree
Showing 169 changed files with 2,482 additions and 5,054 deletions.
1 change: 1 addition & 0 deletions .env.development
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BROWSER=none
FAST_REFRESH=true
REACT_APP_LISTEN_URL=http://127.0.0.1:26667
REACT_APP_TOKEN=
4 changes: 2 additions & 2 deletions cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ BUILD_FLAGS := -tags "${BUILD_TAGS}" -ldflags "${LD_FLAGS}"
all: mod_verify test benchmark install

install: mod_verify
go build -mod=readonly ${BUILD_FLAGS} -o ${GOPATH}/bin/sdccli main.go
go build -mod=readonly ${BUILD_FLAGS} -o ${GOPATH}/bin/sentinelcli main.go

build: mod_verify
go build -mod=readonly ${BUILD_FLAGS} -o ../bin/manager main.go
go build -mod=readonly ${BUILD_FLAGS} -o ../bin/sentinelcli main.go

test:
@go test -mod=readonly -cover ${PACKAGES}
Expand Down
95 changes: 57 additions & 38 deletions cli/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ import (
"path/filepath"
"strings"

clientutils "github.com/cosmos/cosmos-sdk/x/auth/client/utils"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/std"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/gorilla/mux"
"github.com/rs/cors"
"github.com/sentinel-official/hub"
"github.com/sentinel-official/hub/params"
"github.com/spf13/cobra"
"github.com/spf13/viper"
rpchttp "github.com/tendermint/tendermint/rpc/client/http"

"github.com/sentinel-official/desktop-client/cli/context"
"github.com/sentinel-official/desktop-client/cli/lite"
"github.com/sentinel-official/desktop-client/cli/middlewares"
"github.com/sentinel-official/desktop-client/cli/rest/account"
"github.com/sentinel-official/desktop-client/cli/rest/auth"
"github.com/sentinel-official/desktop-client/cli/rest/bank"
"github.com/sentinel-official/desktop-client/cli/rest/config"
"github.com/sentinel-official/desktop-client/cli/rest/deposit"
Expand All @@ -34,6 +37,7 @@ import (
"github.com/sentinel-official/desktop-client/cli/rest/staking"
"github.com/sentinel-official/desktop-client/cli/rest/subscription"
"github.com/sentinel-official/desktop-client/cli/types"
"github.com/sentinel-official/desktop-client/cli/utils"
)

func ServerCmd(cfg *types.Config) *cobra.Command {
Expand All @@ -60,59 +64,68 @@ func ServerCmd(cfg *types.Config) *cobra.Command {
return err
}

var (
cdc = hub.MakeCodec()
buildFolder = filepath.Join(home, "build")
)
encoding := params.MakeEncodingConfig()
std.RegisterInterfaces(encoding.InterfaceRegistry)
hub.ModuleBasics.RegisterInterfaces(encoding.InterfaceRegistry)

rpcclient, err := rpchttp.New(cfg.Chain.RPCAddress, "/websocket")
if err != nil {
return err
}

client, err := lite.NewClientFromConfig(cfg)
kr, err := keyring.New("sentinel", keyring.BackendOS, home, cmd.InOrStdin())
if err != nil {
return err
}

client.WithCodec(cdc).
WithTxEncoder(clientutils.GetTxEncoder(cdc))
client := lite.NewDefaultClient().
WithAccountRetriever(authtypes.AccountRetriever{}).
WithChainID(cfg.Chain.ID).
WithClient(rpcclient).
WithGas(cfg.Chain.Gas).
WithGasAdjustment(cfg.Chain.GasAdjustment).
WithGasPrices(cfg.Chain.GasPrices).
WithInterfaceRegistry(encoding.InterfaceRegistry).
WithKeyring(kr).
WithLegacyAmino(encoding.Amino).
WithNodeURI(cfg.Chain.RPCAddress).
WithSimulateAndExecute(cfg.Chain.SimulateAndExecute).
WithTxConfig(encoding.TxConfig)

ctx := context.NewContext().
WithHome(home).
WithConfig(cfg).
WithClient(client)
WithClient(client).
WithToken(utils.RandomStringHex(32))

var (
muxRouter = mux.NewRouter()
protectedRouter = muxRouter.PathPrefix("/api/v1").Subrouter()
unprotectedRouter = muxRouter.PathPrefix("/api/v1").Subrouter()
muxRouter = mux.NewRouter()
prefixRouter = muxRouter.PathPrefix("/api/v1").Subrouter()
)

muxRouter.Use(middlewares.Log)
muxRouter.PathPrefix("/").
Handler(http.FileServer(http.Dir(buildFolder)))

unprotectedRouter.Use(middlewares.AddHeaders)
auth.RegisterRoutes(unprotectedRouter, ctx)

protectedRouter.Use(middlewares.AddHeaders)
protectedRouter.Use(middlewares.TokenVerify(ctx))
account.RegisterRoutes(protectedRouter, ctx)
bank.RegisterRoutes(protectedRouter, ctx)
config.RegisterRoutes(protectedRouter, ctx)
deposit.RegisterRoutes(protectedRouter, ctx)
distribution.RegisterRoutes(protectedRouter, ctx)
gov.RegisterRoutes(protectedRouter, ctx)
keys.RegisterRoutes(protectedRouter, ctx)
node.RegisterRoutes(protectedRouter, ctx)
plan.RegisterRoutes(protectedRouter, ctx)
provider.RegisterRoutes(protectedRouter, ctx)
service.RegisterRoutes(protectedRouter, ctx)
session.RegisterRoutes(protectedRouter, ctx)
staking.RegisterRoutes(protectedRouter, ctx)
subscription.RegisterRoutes(protectedRouter, ctx)
prefixRouter.Use(middlewares.AddHeaders)
prefixRouter.Use(middlewares.TokenVerify(ctx))
account.RegisterRoutes(prefixRouter, ctx)
bank.RegisterRoutes(prefixRouter, ctx)
config.RegisterRoutes(prefixRouter, ctx)
deposit.RegisterRoutes(prefixRouter, ctx)
distribution.RegisterRoutes(prefixRouter, ctx)
gov.RegisterRoutes(prefixRouter, ctx)
keys.RegisterRoutes(prefixRouter, ctx)
node.RegisterRoutes(prefixRouter, ctx)
plan.RegisterRoutes(prefixRouter, ctx)
provider.RegisterRoutes(prefixRouter, ctx)
service.RegisterRoutes(prefixRouter, ctx)
session.RegisterRoutes(prefixRouter, ctx)
staking.RegisterRoutes(prefixRouter, ctx)
subscription.RegisterRoutes(prefixRouter, ctx)

router := cors.New(
cors.Options{
AllowedOrigins: strings.Split(cfg.CORS.AllowedOrigins, ","),
AllowedMethods: []string{http.MethodGet, http.MethodPost, http.MethodPut},
AllowedHeaders: []string{"Authorization", "Content-Type"},
AllowedHeaders: []string{"Content-Type", "Authorization"},
},
).Handler(muxRouter)

Expand All @@ -121,14 +134,20 @@ func ServerCmd(cfg *types.Config) *cobra.Command {
return err
}

log.Printf("Listening on URL %s\n", listenURL)
switch url.Scheme {
case "http", "https":
default:
return fmt.Errorf("invalid listen URL schema")
}

log.Printf("URL: %s, TOKEN: %s", listenURL, ctx.Token())
switch url.Scheme {
case "http":
return http.ListenAndServe(url.Host, router)
case "https":
return http.ListenAndServeTLS(url.Host, certFile, keyFile, router)
default:
return fmt.Errorf("invalid listen URL schema")
return nil
}
},
}
Expand Down
34 changes: 14 additions & 20 deletions cli/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ package context
import (
"context"

"github.com/tendermint/tendermint/libs/bytes"

"github.com/sentinel-official/desktop-client/cli/lite"
"github.com/sentinel-official/desktop-client/cli/types"
)

type Context struct {
home string
token string
ctx context.Context
service types.Service
client *lite.Client
config *types.Config
token *types.AuthToken
}

func NewContext() *Context {
Expand All @@ -24,23 +22,19 @@ func NewContext() *Context {
}
}

func (c *Context) WithHome(v string) *Context { c.home = v; return c }
func (c *Context) WithClient(v *lite.Client) *Context { c.client = v; return c }
func (c *Context) WithConfig(v *types.Config) *Context { c.config = v; return c }
func (c *Context) WithAuthToken(v *types.AuthToken) *Context { c.token = v; return c }
func (c *Context) WithContext(v context.Context) *Context { c.ctx = v; return c }
func (c *Context) WithService(v types.Service) *Context { c.service = v; return c }

func (c *Context) AddressHex() string {
return bytes.HexBytes(c.client.FromAddress().Bytes()).String()
}

func (c *Context) Home() string { return c.home }
func (c *Context) Client() *lite.Client { return c.client }
func (c *Context) Config() *types.Config { return c.config }
func (c *Context) AuthToken() *types.AuthToken { return c.token }
func (c *Context) Context() context.Context { return c.ctx }
func (c *Context) Service() types.Service { return c.service }
func (c *Context) WithHome(v string) *Context { c.home = v; return c }
func (c *Context) WithToken(v string) *Context { c.token = v; return c }
func (c *Context) WithClient(v *lite.Client) *Context { c.client = v; return c }
func (c *Context) WithConfig(v *types.Config) *Context { c.config = v; return c }
func (c *Context) WithContext(v context.Context) *Context { c.ctx = v; return c }
func (c *Context) WithService(v types.Service) *Context { c.service = v; return c }

func (c *Context) Home() string { return c.home }
func (c *Context) Token() string { return c.token }
func (c *Context) Client() *lite.Client { return c.client }
func (c *Context) Config() *types.Config { return c.config }
func (c *Context) Context() context.Context { return c.ctx }
func (c *Context) Service() types.Service { return c.service }

func (c *Context) WithValue(key, value interface{}) *Context {
c.WithContext(context.WithValue(c.ctx, key, value))
Expand Down
26 changes: 16 additions & 10 deletions cli/go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
module github.com/sentinel-official/desktop-client/cli

go 1.15
go 1.16

require (
github.com/cosmos/cosmos-sdk v0.39.2
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d
github.com/cosmos/cosmos-sdk v0.42.5
github.com/cosmos/go-bip39 v1.0.0
github.com/go-kit/kit v0.10.0
github.com/gorilla/mux v1.8.0
github.com/pelletier/go-toml v1.8.0
github.com/pelletier/go-toml v1.8.1
github.com/rs/cors v1.7.0
github.com/sentinel-official/hub v0.5.0
github.com/spf13/cobra v1.0.0
github.com/sentinel-official/hub v0.6.2
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
github.com/tendermint/tendermint v0.33.9
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb
github.com/tendermint/tendermint v0.34.10
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
google.golang.org/grpc v1.38.0
)

replace github.com/keybase/go-keychain => github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4
replace (
github.com/cosmos/cosmos-sdk => github.com/sentinel-official/cosmos-sdk v0.42.6-sentinel
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
Loading

0 comments on commit 9cf8785

Please sign in to comment.