Skip to content
This repository has been archived by the owner on Dec 22, 2021. It is now read-only.

updating import links for shim and peer package #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

oscillator25
Copy link

The shim and peer protobuf modules are no longer vendored automatically by Fabric, so they are needed to vendor individually otherwise they lead to the issue as depicted in the attached screenshot.

chaincode_go_import-error

The shim and peer protobuf modules are no longer vendored automatically by Fabric, so they are needed to vendor individually.
@harishkgithub
Copy link

@oscillator25
I am running into similar issue may if know got this issue fixed just by replacing the import statement?
or did you any additional installation?
Because I tried
"go get" it did not work

@oscillator25
Copy link
Author

oscillator25 commented Aug 31, 2021

@harishkgithub
The problem is mainly due to the import path of shim and peer package files since they have been moved to a separate repository(links for both of them are included below):
shim package repository: https://github.com/hyperledger/fabric-chaincode-go
peer package repository: https://github.com/hyperledger/fabric-protos-go

You can either individually include the required files during your local environment configuration or use the updated path in the chaincode. For me, things worked fine thereafter. If I can be of any other help, please feel free to reach out by replying to this thread.

P.S.: "go get" didn't worked for the same reason that the required shim and peer packages have been moved to separate locations.

@harishkgithub
Copy link

harishkgithub commented Aug 31, 2021

@oscillator25

Thanks for explanation but just an observation

1)I had upgrade go to 1.17 with this I am able to package successfully with current import statements itself
"github.com/hyperledger/fabric/core/chaincode/shim"
sc "github.com/hyperledger/fabric/protos/peer"

but when I try to deploy I get the below exception in VS code

Failed to install on peer Org1 Peer with reason: Could not install smart contact received error: failed with status:500 ::failed to invoke backing implementation of 'InstallChaincode': could not build chaincode: external builder failed: external builder ```

failed to build: external builder 'golang' failed: exit status 1

my go.mod

Mac src % cat go.mod
module chaincode

go 1.17

require (
	github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
	github.com/hyperledger/fabric-protos-go v0.0.0-20210720123151-f0dc3e2a0871
)

require (
	github.com/go-sql-driver/mysql v1.6.0 // indirect
	github.com/golang/protobuf v1.5.2 // indirect
	golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
	golang.org/x/mod v0.4.2 // indirect
	golang.org/x/net v0.0.0-20210825183410-e898025ed96a // indirect
	golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
	golang.org/x/text v0.3.7 // indirect
	golang.org/x/tools v0.1.5 // indirect
	golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
	google.golang.org/genproto v0.0.0-20210831024726-fe130286e0e2 // indirect
	google.golang.org/grpc v1.40.0 // indirect
	google.golang.org/protobuf v1.27.1 // indirect
)

2)I tried to package again using your suggestions for import statements

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

same observation able to package successfully [ ".tar.gz" ]
but failed during deployment

I tried deleting "go.mod" file, it brought back me to old issue of "compiler errors"
I am using Vs Code extension "IBM Blockchain Platform" - "v2.0.4"

I guess with go.mod file and 1.17 version even the current code is not throwing exception
guess somehow the below from go.mod is mapping

require (
	github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
	github.com/hyperledger/fabric-protos-go v0.0.0-20210720123151-f0dc3e2a0871
)

Please tell me if my conclusions are correct?
Is there anything wrong in my approach?
How to fix the deploy error If you know

Thanks in advance

@harishkgithub
Copy link

harishkgithub commented Sep 21, 2021

@oscillator25

Ignore my previous comment

I re-tried from scratch using this PR fix following helped create package without errors

Prequsite:
While inside "modfriday" folder this is the folder where I have kept my chaincode
Along with the changes I had to do

  1. go mod init
  2. go build crowdfunding.go
    we will see the below issue
MacBook-Pro modfriday % go build crowdfunding.go
crowdfunding.go:15:2: no required module provides package github.com/hyperledger/fabric-chaincode-go/shim; to add it:
        go get github.com/hyperledger/fabric-chaincode-go/shim
crowdfunding.go:16:2: no required module provides package github.com/hyperledger/fabric-protos-go/peer; to add it:
        go get github.com/hyperledger/fabric-protos-go/peer
MacBook-Pro modfriday % 
  1. Then we should do
    i) go get github.com/hyperledger/fabric-chaincode-go/shim
    Output:
MacBook-Pro modfriday % go get github.com/hyperledger/fabric-chaincode-go/shim
go get: added github.com/golang/protobuf v1.3.2
go get: added github.com/hyperledger/fabric-chaincode-go v0.0.0-20210718160520-38d29fabecb9
go get: added github.com/hyperledger/fabric-protos-go v0.0.0-20190919234611-2a87503ac7c9
go get: added golang.org/x/net v0.0.0-20190522155817-f3200d17e092
go get: added golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542
go get: added golang.org/x/text v0.3.0
go get: added google.golang.org/genproto v0.0.0-20180831171423-11092d34479b
go get: added google.golang.org/grpc v1.23.0

ii) go get github.com/hyperledger/fabric-protos-go/peer
Output:

MacBook-Pro modfriday %  go get github.com/hyperledger/fabric-protos-go/peer
go: downloading github.com/hyperledger/fabric-protos-go v0.0.0-20210910071102-480345259e49
go get: upgraded github.com/hyperledger/fabric-protos-go v0.0.0-20190919234611-2a87503ac7c9 => v0.0.0-20210910071102-480345259e49
MacBook-Pro modfriday % 

4)Open VsCode at the directory where "crowdfunding.go" is present
using "IBM BLOCKCHAIN PLATFORM"
Under "SMART CONTRACTS" -> "Package Open project"
We will be prompted for
"tar.gz(V2 channel capabilities" and
"cds(V1 channel capabilities"
i)I selected "tar.gz(V2 channel capabilities" because our ibm blockchain platform extension is v2.0.4
ii) Enter package name "modfriday"
press enter key
Enter version for our package "1.0"
press enter key
we will have our package "[email protected] (tar,gz)" under "SMART CONTRACTS"

I am completely new to "go" and "blockchain" hence then lengthy post :-( hope it helps someone like me

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

Successfully merging this pull request may close these issues.

3 participants