Skip to content

Commit

Permalink
some godoc and set the root dir in the server context (FourthState#178)
Browse files Browse the repository at this point in the history
* some godoc and set the root dir in the server context

* add verison/commit hash to the build

* seperate plasmacli/d build/install targets

* update dependencies related to cobra/viper

* add build folder to gitignore

* some godoc. cosmos version command. must bind with viper to work appropriately

* extra newline in Makefile and added phony targets
  • Loading branch information
hamdiallam authored Dec 25, 2019
1 parent 6274e7c commit 77fdee3
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
vendor/
/build
contracts/abi
contracts/node_modules
cmd/plasmad/plasmad
cmd/plasmacli/plasmacli
vendor/
40 changes: 31 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,44 @@
export GO111MODULE=on

#######################
### Current Build Properties
VERSION := $(shell echo $(shell git describe --tags) | sed 's/^v//')
COMMIT := $(shell git log -1 --format='%H')
BUILD_TAGS = netgo

BUILD_FLAGS = -tags "$(BUILD_TAGS)" -ldflags \
'-X github.com/cosmos/cosmos-sdk/version.Version=$(VERSION) \
-X github.com/cosmos/cosmos-sdk/version.Commit=$(COMMIT) \
-X "github.com/cosmos/cosmos-sdk/version.BuildTags=$(BUILD_TAGS)"'

all: install test

########################################
### Install & Build

build: go.sum
build: go.sum build-plasmad build-plasmacli

build-plasmad: go.sum
ifeq ($(OS),Windows_NT)
go build -o -mod=readonly -o build/plasmad.exe ./cmd/plasmad
go build -o -mod=readonly -o build/plasmacli.exe ./cmd/plasmacli
go build $(BUILD_FLAGS) -o -mod=readonly -o build/plasmad.exe ./cmd/plasmad
else
go build -o -mod=readonly -o build/plasmad ./cmd/plasmad
go build -o -mod=readonly -o build/plasmacli ./cmd/plasmacli
go build $(BUILD_FLAGS) -o -mod=readonly -o build/plasmad ./cmd/plasmad
endif

install: go.sum
go install -mod=readonly ./cmd/plasmad
go install -mod=readonly ./cmd/plasmacli
build-plasmacli: go.sum
ifeq ($(OS),Windows_NT)
go build $(BUILD_FLAGS) -o -mod=readonly -o build/plasmacli.exe ./cmd/plasmacli
else
go build $(BUILD_FLAGS) -o -mod=readonly -o build/plasmacli ./cmd/plasmacli
endif

install: go.sum install-plasmad install-plasmacli

install-plasmad: go.sum
go install $(BUILD_FLAGS) -mod=readonly ./cmd/plasmad

install-plasmacli: go.sum
go install $(BUILD_FLAGS) -mod=readonly ./cmd/plasmacli

########################################
### Dependencies & Maintenance
Expand All @@ -37,4 +59,4 @@ test-unit:
go test -mod=readonly -race -coverprofile=coverage.txt -covermode=atomic -v ./...

# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
.PHONY: all build install go.sum test test-unit
.PHONY: all build build-plasmad build-plasmacli install install-plasmad install-plasmacli go.sum test test-unit
2 changes: 1 addition & 1 deletion cmd/plasmacli/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func DefaultConfig() Config {
}
}

// RegisterViper will match client flags with config and register env
// RegisterViperAndEnv will match client flags with config and register env
func RegisterViperAndEnv() {
viper.SetEnvPrefix("PCLI")
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
Expand Down
1 change: 1 addition & 0 deletions cmd/plasmacli/subcmd/eth/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ An eth node instance needs to be running for this command to work.`,
},
}

// HasTxExited -
func HasTxExited(pos plasma.Position) (bool, error) {
conn, err := config.GetContractConn()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/plasmacli/subcmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ var rootCmd = &cobra.Command{
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
config.RegisterViperAndEnv()
homeDir := viper.GetString(flags.Home)

homeDir := viper.GetString(flags.Home)
store.InitKeystore(homeDir)

configFilepath := filepath.Join(homeDir, "config.toml")
Expand Down
16 changes: 6 additions & 10 deletions cmd/plasmacli/subcmd/version.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package subcmd

import (
"fmt"
"github.com/cosmos/cosmos-sdk/version"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// VersionCmd returns the version cmd for plasmacli
var versionCmd = version.VersionCmd

// VersionCmd -
func VersionCmd() *cobra.Command {
viper.BindPFlags(versionCmd.LocalFlags())
return versionCmd
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of the plasma client",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Plasma Client v0.3.0")
},
}
9 changes: 6 additions & 3 deletions cmd/plasmad/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"github.com/FourthState/plasma-mvp-sidechain/app"
"github.com/FourthState/plasma-mvp-sidechain/cmd/plasmad/config"
"github.com/FourthState/plasma-mvp-sidechain/cmd/plasmad/subcmd"
Expand All @@ -16,10 +17,13 @@ import (
"path/filepath"
)

var rootDir string = os.ExpandEnv("$HOME/.plasmad")

func main() {
// codec only used for server.AddCommand
cdc := app.MakeCodec()
ctx := server.NewDefaultContext()
ctx.Config.SetRoot(rootDir)

rootCmd := &cobra.Command{
Use: "plasmad",
Expand All @@ -29,11 +33,10 @@ func main() {
rootCmd.AddCommand(subcmd.InitCmd(ctx, cdc))
server.AddCommands(ctx, cdc, rootCmd, newApp, nil)

// HomeFlag in tendermint cli will be set to `~/.plasmad`
rootDir := os.ExpandEnv("$HOME/.plasmad")
executor := cli.PrepareBaseCmd(rootCmd, "PD", rootDir)
if err := executor.Execute(); err != nil {
panic(err)
fmt.Println(err)
os.Exit(1)
}
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/plasmad/subcmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
if tmCommon.FileExists(genFile) {
if !overwrite {
return fmt.Errorf("genesis.json file already exists: %v", genFile)
} else {
fmt.Printf("overwriting genesis.json...\n")
}

fmt.Printf("overwriting genesis.json...\n")
}
// read of create the private key file for this config
var privValidator *privval.FilePV
Expand Down Expand Up @@ -104,9 +104,9 @@ func InitCmd(ctx *server.Context, cdc *codec.Codec) *cobra.Command {
if tmCommon.FileExists(plasmaPath) {
if !overwrite {
return fmt.Errorf("plasma.toml already exists at '%s'. Use -o flag to overwrite", plasmaPath)
} else {
fmt.Println("overwriting plasma.toml...")
}

fmt.Println("overwriting plasma.toml...")
}
pConfig.WritePlasmaConfigFile(plasmaPath, plasmaConfig)

Expand Down
27 changes: 9 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,28 @@ require (
github.com/ethereum/go-ethereum v1.8.20
github.com/fjl/memsize v0.0.0-20180929194037-2a09253e352a // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/google/gofuzz v1.0.0 // indirect
github.com/google/uuid v1.1.1 // indirect
github.com/gorilla/mux v1.7.0
github.com/gorilla/websocket v1.4.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/huin/goupnp v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.1 // indirect
github.com/jmhodges/levigo v1.0.0 // indirect
github.com/karalabe/hid v0.0.0-20181128192157-d815e0c1a2e2 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/mattn/go-colorable v0.1.1 // indirect
github.com/mattn/go-isatty v0.0.6 // indirect
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/pborman/uuid v0.0.0-20180906182336-adf5a7427709 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/prometheus/client_golang v0.9.2 // indirect
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90 // indirect
github.com/prometheus/common v0.2.0 // indirect
github.com/prometheus/procfs v0.0.0-20190227231451-bbced9601137 // indirect
github.com/pelletier/go-toml v1.6.0 // indirect
github.com/rakyll/statik v0.1.6 // indirect
github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 // indirect
github.com/rjeczalik/notify v0.9.2 // indirect
github.com/rs/cors v1.6.0 // indirect
github.com/spf13/afero v1.2.1 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v0.0.5
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
github.com/spf13/viper v1.0.3
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.2.2
github.com/syndtr/goleveldb v0.0.0-20190226153722-4217c9f31f58
github.com/tendermint/btcd v0.1.0 // indirect
Expand All @@ -59,13 +49,14 @@ require (
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5 // indirect
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 // indirect
golang.org/x/net v0.0.0-20190603091049-60506f45cf65 // indirect
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed // indirect
golang.org/x/sys v0.0.0-20191224085550-c709ea063b76 // indirect
golang.org/x/text v0.3.2 // indirect
golang.org/x/tools v0.0.0-20190603231351-8aaa1484dc10 // indirect
google.golang.org/genproto v0.0.0-20190227213309-4f5b463f9597 // indirect
gopkg.in/ini.v1 v1.51.1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
gopkg.in/urfave/cli.v1 v1.20.0 // indirect
gopkg.in/yaml.v2 v2.2.2 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
)

replace golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
Expand Down
Loading

0 comments on commit 77fdee3

Please sign in to comment.