无法构建 “chaintool/example02″。

huangapple go评论87阅读模式
英文:

Cannot build "chaintool/example02"

问题

我正在尝试按照Chaincode Development Environment上的说明在我的本地环境中设置Hyperledger。

不幸的是,我对golang完全不熟悉。当我在构建"chaintool/example02"时遇到错误时,我不知道如何进一步处理 - 我应该忽略这个问题还是首先修复一些东西?例如,运行带有一些选项的make命令等...我如何获取缺少的导入?

输出如下所示:

hyper-00:chaincode hyper$ pwd
/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/examples/chaincode/chaintool/example02/src/chaincode

hyper-00:chaincode hyper$ go build ./
chaincode_example02.go:24:2: 找不到包"hyperledger/cci/appinit"在任何地方:
/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/cci/appinit (vendor tree)
/usr/local/go/src/hyperledger/cci/appinit (from $GOROOT)
/Users/hyper/Projects/blockchain/src/hyperledger/cci/appinit (from $GOPATH)
chaincode_example02.go:25:2: 找不到包"hyperledger/cci/org/hyperledger/chaincode/example02"在任何地方:
/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/cci/org/hyperledger/chaincode/example02 (vendor tree)
/usr/local/go/src/hyperledger/cci/org/hyperledger/chaincode/example02 (from $GOROOT)
/Users/hyper/Projects/blockchain/src/hyperledger/cci/org/hyperledger/chaincode/example02 (from $GOPATH)
chaincode_example02.go:26:2: 找不到包"hyperledger/ccs"在任何地方:
/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/ccs (vendor tree)
/usr/local/go/src/hyperledger/ccs (from $GOROOT)
/Users/hyper/Projects/blockchain/src/hyperledger/ccs (from $GOPATH)
hyper-00:chaincode hyper$

我的$GOPATH是:

hyper-00:~ hyper$ echo $GOPATH
/Users/hyper/Projects/blockchain


**[2017-01-02编辑]**

我再次重复了克隆存储库的过程。
我认为我的错误是从GitHub上拉取了错误的源代码 - 可能是"master"而不是"v0.6"。

我所做的并且现在编译工作正常的是:

$ sudo apt install golang-go

$ gedit .profile

export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/Projects/blockchain

$ . ~/.profile

$ mkdir -p $GOPATH/src/github.com/hyperledger/

$ cd $GOPATH/src/github.com/hyperledger

$ git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric

$ cd ~/Projects/blockchain/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

$ go build

英文:

I am trying to follow instructions on Chaincode Development Environment to setup hyperledger in my local environment.

Unfortunately, I am completely new to golang. When I come across an error trying to build "chaintool/example02" I have no idea how to proceed further - should I ignore the issue or first I should fix something? For example, to run make with some options, etc ... How can I get missing imports ?

The output looks as follows:

hyper-00:chaincode hyper$ pwd
 /Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/examples/chaincode/chaintool/example02/src/chaincode

hyper-00:chaincode hyper$ go build ./
    chaincode_example02.go:24:2: cannot find package "hyperledger/cci/appinit" in any of:
    	/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/cci/appinit (vendor tree)
    	/usr/local/go/src/hyperledger/cci/appinit (from $GOROOT)
    	/Users/hyper/Projects/blockchain/src/hyperledger/cci/appinit (from $GOPATH)
    chaincode_example02.go:25:2: cannot find package "hyperledger/cci/org/hyperledger/chaincode/example02" in any of:
    	/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/cci/org/hyperledger/chaincode/example02 (vendor tree)
    	/usr/local/go/src/hyperledger/cci/org/hyperledger/chaincode/example02 (from $GOROOT)
    	/Users/hyper/Projects/blockchain/src/hyperledger/cci/org/hyperledger/chaincode/example02 (from $GOPATH)
    chaincode_example02.go:26:2: cannot find package "hyperledger/ccs" in any of:
    	/Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/vendor/hyperledger/ccs (vendor tree)
    	/usr/local/go/src/hyperledger/ccs (from $GOROOT)
    	/Users/hyper/Projects/blockchain/src/hyperledger/ccs (from $GOPATH)
hyper-00:chaincode hyper$ 

My $GOPATH gives:

hyper-00:~ hyper$ echo $GOPATH 
/Users/hyper/Projects/blockchain

<hr>
[EDITED on 2017-01-02]

I repeated the repo cloning procedure again.
I think my mistake was I pulled a wrong source from GitHub - probably "master", not "v0.6".

What I did and the compilation works now is:

$ sudo apt install golang-go

$ gedit .profile
    
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/Projects/blockchain    

$ . ~/.profile

$ mkdir -p $GOPATH/src/github.com/hyperledger/

$ cd $GOPATH/src/github.com/hyperledger

$ git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric

$ cd ~/Projects/blockchain/src/github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02 

$ go build

答案1

得分: 2

github.com/hyperledger/fabric 应该在其 vendor/ 文件夹中包含所有这些依赖项,或者将示例放在自己的存储库中,并带有一个 vendor 文件夹,所以这看起来是他们的问题而不是你的问题。

你可以通过运行 go get x y z 来修复它,以获取所有缺失的包,或者尝试使用一个 vendoring 工具来获取它们。

有很多 vendoring 的选项,但直到明年才有“官方”选项。我更喜欢 govendor。我还没有尝试过这个特定的存储库,但你可以尝试以下命令:

go get -u github.com/kardianos/govendor
cd /Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/
govendor fetch -v +missing
英文:

github.com/hyperledger/fabric should have included all these dependencies in its vendor/ folder or put the examples in their own repo with a vendor folder, so this looks like their problem not yours.

You can fix it by running go get x y z for all missing packages, or try using a vendoring tool to get them.

There are many options for vendoring but no "official" option until next year. I prefer govendor. i havent tried it with this particular repo but you can try with:

go get -u github.com/kardianos/govendor
cd /Users/hyper/Projects/blockchain/src/github.com/hyperledger/fabric/
govendor fetch -v +missing

答案2

得分: 2

HyperLedger团队提供了非常好的文档,介绍了如何使用chaintool来记录API(通过链码接口,即CCI)。没有这个,链码的使用者必须检查源代码才能理解如何组合REST调用。这是一个很好的想法。

构建链码的这种方法要求您在$GOPATH中的github.com/hyperledger/fabric旁边下载github.com/hyperledger/cci和github.com/hyperledger/ccs。不幸的是,我没有看到可以下载这些的任何存储库(无论是在github还是gerrit上)。

此外,到目前为止,我只看到了一个使用chaintool与cci和ccs的示例,即chaintool/example02...但由于缺少hyperledger包,它无法编译。

关于支持cci/ccs的chaintool的文档位于以下位置:

但似乎这份文档已被复制到以下位置,并从'chaintool'重命名为'openblockchain compiler'(或OBCC),并标记为'work in progress':

因此,我倾向于认为chaintool/example02不是目前支持的构建链码的方法...至少在OBCC正式可用之前是这样的。

英文:

The HyperLedger team has provided very good documentation on how to use chaintool in a manner that allows users to document APIs (via Chain Code Interface, or CCI). Without this, consumers of a chaincode must inspect source code to understand how to compose a REST invocation. Great idea.

This approach to building chaincode requires you download github.com/hyperledger/cci and github.com/hyperledger/ccs to reside next to github.com/hyperledger/fabric within your $GOPATH. Unfortunately, I don't see any repository (on either github or gerrit) where this can be downloaded.

Further, I've only seen one example (thus far) of how to use chaintool with cci and ccs, which is chaintool/example02... and it does not compile due to these missing hyperledger packages.

There is documentation on chaintool with cci/ccs support at the following location:

But it seems this documentation has been copied to the following location and renamed from 'chaintool' to 'openblockchain compiler' (or OBCC) and labeled as a 'work in progress':

As such, I am inclined to believe the chaintool/example02 is not a currently supported approach to building chaincode... at least until OBCC becomes officially available.

huangapple
  • 本文由 发表于 2016年12月22日 04:46:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/41271614.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定