美文网首页区块链
Cosmos编译安装

Cosmos编译安装

作者: 印随2018 | 来源:发表于2018-11-13 15:45 被阅读55次

    关注:Cosmos的编译环境

    下面是源码编译gaia的步骤(需要首先安装GO环境)

    export GO111MODULE=on
    
    go get github.com/cosmos/cosmos-sdk
    cd go/src/github.com/cosmos/
    git checkout -b 0.26.1-rc1 v0.26.1-rc1
    
    go mod init
    go build ./cmd/gaia/cmd/gaiad
    go build ./cmd/gaia/cmd/gaiacli
    

    大多数情况下,你会看到下面这个错误信息

    # github.com/cosmos/cosmos-sdk/crypto/keys/mintkey
    crypto/keys/mintkey/mintkey.go:108:41: too many arguments in call to bcrypt.GenerateFromPassword
        have ([]byte, []byte, int)
        want ([]byte, int)
    crypto/keys/mintkey/mintkey.go:142:41: too many arguments in call to bcrypt.GenerateFromPassword
        have ([]byte, []byte, int)
        want ([]byte, int)
    

    仔细一看,明显是cosmos里的代码用错了,但是再想想,cosmos团队会犯这种低级错误么,肯定是自己的编译环境有问题。纠结许久😖。后来发现,因为cosmos源码是使用godep来管理代码依赖的,但我们这里却是使用gomodule,是不是配置文件转换过程中出现了问题。

    仔细看了Gopkg.toml,发现下面一段配置

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

    含义是重定向依赖的项目名称,但是没有自动添加到go.mod里,我们手动添加下面一行配置到go.mod里就可以了

    replace golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd => github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
    

    需要注意的是,项目的版本号一定要和go.mod里的内容一致。


    cosmos团队可能在github.com/tendermint/crypt加了一些新的特性,所以没有使用google原生的代码,但是在源码中的import依然还是使用了golang.org/x/crypto的路径,这个挺坑的☹

    相关文章

      网友评论

        本文标题:Cosmos编译安装

        本文链接:https://www.haomeiwen.com/subject/xwtlfqtx.html