Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: a part of decouple fabric code #66

Merged
merged 1 commit into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golang_nofunction.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ jobs:
- run: make generate
name: Generate test mocks
- name: run lint
run: make golint || true
run: make golint

1 change: 0 additions & 1 deletion go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ require (
github.com/spf13/afero v1.3.1 // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.1.1 // indirect
github.com/sykesm/zap-logfmt v0.0.4 // indirect
go.uber.org/atomic v1.7.0 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Knetic/govaluate v3.0.0+incompatible h1:7o6+MAPhYTCF0+fdvoz1xDedhRb4f6s9Tn1Tt7/WTEg=
Expand Down Expand Up @@ -279,7 +278,6 @@ github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.1.1 h1:/8JBRFO4eoHu1TmpsLgNBq1CQgRUg4GolYlEFieqJgo=
github.com/spf13/viper v1.1.1/go.mod h1:A8kyI5cUJhb8N+3pkfONlcEcZbueH6nhAm0Fq7SrnBM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
19 changes: 15 additions & 4 deletions go/internal/configtxgen/genesisconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/hyperledger/fabric-protos-go-apiv2/orderer/etcdraft"
cf "github.com/hyperledger/fabric/core/config"
)

const (
Expand Down Expand Up @@ -399,19 +398,31 @@ loop:
log.Panicf("consenter info in %s configuration did not specify server TLS cert", EtcdRaft)
}
clientCertPath := string(c.GetClientTlsCert())
cf.TranslatePathInPlace(configDir, &clientCertPath)
TranslatePathInPlace(configDir, &clientCertPath)
c.ClientTlsCert = []byte(clientCertPath)
serverCertPath := string(c.GetServerTlsCert())
cf.TranslatePathInPlace(configDir, &serverCertPath)
TranslatePathInPlace(configDir, &serverCertPath)
c.ServerTlsCert = []byte(serverCertPath)
}
default:
log.Panicf("unknown orderer type: %s", ord.OrdererType)
}
}

func TranslatePathInPlace(base string, p *string) {
*p = TranslatePath(base, *p)
}

func TranslatePath(base, p string) string {
if filepath.IsAbs(p) {
return p
}

return filepath.Join(base, p)
}

func translatePaths(configDir string, org *Organization) {
cf.TranslatePathInPlace(configDir, &org.MSPDir)
TranslatePathInPlace(configDir, &org.MSPDir)
}

// configCache stores marshalled bytes of config structures that produced from
Expand Down
6 changes: 2 additions & 4 deletions go/internal/configtxgen/metadata/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ package metadata
import (
"fmt"
"runtime"

"github.com/hyperledger/fabric/common/metadata"
)

const ProgramName = "configtxgen"

var (
CommitSHA = metadata.CommitSHA
Version = metadata.Version
CommitSHA = "development build"
Version = "latest"
)

func GetVersionInfo() string {
Expand Down
2 changes: 1 addition & 1 deletion go/internal/genesis/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (f *factory) Block(channelID string) *cb.Block {
block := protoutil.NewBlock(0, nil)
block.Data = &cb.BlockData{Data: [][]byte{protoutil.MarshalOrPanic(envelope)}}
block.Header.DataHash = protoutil.BlockDataHash(block.Data)
block.Metadata.Metadata[cb.BlockMetadataIndex_LAST_CONFIG] = protoutil.MarshalOrPanic(&cb.Metadata{
block.Metadata.Metadata[1] = protoutil.MarshalOrPanic(&cb.Metadata{
Value: protoutil.MarshalOrPanic(&cb.LastConfig{Index: 0}),
})
block.Metadata.Metadata[cb.BlockMetadataIndex_SIGNATURES] = protoutil.MarshalOrPanic(&cb.Metadata{
Expand Down
12 changes: 5 additions & 7 deletions go/internal/msp/msp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package msp
import (
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/hyperledger/fabric-protos-go-apiv2/msp"
"github.com/hyperledger/fabric/bccsp"
"google.golang.org/protobuf/proto"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -121,7 +119,7 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M
if err == nil {
// load the file, if there is a failure in loading it then
// return an error
raw, err := ioutil.ReadFile(configFile)
raw, err := os.ReadFile(configFile)
if err != nil {
return nil, fmt.Errorf("failed loading configuration file at [%s] %w", configFile, err)
}
Expand Down Expand Up @@ -193,8 +191,8 @@ func getMspConfig(dir string, ID string, sigid *msp.SigningIdentityInfo) (*msp.M

// Set FabricCryptoConfig
cryptoConfig := &msp.FabricCryptoConfig{
SignatureHashFamily: bccsp.SHA2,
IdentityIdentifierHashFunction: bccsp.SHA256,
SignatureHashFamily: "SHA2",
IdentityIdentifierHashFunction: "SHA256",
}

// Compose FabricMSPConfig
Expand Down Expand Up @@ -228,7 +226,7 @@ func getPemMaterialFromDir(dir string) ([][]byte, error) {
}

content := make([][]byte, 0)
files, err := ioutil.ReadDir(dir)
files, err := os.ReadDir(dir)
if err != nil {
return nil, fmt.Errorf("could not read directory %s %w", dir, err)
}
Expand Down Expand Up @@ -297,7 +295,7 @@ type Configuration struct {
}

func readFile(file string) ([]byte, error) {
fileCont, err := ioutil.ReadFile(file)
fileCont, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("could not read file %s %w", file, err)
}
Expand Down
7 changes: 4 additions & 3 deletions go/internal/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import (
"crypto/x509"
"encoding/pem"
"fmt"
"io/ioutil"
"net"
"os"
"time"

grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"
)

Expand Down Expand Up @@ -55,7 +56,7 @@ func GetTLSCACerts(file string) ([]byte, error) {
return nil, nil
}

in, err := ioutil.ReadFile(file)
in, err := os.ReadFile(file)
if err != nil {
return nil, fmt.Errorf("error loading %s %w", file, err)
}
Expand Down Expand Up @@ -370,7 +371,7 @@ func (client *GRPCClient) NewConnection(address string, tlsOptions ...TLSOption)
},
))
} else {
dialOpts = append(dialOpts, grpc.WithInsecure())
dialOpts = append(dialOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}

dialOpts = append(dialOpts, grpc.WithDefaultCallOptions(
Expand Down
7 changes: 4 additions & 3 deletions go/pkg/chaincode/packageID.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import (
"archive/tar"
"bytes"
"compress/gzip"
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"os"
"regexp"

"github.com/hyperledger/fabric/common/util"
)

const (
Expand Down Expand Up @@ -40,7 +39,9 @@ func PackageID(PackageFile string) (string, error) {

// PackageID returns the package ID with the label and hash of the chaincode install package
func GetPackageID(label string, ccInstallPkg []byte) string {
hash := util.ComputeSHA256(ccInstallPkg)
h := sha256.New()
h.Write(ccInstallPkg)
hash := h.Sum(nil)
return fmt.Sprintf("%s:%x", label, hash)
}

Expand Down