From 1603804ca09c6bd6c705d7d34bbf8564d46b0664 Mon Sep 17 00:00:00 2001 From: Sridhar Ganesan Date: Tue, 17 Jul 2018 21:18:55 +0200 Subject: [PATCH] Using basecoin as the template and refactoring the command that creates the workspace setup Removing templates, making changes to makefile to remove dependency on packr --- Gopkg.lock | 8 +- Gopkg.toml | 4 - Makefile | 21 ++- cmd/cosmos-sdk-cli/cmd/init.go | 146 +++++++++++++------ cmd/cosmos-sdk-cli/cmd/root.go | 3 - cmd/cosmos-sdk-cli/template/Gopkg.toml | 58 -------- cmd/cosmos-sdk-cli/template/Makefile | 23 --- cmd/cosmos-sdk-cli/template/app/app.go | 144 ------------------ cmd/cosmos-sdk-cli/template/cmd/cli/main.go | 77 ---------- cmd/cosmos-sdk-cli/template/cmd/node/main.go | 69 --------- cmd/cosmos-sdk-cli/template/types/account.go | 77 ---------- tools/Makefile | 15 -- 12 files changed, 111 insertions(+), 534 deletions(-) delete mode 100644 cmd/cosmos-sdk-cli/template/Gopkg.toml delete mode 100644 cmd/cosmos-sdk-cli/template/Makefile delete mode 100644 cmd/cosmos-sdk-cli/template/app/app.go delete mode 100644 cmd/cosmos-sdk-cli/template/cmd/cli/main.go delete mode 100644 cmd/cosmos-sdk-cli/template/cmd/node/main.go delete mode 100644 cmd/cosmos-sdk-cli/template/types/account.go diff --git a/Gopkg.lock b/Gopkg.lock index 3d5f74179..66f6c0492 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -78,12 +78,6 @@ revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc" version = "v1.7.0" -[[projects]] - name = "github.com/gobuffalo/packr" - packages = ["."] - revision = "bd47f2894846e32edcf9aa37290fef76c327883f" - version = "v1.11.1" - [[projects]] name = "github.com/gogo/protobuf" packages = [ @@ -507,6 +501,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "2a655310c28a7f80cb2cfe5f2969182896aac09293344472de10e9135ddc364c" + inputs-digest = "71e86b1f1e9ec71901c20d8532dc8477df66eff37a407322379f6a8b03e5d91b" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 2a8ef4bc7..3db675ebb 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -67,10 +67,6 @@ name = "github.com/zondax/ledger-goclient" revision = "39ba4728c137c75718a21f9b4b3280fa31b9139b" -[[constraint]] - name = "github.com/gobuffalo/packr" - version = "1.11.1" - [prune] go-tests = true unused-packages = true diff --git a/Makefile b/Makefile index d8eab8e86..69890355c 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -PACKAGES=$(shell go list ./... | grep -v '/vendor/' | grep -v '/cosmos-sdk-cli/template') -PACKAGES_NOCLITEST=$(shell go list ./... | grep -v '/vendor/' | grep -v '/cosmos-sdk-cli/template' | grep -v github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test) +PACKAGES=$(shell go list ./... | grep -v '/vendor/') +PACKAGES_NOCLITEST=$(shell go list ./... | grep -v '/vendor/' | grep -v github.com/cosmos/cosmos-sdk/cmd/gaia/cli_test) COMMIT_HASH := $(shell git rev-parse --short HEAD) BUILD_TAGS = netgo ledger BUILD_FLAGS = -tags "${BUILD_TAGS}" -ldflags "-X github.com/cosmos/cosmos-sdk/version.GitCommit=${COMMIT_HASH}" @@ -39,11 +39,9 @@ build-linux: build_cosmos-sdk-cli: ifeq ($(OS),Windows_NT) - packr build $(BUILD_FLAGS) -o build/cosmos-sdk-cli.exe ./cmd/cosmos-sdk-cli - packr clean + go build $(BUILD_FLAGS) -o build/cosmos-sdk-cli.exe ./cmd/cosmos-sdk-cli else - packr build $(BUILD_FLAGS) -o build/cosmos-sdk-cli ./cmd/cosmos-sdk-cli - packr clean + go build $(BUILD_FLAGS) -o build/cosmos-sdk-cli ./cmd/cosmos-sdk-cli endif build_examples: @@ -70,8 +68,7 @@ install_examples: go install $(BUILD_FLAGS) ./examples/democoin/cmd/democli install_cosmos-sdk-cli: - packr install $(BUILD_FLAGS) ./cmd/cosmos-sdk-cli - packr clean + go install $(BUILD_FLAGS) ./cmd/cosmos-sdk-cli install_debug: go install $(BUILD_FLAGS) ./cmd/gaia/cmd/gaiadebug @@ -95,7 +92,7 @@ get_tools: get_vendor_deps: @rm -rf vendor/ @echo "--> Running dep ensure" - @dep ensure -v --vendor-only + @dep ensure -v draw_deps: @# requires brew install graphviz or apt-get install graphviz @@ -129,9 +126,9 @@ test_cover: @bash tests/test_cover.sh test_lint: - gometalinter.v2 --config=tools/gometalinter.json ./... --exclude cmd/cosmos-sdk-cli/template - !(gometalinter.v2 --disable-all --enable='errcheck' --vendor ./... | grep -v "client/" | grep -v "cosmos-sdk-cli/template/") - find . -name '*.go' -type f -not -path "./vendor*" -not -path "./cmd/cosmos-sdk-cli/template" -not -path "*.git*" | xargs gofmt -d -s + gometalinter.v2 --config=tools/gometalinter.json ./... + !(gometalinter.v2 --disable-all --enable='errcheck' --vendor ./... | grep -v "client/" ) + find . -name '*.go' -type f -not -path "./vendor*" -not -path "*.git*" | xargs gofmt -d -s dep status >> /dev/null !(grep -n branch Gopkg.toml) diff --git a/cmd/cosmos-sdk-cli/cmd/init.go b/cmd/cosmos-sdk-cli/cmd/init.go index 713f7e81a..2279dc8a1 100644 --- a/cmd/cosmos-sdk-cli/cmd/init.go +++ b/cmd/cosmos-sdk-cli/cmd/init.go @@ -1,21 +1,19 @@ package cmd import ( - "bufio" "fmt" "go/build" "io/ioutil" "os" "strings" - "time" "github.com/cosmos/cosmos-sdk/version" - "github.com/gobuffalo/packr" - "github.com/pkg/errors" "github.com/spf13/cobra" + "path/filepath" ) func init() { + initCmd.Flags().StringVarP(&remoteProjectPath, "project-path", "p", "", "Remote project path. eg: github.com/your_user_name/project_name") rootCmd.AddCommand(initCmd) } @@ -28,54 +26,112 @@ func resolveProjectPath(remoteProjectPath string) string { return gopath + string(os.PathSeparator) + "src" + string(os.PathSeparator) + remoteProjectPath } -var initCmd = &cobra.Command{ - Use: "init AwesomeProjectName", - Short: "Initialize your new cosmos zone", - RunE: func(cmd *cobra.Command, args []string) error { - if len(args) < 1 { - return errors.New("Project name is required") +func check(e error) { + if e != nil { + panic(e) + } +} + +var remoteBasecoinPath = "github.com/cosmos/cosmos-sdk/examples/basecoin" + +func copyBasecoinTemplate(projectName string, projectPath string, remoteProjectPath string) { + basecoinProjectPath := resolveProjectPath(remoteBasecoinPath) + filepath.Walk(basecoinProjectPath, func(path string, f os.FileInfo, err error) error { + if !f.IsDir() { + data, err := ioutil.ReadFile(path) + check(err) + contents := string(data) + // Extract relative file path eg: app/app.go instead of /Users/..../github.com/cosmos/...examples/basecoin/app/app.go + relativeFilePath := path[len(basecoinProjectPath)+1:] + // Evaluating the filepath in the new project folder + projectFilePath := projectPath + string(os.PathSeparator) + relativeFilePath + lengthOfRootDir := strings.LastIndex(projectFilePath, string(os.PathSeparator)) + // Extracting the path of root directory from the filepath + rootDir := projectFilePath[0:lengthOfRootDir] + // Creating the required directory first + os.MkdirAll(rootDir, os.ModePerm) + fmt.Println("Creating " + projectFilePath) + // Writing the contents to a file in the project folder + ioutil.WriteFile(projectFilePath, []byte(contents), os.ModePerm) } + return nil + }) + + //Copy the entire basecoin directory to the project path. + //os.MkdirAll(projectPath+string(os.PathSeparator)+rootDir, os.ModePerm) + //filePath := projectPath + string(os.PathSeparator) + actualPath + //ioutil.WriteFile(filePath, []byte(contents), os.ModePerm) +} + +func createGopkg(projectPath string) { + // Create gopkg.toml file + dependencies := map[string]string{ + "github.com/cosmos/cosmos-sdk": version.Version, + } + overrides := map[string]string{ + "github.com/golang/protobuf": "1.1.0", + } + contents := "" + for dependency, version := range dependencies { + contents += "[[constraint]]\n\tname = \"" + dependency + "\"\n\tversion = \"" + version + "\"\n\n" + } + for dependency, version := range overrides { + contents += "[[override]]\n\tname = \"" + dependency + "\"\n\tversion = \"=" + version + "\"\n\n" + } + contents += "[prune]\n\tgo-tests = true\n\tunused-packages = true" + ioutil.WriteFile(projectPath+"/Gopkg.toml", []byte(contents), os.ModePerm) +} + +func createMakefile(projectPath string) { + // Create makefile + makefileContents := `PACKAGES=$(shell go list ./... | grep -v '/vendor/') + +all: get_tools get_vendor_deps build test + +get_tools: + go get github.com/golang/dep/cmd/dep + +build: + go build -o bin/basecli cmd/basecli/main.go && go build -o bin/basecoind cmd/basecoind/main.go + +get_vendor_deps: + @rm -rf vendor/ + @dep ensure + +test: + @go test $(PACKAGES) + +benchmark: + @go test -bench=. $(PACKAGES) + +.PHONY: all build test benchmark` + ioutil.WriteFile(projectPath+"/Makefile", []byte(makefileContents), os.ModePerm) + +} + +func setupBasecoinWorkspace(projectName string, remoteProjectPath string) { + projectPath := resolveProjectPath(remoteProjectPath) + fmt.Println("Configuring your project in " + projectPath) + copyBasecoinTemplate(projectName, projectPath, remoteProjectPath) + createGopkg(projectPath) + createMakefile(projectPath) + fmt.Println("\nInitialized a new project at " + projectPath + ".\nHappy hacking!") +} + +var remoteProjectPath string +var initCmd = &cobra.Command{ + Use: "init [ProjectName]", + Short: "Initialize your new cosmos zone", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + fmt.Print("Thanks for choosing Cosmos-SDK to build your project.\n\n") projectName := args[0] - capitalizedProjectName := strings.Title(projectName) shortProjectName := strings.ToLower(projectName) - reader := bufio.NewReader(os.Stdin) - fmt.Println("Thank you for using cosmos-zone tool.") - fmt.Println("You are only a few steps away from creating your brand new blockchain project on Cosmos.") - fmt.Print("We will ask you a few more questions to guide you through this process\n\n") - fmt.Print("To configure this project we need a remote project path. If you are unsure you can leave this empty. ") - fmt.Print("Remote project path is usually something like github.com/your_user_name/project_name\n") - fmt.Print("Enter remote project path: ") - remoteProjectPath, _ := reader.ReadString('\n') remoteProjectPath = strings.ToLower(strings.TrimSpace(remoteProjectPath)) if remoteProjectPath == "" { remoteProjectPath = strings.ToLower(shortProjectName) } - projectPath := resolveProjectPath(remoteProjectPath) - fmt.Print("configuring the project in " + projectPath + "\n\n") - time.Sleep(2 * time.Second) - box := packr.NewBox("../template") - var replacer = strings.NewReplacer("MyAwesomeProject", capitalizedProjectName, "myawesomeproject", shortProjectName, "github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template", remoteProjectPath) - box.Walk(func(path string, file packr.File) error { - actualPath := replacer.Replace(path) - fmt.Println("Creating file: " + actualPath) - contents := box.String(path) - contents = replacer.Replace(contents) - if actualPath == "Gopkg.toml" { - versionReplacer := strings.NewReplacer("_COSMOS_VERSION_", version.Version) - contents = versionReplacer.Replace(contents) - } - lastIndex := strings.LastIndex(actualPath, string(os.PathSeparator)) - rootDir := "" - if lastIndex != -1 { - rootDir = actualPath[0:lastIndex] - } - // Create directory - os.MkdirAll(projectPath+string(os.PathSeparator)+rootDir, os.ModePerm) - filePath := projectPath + string(os.PathSeparator) + actualPath - ioutil.WriteFile(filePath, []byte(contents), os.ModePerm) - return nil - }) - fmt.Println("Initialized a new project at " + projectPath + ". Happy hacking!") + setupBasecoinWorkspace(shortProjectName, remoteProjectPath) return nil }, } diff --git a/cmd/cosmos-sdk-cli/cmd/root.go b/cmd/cosmos-sdk-cli/cmd/root.go index ae09169d9..2eddd79b5 100644 --- a/cmd/cosmos-sdk-cli/cmd/root.go +++ b/cmd/cosmos-sdk-cli/cmd/root.go @@ -10,9 +10,6 @@ import ( var rootCmd = &cobra.Command{ Use: "cosmos-sdk-cli", Short: "Tools to develop on cosmos-sdk", - Run: func(cmd *cobra.Command, args []string) { - // Do Stuff Here - }, } // Execute the command diff --git a/cmd/cosmos-sdk-cli/template/Gopkg.toml b/cmd/cosmos-sdk-cli/template/Gopkg.toml deleted file mode 100644 index b0e7a0fef..000000000 --- a/cmd/cosmos-sdk-cli/template/Gopkg.toml +++ /dev/null @@ -1,58 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - -[[constraint]] - name = "github.com/pkg/errors" - version = "~0.8.0" - -[[constraint]] - name = "github.com/spf13/cobra" - version = "~0.0.1" - -[[constraint]] - name = "github.com/spf13/viper" - version = "~1.0.0" - -[[constraint]] - name = "github.com/stretchr/testify" - version = "~1.2.1" - -[[constraint]] - version = "~0.10.0" - source = "github.com/tendermint/go-amino" - name = "github.com/tendermint/go-wire" - -[[constraint]] - version = "~0.21.0" - name = "github.com/cosmos/cosmos-sdk" - -[[override]] - version = "=1.1.0" - name = "github.com/golang/protobuf" - -[prune] - go-tests = true - unused-packages = true diff --git a/cmd/cosmos-sdk-cli/template/Makefile b/cmd/cosmos-sdk-cli/template/Makefile deleted file mode 100644 index 87a3d7abe..000000000 --- a/cmd/cosmos-sdk-cli/template/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -PACKAGES=$(shell go list ./... | grep -v '/vendor/') -#BUILD_FLAGS = -ldflags "-X github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template/version.GitCommit=`git rev-parse --short HEAD`" - -all: get_tools get_vendor_deps build test - -get_tools: - go get github.com/golang/dep/cmd/dep - -build: - go build -o bin/myawesomeprojectcli cmd/cli/main.go && go build -o bin/myawesomeprojectd cmd/node/main.go - -get_vendor_deps: - @rm -rf vendor/ - @dep ensure - -test: - @go test $(PACKAGES) - -benchmark: - @go test -bench=. $(PACKAGES) - -.PHONY: all build test benchmark - diff --git a/cmd/cosmos-sdk-cli/template/app/app.go b/cmd/cosmos-sdk-cli/template/app/app.go deleted file mode 100644 index 465acbf0f..000000000 --- a/cmd/cosmos-sdk-cli/template/app/app.go +++ /dev/null @@ -1,144 +0,0 @@ -package app - -import ( - "encoding/json" - - abci "github.com/tendermint/tendermint/abci/types" - cmn "github.com/tendermint/tendermint/libs/common" - dbm "github.com/tendermint/tendermint/libs/db" - "github.com/tendermint/tendermint/libs/log" - tmtypes "github.com/tendermint/tendermint/types" - - bam "github.com/cosmos/cosmos-sdk/baseapp" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" - "github.com/cosmos/cosmos-sdk/x/auth" - "github.com/cosmos/cosmos-sdk/x/bank" - - "github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template/types" -) - -const ( - appName = "MyAwesomeProjectApp" -) - -// Extended ABCI application -type MyAwesomeProjectApp struct { - *bam.BaseApp - cdc *wire.Codec - - // keys to access the substores - capKeyMainStore *sdk.KVStoreKey - capKeyAccountStore *sdk.KVStoreKey - - // keepers - feeCollectionKeeper auth.FeeCollectionKeeper - coinKeeper bank.Keeper - - // Manage getting and setting accounts - accountMapper auth.AccountMapper -} - -func NewMyAwesomeProjectApp(logger log.Logger, db dbm.DB) *MyAwesomeProjectApp { - - // Create app-level codec for txs and accounts. - var cdc = MakeCodec() - - // Create your application object. - var app = &MyAwesomeProjectApp{ - BaseApp: bam.NewBaseApp(appName, cdc, logger, db), - cdc: cdc, - capKeyMainStore: sdk.NewKVStoreKey("main"), - capKeyAccountStore: sdk.NewKVStoreKey("acc"), - } - - // Define the accountMapper. - app.accountMapper = auth.NewAccountMapper( - cdc, - app.capKeyAccountStore, // target store - types.ProtoAppAccount, // prototype - ) - - // Add handlers. - app.coinKeeper = bank.NewKeeper(app.accountMapper) - app.Router(). - AddRoute("bank", bank.NewHandler(app.coinKeeper)) - - // Initialize BaseApp. - app.SetInitChainer(app.initChainerFn()) - app.MountStoresIAVL(app.capKeyMainStore, app.capKeyAccountStore) - app.SetAnteHandler(auth.NewAnteHandler(app.accountMapper, app.feeCollectionKeeper)) - err := app.LoadLatestVersion(app.capKeyMainStore) - if err != nil { - cmn.Exit(err.Error()) - } - return app -} - -// custom tx codec -func MakeCodec() *wire.Codec { - var cdc = wire.NewCodec() - wire.RegisterCrypto(cdc) // Register crypto. - sdk.RegisterWire(cdc) // Register Msgs - bank.RegisterWire(cdc) - - // Register AppAccount - cdc.RegisterInterface((*auth.Account)(nil), nil) - cdc.RegisterConcrete(&types.AppAccount{}, "myawesomeproject/Account", nil) - - cdc.Seal() - - return cdc -} - -// custom logic for myawesomeproject initialization -// nolint: unparam -func (app *MyAwesomeProjectApp) initChainerFn() sdk.InitChainer { - return func(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain { - stateJSON := req.AppStateBytes - - genesisState := new(types.GenesisState) - err := app.cdc.UnmarshalJSON(stateJSON, genesisState) - if err != nil { - panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468 - // return sdk.ErrGenesisParse("").TraceCause(err, "") - } - - for _, gacc := range genesisState.Accounts { - acc, err := gacc.ToAppAccount() - if err != nil { - panic(err) // TODO https://github.com/cosmos/cosmos-sdk/issues/468 - // return sdk.ErrGenesisParse("").TraceCause(err, "") - } - app.accountMapper.SetAccount(ctx, acc) - } - - return abci.ResponseInitChain{} - } -} - -// Custom logic for state export -func (app *MyAwesomeProjectApp) ExportAppStateAndValidators() (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) { - ctx := app.NewContext(true, abci.Header{}) - - // iterate to get the accounts - accounts := []*types.GenesisAccount{} - appendAccount := func(acc auth.Account) (stop bool) { - account := &types.GenesisAccount{ - Address: acc.GetAddress(), - Coins: acc.GetCoins(), - } - accounts = append(accounts, account) - return false - } - app.accountMapper.IterateAccounts(ctx, appendAccount) - - genState := types.GenesisState{ - Accounts: accounts, - } - appState, err = wire.MarshalJSONIndent(app.cdc, genState) - if err != nil { - return nil, nil, err - } - return appState, validators, nil -} diff --git a/cmd/cosmos-sdk-cli/template/cmd/cli/main.go b/cmd/cosmos-sdk-cli/template/cmd/cli/main.go deleted file mode 100644 index 9ce51c999..000000000 --- a/cmd/cosmos-sdk-cli/template/cmd/cli/main.go +++ /dev/null @@ -1,77 +0,0 @@ -package main - -import ( - "os" - - "github.com/spf13/cobra" - - "github.com/tendermint/tendermint/libs/cli" - - "github.com/cosmos/cosmos-sdk/client" - "github.com/cosmos/cosmos-sdk/client/keys" - "github.com/cosmos/cosmos-sdk/client/lcd" - "github.com/cosmos/cosmos-sdk/client/rpc" - "github.com/cosmos/cosmos-sdk/client/tx" - - "github.com/cosmos/cosmos-sdk/version" - authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli" - bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli" - - "github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template/app" - "github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template/types" -) - -// rootCmd is the entry point for this binary -var ( - rootCmd = &cobra.Command{ - Use: "myawesomeprojectcli", - Short: "MyAwesomeProject light-client", - } -) - -func main() { - // disable sorting - cobra.EnableCommandSorting = false - - // get the codec - cdc := app.MakeCodec() - - // TODO: setup keybase, viper object, etc. to be passed into - // the below functions and eliminate global vars, like we do - // with the cdc - - // add standard rpc, and tx commands - rpc.AddCommands(rootCmd) - rootCmd.AddCommand(client.LineBreak) - tx.AddCommands(rootCmd, cdc) - rootCmd.AddCommand(client.LineBreak) - - // add query/post commands (custom to binary) - // start with commands common to basecoin - rootCmd.AddCommand( - client.GetCommands( - authcmd.GetAccountCmd("acc", cdc, types.GetAccountDecoder(cdc)), - )...) - rootCmd.AddCommand( - client.PostCommands( - bankcmd.SendTxCmd(cdc), - )...) - // and now myawesomeproject specific commands here - - // add proxy, version and key info - rootCmd.AddCommand( - client.LineBreak, - lcd.ServeCommand(cdc), - keys.Commands(), - client.LineBreak, - version.VersionCmd, - ) - - // prepare and add flags - executor := cli.PrepareMainCmd(rootCmd, "BC", os.ExpandEnv("$HOME/.myawesomeprojectcli")) - err := executor.Execute() - if err != nil { - // handle with #870 - panic(err) - } -} diff --git a/cmd/cosmos-sdk-cli/template/cmd/node/main.go b/cmd/cosmos-sdk-cli/template/cmd/node/main.go deleted file mode 100644 index 8a2774430..000000000 --- a/cmd/cosmos-sdk-cli/template/cmd/node/main.go +++ /dev/null @@ -1,69 +0,0 @@ -package main - -import ( - "encoding/json" - "io" - "os" - - "github.com/spf13/cobra" - - abci "github.com/tendermint/tendermint/abci/types" - "github.com/tendermint/tendermint/libs/cli" - dbm "github.com/tendermint/tendermint/libs/db" - "github.com/tendermint/tendermint/libs/log" - tmtypes "github.com/tendermint/tendermint/types" - - "github.com/cosmos/cosmos-sdk/cmd/cosmos-sdk-cli/template/app" - - "github.com/cosmos/cosmos-sdk/server" - "github.com/cosmos/cosmos-sdk/wire" -) - -// init parameters -var MyAwesomeProjectAppInit = server.AppInit{ - AppGenState: MyAwesomeProjectAppGenState, - AppGenTx: server.SimpleAppGenTx, -} - -// GenAppParams sets up the app_state, append any other app specific components. -func MyAwesomeProjectAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (appState json.RawMessage, err error) { - appState, err = server.SimpleAppGenState(cdc, appGenTxs) - if err != nil { - return - } - - return -} - -func newApp(logger log.Logger, db dbm.DB, _ io.Writer) abci.Application { - return app.NewMyAwesomeProjectApp(logger, db) -} - -func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error) { - dapp := app.NewMyAwesomeProjectApp(logger, db) - return dapp.ExportAppStateAndValidators() -} - -func main() { - cdc := app.MakeCodec() - ctx := server.NewDefaultContext() - - rootCmd := &cobra.Command{ - Use: "myawesomeprojectd", - Short: "MyAwesomeProject Daemon (server)", - PersistentPreRunE: server.PersistentPreRunEFn(ctx), - } - - server.AddCommands(ctx, cdc, rootCmd, MyAwesomeProjectAppInit, - server.ConstructAppCreator(newApp, "myawesomeproject"), - server.ConstructAppExporter(exportAppStateAndTMValidators, "myawesomeproject")) - - // prepare and add flags - rootDir := os.ExpandEnv("$HOME/.myawesomeprojectd") - executor := cli.PrepareBaseCmd(rootCmd, "BC", rootDir) - err := executor.Execute() - if err != nil { - // handle with #870 - panic(err) - } -} diff --git a/cmd/cosmos-sdk-cli/template/types/account.go b/cmd/cosmos-sdk-cli/template/types/account.go deleted file mode 100644 index 211aef2cf..000000000 --- a/cmd/cosmos-sdk-cli/template/types/account.go +++ /dev/null @@ -1,77 +0,0 @@ -package types - -import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/wire" - "github.com/cosmos/cosmos-sdk/x/auth" -) - -var _ auth.Account = (*AppAccount)(nil) - -// Custom extensions for this application. This is just an example of -// extending auth.BaseAccount with custom fields. -// -// This is compatible with the stock auth.AccountStore, since -// auth.AccountStore uses the flexible go-amino library. -type AppAccount struct { - auth.BaseAccount - Name string `json:"name"` -} - -// Constructor for AppAccount -func ProtoAppAccount() auth.Account { - return &AppAccount{} -} - -// nolint -func (acc AppAccount) GetName() string { return acc.Name } -func (acc *AppAccount) SetName(name string) { acc.Name = name } - -// Get the AccountDecoder function for the custom AppAccount -func GetAccountDecoder(cdc *wire.Codec) auth.AccountDecoder { - return func(accBytes []byte) (res auth.Account, err error) { - if len(accBytes) == 0 { - return nil, sdk.ErrTxDecode("accBytes are empty") - } - acct := new(AppAccount) - err = cdc.UnmarshalBinaryBare(accBytes, &acct) - if err != nil { - panic(err) - } - return acct, err - } -} - -//___________________________________________________________________________________ - -// State to Unmarshal -type GenesisState struct { - Accounts []*GenesisAccount `json:"accounts"` -} - -// GenesisAccount doesn't need pubkey or sequence -type GenesisAccount struct { - Name string `json:"name"` - Address sdk.AccAddress `json:"address"` - Coins sdk.Coins `json:"coins"` -} - -func NewGenesisAccount(aa *AppAccount) *GenesisAccount { - return &GenesisAccount{ - Name: aa.Name, - Address: aa.Address, - Coins: aa.Coins.Sort(), - } -} - -// convert GenesisAccount to AppAccount -func (ga *GenesisAccount) ToAppAccount() (acc *AppAccount, err error) { - baseAcc := auth.BaseAccount{ - Address: ga.Address, - Coins: ga.Coins.Sort(), - } - return &AppAccount{ - BaseAccount: baseAcc, - Name: ga.Name, - }, nil -} diff --git a/tools/Makefile b/tools/Makefile index 5dfbd08fa..d58f52d1b 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -13,7 +13,6 @@ MISSPELL = github.com/client9/misspell/cmd/misspell ERRCHECK = github.com/kisielk/errcheck UNPARAM = mvdan.cc/unparam GOCYCLO = github.com/alecthomas/gocyclo -PACKR = github.com/gobuffalo/packr DEP_CHECK := $(shell command -v dep 2> /dev/null) GOLINT_CHECK := $(shell command -v golint 2> /dev/null) @@ -24,7 +23,6 @@ MISSPELL_CHECK := $(shell command -v misspell 2> /dev/null) ERRCHECK_CHECK := $(shell command -v errcheck 2> /dev/null) UNPARAM_CHECK := $(shell command -v unparam 2> /dev/null) GOCYCLO_CHECK := $(shell command -v gocyclo 2> /dev/null) -PACKR_CHECK := $(shell command -v packr 2> /dev/null) check_tools: ifndef DEP_CHECK @@ -72,11 +70,6 @@ ifndef GOCYCLO_CHECK else @echo "Found gocyclo in path." endif -ifndef PACKR_CHECK - @echo "No packr in path. Install with make get_tools'." -else - @echo "Found packr in path." -endif get_tools: ifdef DEP_CHECK @@ -133,12 +126,6 @@ else @echo "Installing goyclo" go get -v $(GOCYCLO) endif -ifdef PACKR_CHECK - @echo "Packr is already installed. Run 'make update_tools' to update." -else - @echo "$(ansi_grn)Installing packr$(ansi_end)" - go get -v $(PACKR) -endif update_tools: @echo "Updating dep" @@ -159,8 +146,6 @@ update_tools: go get -u -v $(UNPARAM) @echo "Updating goyclo" go get -u -v $(GOCYCLO) - @echo "Updating packr" - go get -u -v $(PACKR) # To avoid unintended conflicts with file names, always add to .PHONY # unless there is a reason not to.