3

I worked out the solution to this problem as I was creating this post but figured I'd leave my trail of tears up here to maybe help other people who have run into the same thing. Ultimately the root of the problem was outdated instructions in the tutorial, not reflecting changes to the underlying repositories.

I am working from this page: https://hyperledger-fabric.readthedocs.io/en/release-1.4/chaincode4ade.html

My environment: - Ubuntu 18.04 Server (running as VM in virtualbox) - go version 1.13.5 - working directory: /home/fabric-1/go/src/sacc - $GOPATH: /home/fabric-1/go

also in /home/fabric-1/go/src I have cloned fabric with:

git clone https://github.com/hyperledger/fabric.git

In my ~/go/source/sacc directory I have written the file according to instructions with the following imports:

import (
    "fmt"

    "github.com/hyperledger/fabric/core/chaincode/shim"
    "github.com/hyperledger/fabric/protos/peer"
)

So when I first ran the command

go get -u github.com/hyperledger/fabric/core/chaincode/shim

I got an error stating it could not find the package "shim". I did a "find" command on the github.com directory and found that it was there, but in a strange place, I tried moving the shim directory to someplace friendly, that resulted in the usual rabbit-hole frenzy when you do something like that ...

After spending a day mucking about, trying to install shim code from other places, it finally dawned on me (duh!) to change the import statement for shim:

import (
    "fmt"

    "github.com/hyperledger/fabric/vendor/github.com/hyperledger/fabric-chaincode-go/shim"
    "github.com/hyperledger/fabric/protos/peer"
)

After this, 'go get' worked find, but 'go build' failed - couldn't find 'peer' (sigh)

After a lunch break (and resisting the temptation to do vodka shots) I figured they re-arranged things since they wrote the tutorial. I looked closer at the paths and saw there were github.com directories under other github.com directories. So back to github (which I am finally not too afraid of), found repositories corresponding to the subdirectories:

https://github.som/hyperledger/fabric/fabric-chaincode-go
https://github.som/hyperledger/fabric/fabric-protos-go

I cloned these into my environment:

cd $GOPATH/src/github.com/hyperledger
git clone https://github.som/hyperledger/fabric/fabric-chaincode-go
git clone https://github.som/hyperledger/fabric/fabric-protos-go

Then I went back again and changed the import statements in my sacc.go code:

import (
    "fmt"

    "github.com/hyperledger/fabric-chaincode-go/shim"
    "github.com/hyperledger/fabric-protos-go/peer"
)

and HEY !!! YEAY !!! the 'go get' and 'go build' commands worked just fine, the compile was successful, and now off to the next problem (well, ok, actually tomorrow - it's dark and cold out, and I think I'll go do that vodka I didn't do earlier).

user55836
  • 31
  • 1

1 Answers1

0

I'm also working from this page.

I got the following error when running go get -u github.com/hyperledger/fabric/core/chaincode/shim command.

package github.com/hyperledger/fabric/core/chaincode/shim: cannot find package "github.com/hyperledger/fabric/core/chaincode/shim" in any of: /usr/local/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOROOT) /home/ubuntu/go/src/github.com/hyperledger/fabric/core/chaincode/shim (from $GOPATH)

I searched "shim" directory from hyperledger github page and noticed the directory path has changed.

Then, I updated releated lines of sacc.go file as follows:

import ( "fmt" "github.com/hyperledger/fabric-chaincode-go/shim" "github.com/hyperledger/fabric-protos-go/peer" )

After the update, go get -u github.com/hyperledger/fabric-chaincode-go/shim and go build worked fine for me.

tolgabuyuktanir
  • 646
  • 6
  • 20
  • 1
    Yes, if you are using "v-latest", that's what you need to do. I think part of my problem is that I was experimenting with two versions, v1.4.4-stable, and v-latest, and got some cross-contamination so I wasn't using a 'pure' version which created problems. – user55836 Jan 16 '20 at 01:13