Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

undefined: shim.ChaincodeStubInterface deploying chaincode #29

Closed
dselman opened this issue Sep 2, 2016 · 21 comments
Closed

undefined: shim.ChaincodeStubInterface deploying chaincode #29

dselman opened this issue Sep 2, 2016 · 21 comments

Comments

@dselman
Copy link

dselman commented Sep 2, 2016

Following the "How to Write Chaincode" tutorial I am getting local Go compile errors. When these errors are fixed by replacing references to 'stub *shim.ChaincodeStub' with 'stub shim.ChaincodeStubInterface' the chaincode fails to deploy on the server.

curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d " {
"jsonrpc": "2.0",
"method": "deploy",
"params": {
"type": 1,
"chaincodeID": {
"path": "https://github.com/dselman/chaincode/start\"
},
"ctorMsg": {
"function": "init",
"args": [
"a",
"10",
"b",
"5"
]
},
"secureContext": "user_type1_620a5fb1bf"
},
"id": 2
}" "https://70ef4b7e-f88e-49f3-89aa-dc6f176d7f7b_vp1.us.blockchain.ibm.com:443/chaincode"

Response Body:
{
"jsonrpc": "2.0",
"error": {
"code": -32001,
"message": "Deployment failure",
"data": "Error when deploying chaincode: Error getting chaincode package bytes: Error getting code 'go get' failed with error: 'exit status 2'\n# github.com/dselman/chaincode/start\n/go/usercode/509999092/src/github.com/dselman/chaincode/start/chaincode_start.go:37: undefined: shim.ChaincodeStubInterface\n/go/usercode/509999092/src/github.com/dselman/chaincode/start/chaincode_start.go:74: undefined: shim.ChaincodeStubInterface\n/go/usercode/509999092/src/github.com/dselman/chaincode/start/chaincode_start.go:133: undefined: shim.ChaincodeStubInterface\n/go/usercode/509999092/src/github.com/dselman/chaincode/start/chaincode_start.go:150: undefined: shim.ChaincodeStubInterface\n"
},
"id": 2
}

@dselman
Copy link
Author

dselman commented Sep 2, 2016

@dselman
Copy link
Author

dselman commented Sep 2, 2016

Also note that the Demo Chaincode in the web GUI is using a mixture of imports and shim definitions:

  1. Example02 uses github.com/hyperledger/fabric/core/chaincode/shim and ChaincodeStubInterface
  2. Marbles uses github.com/hyperledger/fabric/core/chaincode/shim and stub *shim.ChaincodeStub
  3. Commercial Paper uses github.com/openblockchain/obc-peer/openchain/chaincode/shim and stub *shim.ChaincodeStub

@fjblau
Copy link

fjblau commented Sep 4, 2016

I am getting the same errors from the IBM Bluemix tutorial. One doesn't compile and the other doesn't deploy.

Any help?

@mastersingh24
Copy link

@dselman - unfortunately, we find ourselves in a tricky situation where the interface definitions for chaincode are different between the version deployed in Bluemix (v0.5-developer-preview) and the master branch currently mirrored in Github from Gerrit. So if you try to compile locally using the current version from Github you won't be able to deploy that to Bluemix and vice versa.

If you want to deploy to Bluemix, you can clone the archive repo (https://github.com/hyperledger-archives/fabric) into your local $GOPATH/src/github.com/hyperledger/fabric and checkout the v0.5-developer-preview branch

@mastersingh24
Copy link

oh - and we actually do use the same shim in all the samples - it is just not 100% obvious which versions of the samples we are using:

  1. commercial paper - https://github.com/IBM-Blockchain/cp-chaincode-v2/tree/master/hyperledger
  2. marbles - https://github.com/IBM-Blockchain/marbles-chaincode/tree/master/hyperledger
  3. Example02 - https://github.com/masterDev1985/hyperledger_chaincode/blob/master/chaincode_example02/chaincode_example02.go (I think)

@dselman
Copy link
Author

dselman commented Sep 5, 2016

Thanks @mastersingh24 -- that worked.

@l2fprod
Copy link

l2fprod commented Sep 6, 2016

@mastersingh24

Will the examples be updated? The out-of-box experience is broken for all new users.

https://github.com/IBM-Blockchain/learn-chaincode/issues/22
https://github.com/IBM-Blockchain/learn-chaincode/issues/19

@dshuffma-ibm
Copy link
Contributor

dshuffma-ibm commented Sep 9, 2016

we have a dilemma. if we accept the change it will break deploying to a bluemix network since those use an older hyperledger version. if we don't accept the change then it will break when deploying to a network using the latest hyperledger version.

we have a few options.

  • setup a new repo for learn chaincode that uses the latest shim
  • create a folder for each version in the learn-chaincode repo
  • tag the current version, accept the changes, tag again and direct people to specific tags from the documentation
  • wait for the bluemix networks to catch up and merge the change then

we are open to community feedback and any other ideas.

@portegys
Copy link

Trying this advice:

If you want to deploy to Bluemix, you can clone the archive repo (https://github.com/hyperledger->archives/fabric) into your local $GOPATH/src/github.com/hyperledger/fabric and checkout the v0.5->developer-preview branch

Forked the above and checked out the branch.
Then tried this go get:
~/Documents/GoProjects/fabric> go get github.com/hyperledger-archives/fabric/core/chaincode/shim

github.com/hyperledger-archives/fabric/core/chaincode/shim

..\src\github.com\hyperledger-archives\fabric\core\chaincode\shim\chaincode.go:107: cannot use clientConn (type *"github.com/hyperledger-archives/fabric/vendor/google.golang.org/grpc".ClientConn) as type *"github.com/hyperledger/fabric/vendor/google.golang.org/grpc".ClientConn in argument to protos.NewChaincodeSupportClient

The go build also fails with:
~/Documents/GoProjects/learn-chaincode/start> go build ./

/C/Users/porteto/Documents/GoProjects/learn-chaincode/start

.\chaincode_start.go:34: cannot use new(SimpleChaincode) (type _SimpleChaincode) as type shim.Chaincode in argument to shim.Start:
*SimpleChaincode does not implement shim.Chaincode (wrong type for Init method)
have Init(_shim.ChaincodeStub, string, []string) ([]byte, error)
want Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)

@kristofer
Copy link

yeah, I gotta say, spending 3 hours digging around looking for a way to understand just what the difference was, I'm dismayed that there isn't some way to change this with some kind of dependency management. If this bites us, now, here with a simple example (trying to show us how easy it is to develop chaincode and deploy it) - well, what will it be like when a real world app (which are usually significantly more complex than these examples) runs afoul of these types of version mismatches? shouldn't there be a "version": "1.1" line someplace??

@dshuffma-ibm
Copy link
Contributor

dshuffma-ibm commented Sep 15, 2016

package managers for golang do exist and it's absolutely the correct long term solution. I agree with you that this is a real world problem that we need to resolve sooner rather than later. the real challenge is to coordinate and align on a single solution. we need the changes to occur in the Hyperledger fabric.

@dyancl
Copy link

dyancl commented Sep 26, 2016

@portegys I had the same issue before. You have to use "$GOPATH/src/github.com/hyperledger/fabric" directory, instead of "hyperledger-archives".

@MHamza81
Copy link

@dyancl I did the same thing, replaced "hyperledger-archives" with "hyperledger" but ended up with this error:
.\chaincode_start.go:41: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:50: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:63: undefined: shim.ChaincodeStubInterface

If you have solved this issue kindly tell me how to do it.

@bouoth
Copy link

bouoth commented Nov 2, 2016

Did the same as you did MHamza81 and got the same errors
if you build with the shim from Hyperledger you get these errors

.\chaincode_start.go:41: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:50: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:63: undefined: shim.ChaincodeStubInterface

and if you use the shim from hyperledger-archives you get
.\chaincode_start.go:34: cannot use new(SimpleChaincode) (type SimpleChaincode) as type shim.Chaincode in argument to shim.Start:
*SimpleChaincode does not implement shim.Chaincode (wrong type for Init method)
have Init(shim.ChaincodeStub, string, []string) ([]byte, error)
want Init(shim.ChaincodeStubInterface, string, []string) ([]byte, error)

The chaincode.go file are different in hyperledger and hyperledger-archives

@masterDev1985
Copy link

@bouoth you are correct. There are differences between the various releases of the fabric. See these instructions for installing the correct version of the fabric on your machine:
https://github.com/IBM-Blockchain/learn-chaincode/blob/master/docs/setup.md#hyperledger-fabric

@bouoth
Copy link

bouoth commented Nov 2, 2016

Thanks Dale Avery !


From: Dale Avery notifications@github.com
Sent: Wednesday, November 2, 2016 6:18 PM
To: IBM-Blockchain/ibm-blockchain-issues
Cc: bouoth; Mention
Subject: Re: [IBM-Blockchain/ibm-blockchain-issues] undefined: shim.ChaincodeStubInterface deploying chaincode (#29)

@bouothhttps://github.com/bouoth you are correct. There are differences between the various releases of the fabric. See these instructions for installing the correct version of the fabric on your machine:
https://github.com/IBM-Blockchain/learn-chaincode/blob/master/docs/setup.md#hyperledger-fabric

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/29#issuecomment-257953650, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWC8zPN5F-1HL9GwBPGTKOjd9HhRijDuks5q6NPjgaJpZM4Jzne0.

@masterDev1985
Copy link

Happy to help!

@subhahari
Copy link

I was using 0.5 release (git clone -b v0.5-developer-preview https://github.com/hyperledger-archives/fabric.git) and I had also got below error:
.\chaincode_start.go:41: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:50: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:63: undefined: shim.ChaincodeStubInterface

I used 0.6 release (git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric) and now am able to compile chaincode successfully.

@bouoth
Copy link

bouoth commented Nov 3, 2016

Thank you ! Ill try v6.0

Envoy? de mon iPhone

Le 3 nov. 2016 ? 14:32, subhahari <notifications@github.commailto:notifications@github.com> a ?crit :

I was using 0.5 release (git clone -b v0.5-developer-preview https://github.com/hyperledger-archives/fabric.git) and I had also got below error:
.\chaincode_start.go:41: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:50: undefined: shim.ChaincodeStubInterface
.\chaincode_start.go:63: undefined: shim.ChaincodeStubInterface

I used 0.6 release (git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric) and now am able to compile chaincode successfully.

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://github.com//issues/29#issuecomment-258158924, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AWC8zH2g9JHaYc0yox5bzhwpRPqeLWBGks5q6fB4gaJpZM4Jzne0.

@hcc0311
Copy link

hcc0311 commented May 20, 2017

git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric ,Not Found What should I do?

@masterDev1985
Copy link

@hcc0311 try again. I was able to clone that branch:

$ git clone -b v0.6 http://gerrit.hyperledger.org/r/fabric
Cloning into 'fabric'...
warning: redirecting to https://gerrit.hyperledger.org/r/fabric/
remote: Counting objects: 4114, done
remote: Finding sources: 100% (32/32)
remote: Total 37297 (delta 2), reused 37277 (delta 2)
Receiving objects: 100% (37297/37297), 52.73 MiB | 758.00 KiB/s, done.
Resolving deltas: 100% (17732/17732), done.

If that doesn't work for you, post the error you are seeing.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests