Error when instantiate chaincode - go

Please help me this issue, error happened when I instantiate my chaincode:
Currently, I guess the issue related to shim package, because I remove it in my utils package, instantiate successfully.
MyChainCode:
import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
"strconv"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/core/chaincode/shim"
"github.com/hyperledger/fabric/protos/msp"
pb "github.com/hyperledger/fabric/protos/peer"
"github.com/myproj/models"
"github.com/myproj/packages/utils"
)
APIstub shim.ChaincodeStubInterface
...
username, _ = utils.GetCurrentUser(APIstub)
...
My packages
package utils
import (
"github.com/hyperledger/fabric/core/chaincode/shim"
"golang.org/x/crypto/bcrypt"
)
func GetCurrentUser(stub shim.ChaincodeStubInterface) (string, error) {
cert, err := GetCreatorCert(stub)
return cert.Subject.CommonName, err
}
Issue:
Error: Error endorsing chaincode: rpc error: code = Unknown desc =
error starting container: Failed to generate platform-specific docker
build: Error returned from build: 2 "#
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:5:
hdr.Format undefined (type *tar.Header has no field or method Format)
~vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:364:15:
undefined: tar.FormatPAX
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:7:
hdr.Format undefined (type *tar.Header has no field or method Format)
~/vendor/github.com/hyperledger/fabric/vendor/github.com/docker/docker/pkg/archive/archive.go:1166:17:
undefined: tar.FormatPAX
Fabric ver 1.1.0
Go ver 1.9.2

I faced the same problem after upgrading fabric to 1.2.0. Fabric 1.2.0 requires go 1.10.x. So I upgraded go lang to 1.10.3 and it worked like a charm.

That can be because you have old version in some files inside your hyperledger/fabric folder.
If you are following the chaincode tutorial, you can just remove your hyperledger/fabric folder.
Regards

I had the same issue by following the documentation.
Switching to branch 'release-1.1' solves the issue.
After cloning the repository proceed with:
hyperleger$ cd fabric
hyperledger/fabric$ git fetch
hyperledger/fabric$ git checkout release-1.1

Related

golang build at /vendor/github.com/weaveworks/promrus is giving an error: undefined: logrus.Level

I am trying to build the golang package (/vendor/github.com/weaveworks/promrus) in IBM Z (Mainframe). And I am getting an error: ./promrus.go:15:25: undefined: logrus.Level
My go version is: go version go1.16.2 zos/s390x
I have tried to read through the article: https://www.ibm.com/docs/en/sdk-go-zos/1.16?topic=porting-applications-zos
and have added a build constraint (//+build zos) as given below. But still the undefined error is not going away. Is there any way to build? Pls help and thanks in advance.
//+build zos
package promrus
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/sirupsen/logrus" )
// PrometheusHook exposes Prometheus counters for each of logrus' log
levels. type PrometheusHook struct {
counterVec *prometheus.CounterVec }
User opened up an official support Case with IBM and found resolution.

unable to get hashicorp / vault

I need to use kmac Hashicorp's Vault implementation. However, when I run the code, the following simple import:
import (
"encoding/hex"
"fmt"
"github.com/hashicorp/vault/sdk/helper/kmac"
)
throws this error: no required module provides package github.com/hashicorp/vault/sdk/helper/kmac/kmac; to add it: go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
If I run:
go get github.com/hashicorp/vault/sdk/helper/kmac/kmac
I get:
go get: module github.com/hashicorp/vault/sdk#upgrade found (v0.2.0), but does not contain package github.com/hashicorp/vault/sdk/helper/kmac/kmac
I also tested to download the latest version but I get the same error. Can I get help?

Having issue defining go_remote_library declaration for 3rdparty/go/golang.org/x/text:*

I'm trying to used github.com/spf13/viper which requires github.com/spf13/afero and that requires some of the 3rdparty/go/golang.org/x/text: packages. Till afero works, and when defining 3rdparty BUILD for text:* packages I get the following errors,
3rdparty/go/github.com/spf13/afero has remote dependencies which require local declaration:
--> golang.org/x/text/unicode/norm (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:unicode/norm)
--> golang.org/x/text/transform (expected go_remote_library declaration at 3rdparty/go/golang.org/x/text:transform)
I tried to define it like this in 3rdparty/go/golang.org/x/text/BUILD,
go_remote_library(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'unicode/norm',
'transform',
]
)
And it still shows the same error. Plus now running buildgen.go fails with the following error,
Exception caught: (pants.build_graph.target.UnknownArgumentError) (backtrace omitted)
Exception message: Invalid target 3rdparty/go/golang.org/x/text:text: GoRemoteLibrary received unknown arguments:
packages = ['unicode/norm', 'transform']
Some more info,
- Pants version: 1.13.0
- pantsbuild.pants.contrib.go: 1.13.0
- Tried using 1.14.0 & 1.15.0 as well and got the same results
Simple example to recreate it,
package main
import (
"fmt"
"github.com/spf13/viper"
)
func main() {
viper.AutomaticEnv()
fmt.Printf("%s", viper.GetString("HOME"))
}
Also you can simply do pants resolve on the package to get the error,
pants resolve 3rdparty/go/github.com/spf13/viper
Thanks to the pants team, got the issue resolved.
buildgen.go does turn go_remote_library(pkg='foo') takes into go_remote_libraries targets.
We need to use go_remote_libraries (not go_remote_library) to specify multiple packages.
Using this works fine,
go_remote_libraries(
rev='342b2e1fbaa52c93f31447ad2c6abc048c63e475',
packages=[
'transform',
'unicode/norm',
]
)

"Import error database/sql" for sql package

"Import error database/sql" for sql package.
I wanna use connect method on the controller.
I think need to install sql package.
controllers/gorm.go
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"github.com/revel/revel"
"myapp/app/models"
"log"
)
add database/sql and try import.
but the error has occurred.
error
Revel engine is NOT listening on.. localhost:58929
/Users/toshi/gocode/src/myapp/app/controllers/gorm.go
ERROR 16:10:50 watcher.go:270: Build detected an error
error="Go Compilation Error (in app/controllers/gorm.go:4): imported and not used: \"database/sql\""
/Users/toshi/gocode/src/myapp/app/controllers/gorm.go
ERROR 16:11:49 watcher.go:270: Build detected an error
error="Go Compilation Error (in app/controllers/gorm.go:4): imported and not used: \"database/sql\""
app path
/Users/toshi/gocode/src/myapp
sql-driver path
/Users/toshi/gocode/src/github.com/go-sql-driver/mysql
http://rabbitfoot141.hatenablog.com/entry/2019/03/05/000551
(reference)

error adding golang cobra package with glide

My glide.yaml import section is
import:
- package: github.com/spf13/cobra
I have
import (
"github.com/spf13/cobra"
)
in my code.
but I am getting the error
vendor/github.com/spf13/cobra/command.go:1092: c.lflags.SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
vendor/github.com/spf13/cobra/command.go:1092: c.Flags().SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
vendor/github.com/spf13/cobra/command.go:1240: c.parentsPflags.SortFlags undefined (type *pflag.FlagSet has no field or method SortFlags)
couples of issues on cobra repo says that can happen if pflag package is old version but in my case don't have that package installed separately.
any idea what am I doing wrong? thanks in advance!
It was problem with glide cache not updating why old version of pflag package was getting installed. More detailed info: https://github.com/spf13/cobra/issues/420

Resources