Cosmos-- 三.教程 -- 14.编译你的程序

cosmos主网即将上线,对文档做了大量更新。特地翻译了一下,方便小伙伴们阅览, 之后会持续更新

第三章教程:

  1. 开始
  2. 程序目标
  3. 开始编写你的程序
  4. Keeper
  5. Msg和Handler
  6. SetName
  7. BuyName
  8. Querier
  9. Codec文件
  10. Nameservice模块的CLI
  11. nameservice模块的REST接口
  12. 引入你的模块并完成程序
  13. Entrypoint
  14. 编译你的程序
  15. 编译并运行程序
  16. 运行REST路由

编译你的程序

Makefile

通过在根目录中编写包含常用命令的./Makefile来帮助用户编译应用程序:

注意:下面的Makefile包含一些与Cosmos SDK和Tendermint的Makefiles相同的命令。

DEP := $(shell command -v dep 2> /dev/null)

get_tools:
ifndef DEP
    @echo "Installing dep"
    go get -u -v github.com/golang/dep/cmd/dep
else
    @echo "Dep is already installed..."
endif

get_vendor_deps:
    @echo "--> Generating vendor directory via dep ensure"
    @rm -rf .vendor-new
    @dep ensure -v -vendor-only

update_vendor_deps:
    @echo "--> Running dep ensure"
    @rm -rf .vendor-new
    @dep ensure -v -update

install:
    go install ./cmd/nsd
    go install ./cmd/nscli

Gopkg.toml

Golang有一些依赖管理工具。在本教程中,你将使用depdep使用仓库根目录中的Gopkg.toml文件来定义应用程序所需的依赖项。Cosmos SDK应用程序目前依赖于某些库的特定版本。以下列表包含所有必需的版本。首先使用下面的constraintsoverrides项替换./Gopkg.toml文件的内容:

# Gopkg.toml example
#
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
# 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/cosmos/cosmos-sdk"
  version = "v0.31.1"

[[override]]
  name = "github.com/golang/protobuf"
  version = "=1.1.0"

[[constraint]]
  name = "github.com/spf13/cobra"
  version = "~0.0.1"

[[constraint]]
  name = "github.com/spf13/viper"
  version = "~1.0.0"

[[override]]
  name = "github.com/tendermint/go-amino"
  version = "v0.14.1"

[[override]]
  name = "github.com/tendermint/iavl"
  version = "v0.12.0"

[[override]]
  name = "github.com/tendermint/tendermint"
  version = "v0.30.0-rc0"

[[override]]
  name = "golang.org/x/crypto"
  source = "https://github.com/tendermint/crypto"
  revision = "3764759f34a542a3aef74d6b02e35be7ab893bba"

[[override]]
  name = "github.com/otiai10/copy"
  revision = "7e9a647135a142c2669943d4a4d29be015ce9392"

[[override]]
  name = "github.com/btcsuite/btcd"
  revision = "ed77733ec07dfc8a513741138419b8d9d3de9d2d"

[prune]
  go-tests = true
  unused-packages = true

注意:如果你再你自己的仓库重头开始编写项目,请确定在运行dep ensure -v之前你已经导入路径github.com/cosmos/sdk-application-tutorial替换成你自己的整个仓库(可能是github.com/{.Username}/{.Project.Repo})。如果不这样做,则需要在再次运行dep ensure -v之前删除./vendor目录(rm -rf ./vendor)以及Gopkg.lock文件(rm Gopkg.lock)。

既然已经完成了这项管理工作,是时候安装dep以及项目依赖:

make get_tools
dep ensure -v

编译应用程序

# Update dependencies to match the constraints and overrides above
dep ensure -update -v

# Install the app into your $GOBIN
make install

# Now you should be able to run the following commands:
nsd help
nscli help

你可能感兴趣的:(Cosmos-- 三.教程 -- 14.编译你的程序)