Issue with Hyperledger fabric go build command - go

package main
import (
"encoding/json"
"fmt"
"strconv"
"github.com/hyperledger/fabric-sdk-go/pkg/client/channel"
"github.com/hyperledger/fabric-sdk-go/pkg/client/event"
"github.com/hyperledger/fabric-sdk-go/pkg/client/ledger"
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
"github.com/hyperledger/fabric-sdk-go/pkg/common/errors/retry"
"github.com/hyperledger/fabric-sdk-go/pkg/common/providers/fab"
"github.com/hyperledger/fabric-sdk-go/pkg/core/config"
"github.com/hyperledger/fabric-sdk-go/pkg/fabsdk"
)
type Degree struct {......
I am new to Blockchain programming and I am trying to build a degree verification application with the help of my friend. We wrote the whole program, Installed/Set Up Hyperledger Fabric, Go on Ubuntu 22.04. When we try to run it using
go build fabric.go (or) go run fabric.go
We get the following error,
fabric.go:7:2: no required module provides package github.com/hyperledger/fabric/core/chaincode/shim; to add it: go get github.com/hyperledger/fabric/core/chaincode/shim fabric.go:8:2: no required module provides package github.com/hyperledger/fabric/protos/peer; to add it: go get github.com/hyperledger/fabric/protos/peer
We tried installing the required Go module dependencies as it suggested and we keep getting
go: module github.com/hyperledger/fabric#upgrade found (v2.1.1+incompatible), but does not contain package github.com/hyperledger/fabric/core/chaincode/shim
and
go: module github.com/hyperledger/fabric#upgrade found (v2.1.1+incompatible), but does not contain package github.com/hyperledger/fabric/protos/peer
I have no idea how to proceed further and I could use your help. Please explain it as if you are explain it to a five year old, because as I said I am new to this and I am not fully versed with all the terms. I am learning fabric by making projects.

I don't really see enough information in your question to see where your problem is occurring and therefore how to solve it. You should not be importing any packages from github.com/hyperledger/fabric/.... This is the core Fabric server implementation and it is not intended to be consumed as a library. Neither the client SDK or chaincode APIs should be importing these packages either, so I am not sure what in your code is referencing them.
If you are just learning Fabric, I would strongly recommend that you use Fabric v2.4 (or later) and use the Fabric Gateway client API to build your client application instead of the legacy Go SDK. Samples linked from that documentation homepage demonstrate how to use the API to build client applications.
The Fabric documentation on client applications describes the key elements of the client application API. The in-line code examples reference the TypeScript sample but there is an identical sample implementation in Go, and the API structure is extremely similar in all the supported client languages, so the tutorial should be useful regardless of your application language.

Related

Hoverfly API Simulations with Golang repositories: how to get started

I have just started to experiment with Hoverfly and I have a Golang backend calling a number of 3rd party APIs for which I would need to create simulations. I am aware that Hoverfly has Java and Py bindings and I have come across a number of tutorials using Hoverfly with both. I think I am possibly missing very trivial point here, once I have created the simulations (via the Capture Mode), what is the next step? Do I simply create integration tests making use of them? Do you import the go package here into my repository? I was looking for some sample usages in the examples folder and I have seen more .py driven ones. Is there any available example that I totally missed out?
Thank you
For Golang testing, you can have a look at the functional tests in the hoverfly project: https://github.com/SpectoLabs/hoverfly/tree/master/functional-tests, it’s using hoverfly to test hoverfly!

Not able to use additional dependencies in AWS lambda function for python

I am building a lambda function to be deployed in a Greengrass core device which has additional dependencies such as NumPy etc. I have followed the instructions provided in official documentation to do so but not able to do it.
I have created a virtual environment, installed all of the dependencies, and compressed all the lib files and directories along with the main code which contains the function handler.
Can anyone help me out regarding this issue?
You should make sure that the hierarchy of your deployed package is correct.
The python dependencies should be in the highest hierarchy level.
My strongest suggestion is to use a framework to deploy your lambdas.
We're using the serverless framework, which has many benefits. In particular, it creates this hierarchy "behind the scene":
https://www.serverless.com/blog/serverless-python-packaging
Disclosure: I'm working for Lumigo, a 3rd party company that helps you to debug your serverless architecture.

How do you deploy a golang google cloud function with a custom go build constraint/tag?

I am using go build constraints to conditionally compile constants into my test/staging/production cloud functions. How can I pass -tags ENV to the builder used by gcloud beta functions deploy?
As #Guilherme mentioned in the comments, indeed, it seems that it's not possible to pass the go constraints/tags to the builder used by Cloud Functions.
I searched around and while there isn't this option, I think indeed, having the option to send constraints to the builder used by Cloud Functions. Considering that, I would recommend you to raise a Feature Request for this to be checked by Google.
One option that you might want to give a look at it, it's deploying your application using Cloud Run. As it's informed in their official documentation about this application:
Use the programming language of your choice, any language or operating system libraries, or even bring your own binaries.
Cloud Run pairs great with the container ecosystem: Cloud Build, Container Registry, Docker.
So, this might work for you as a workaround. In this below tutorial, there are the steps to build and deploy a quick application with Go in Cloud Run.
Quickstart: Build and Deploy
Let me know if the information helped you!

What is happening when you deploy a BNA file to Hyperledger Composer?

After I've put together my business network definition, what is actually happening on peers after I deploy that package? I'm especially interested in how a hyperledger peer can be interpreting javascript, since that doesn't appear to be a supported language for chaincode.
The Composer chain code is written in Go. It uses the Duktape Javascript interpreter to execute the user (and system) JS code within a Go process.
The Composer chain code maps the public JS API to the underlying Fabric Go API calls.
From a Fabric perspective this is just a "normal" piece of Go chain code, albeit quite a complex one!
When you "deploy" a business network using the Composer CLI, you are actually doing 2 things:
deploying the Composer chain code (Go) and starting it
deploying the bytes of the business network archive and storing it in world-state, so that it is available to the interpreter when you submit transactions
In the future we would like to replace the use of Duktape by native Node.js execution. Thanks to Fabric's modular architecture (and use of Docker containers and gRPC) this should be possible.

Is it possible to use Nodejs Crypto module functionality in Fabric Composer?

I would like to be able to use various functions from the nodejs crypto module in my Fabric Composer chaincode. Is that possible? I tried hashing a simple string within my chaincode but it didn't work - in Playground I received this error message: 'TypeError: Cannot read property 'apply' of null.' and using CLI to local HLF the transaction never completed. I tested my javascript hashing code separately and it works but not when I try to run it within chaincode.
At the moment you cannot use node modules in transaction processor functions- you're limited to base javascript. It's possible that nodejs support will come in the future, and making crypo APIs available in composer is another option being considered.
If you want to try something in the mean time, crypto-browserify might be worth investigating. I don't know if anyone has got that to work though, so please report back if you try it.

Resources