From fbfcc708e3702046d1a3a78e30d4754666876f04 Mon Sep 17 00:00:00 2001 From: "Mark S. Lewis" Date: Wed, 15 Jun 2022 13:23:37 +0100 Subject: [PATCH] Use fabric-protos-go-apiv2 in Go client (#452) Uses the v2 protocol buffer API and avoids direct usage of the deprecated v1 API. Signed-off-by: Mark S. Lewis --- go.mod | 4 +-- go.sum | 4 +-- pkg/client/blockevents.go | 8 ++--- pkg/client/blockevents_test.go | 8 ++--- pkg/client/blockeventsbuilder.go | 14 ++++----- pkg/client/blockeventsfiltered_test.go | 6 ++-- pkg/client/blockeventswithprivatedata_test.go | 8 ++--- pkg/client/chaincodeevents.go | 6 ++-- pkg/client/chaincodeevents_test.go | 6 ++-- pkg/client/chaincodeeventsbuilder.go | 6 ++-- pkg/client/client.go | 10 +++--- pkg/client/commit.go | 8 ++--- pkg/client/errors.go | 2 +- pkg/client/evaluate_test.go | 4 +-- pkg/client/eventsbuilder.go | 2 +- pkg/client/gateway.go | 30 +++++++++--------- pkg/client/gateway_test.go | 8 ++--- pkg/client/identity_test.go | 10 +++--- pkg/client/network.go | 4 +-- pkg/client/offlinesign_test.go | 6 ++-- pkg/client/proposal.go | 6 ++-- pkg/client/proposalbuilder.go | 22 ++++++------- pkg/client/sign_test.go | 4 +-- pkg/client/signingidentity.go | 6 ++-- pkg/client/submit_test.go | 14 ++++----- pkg/client/transaction.go | 8 ++--- pkg/client/transactioncontext.go | 2 +- pkg/client/transactionparser.go | 18 +++++------ pkg/internal/test/transaction.go | 16 +++++----- pkg/internal/util/protobuf.go | 31 ------------------- pkg/internal/util/staticcheck.conf | 1 - scenario/go/blockandprivatedataevents_test.go | 2 +- scenario/go/blockevents_test.go | 2 +- scenario/go/connection_test.go | 4 +-- scenario/go/filteredblockevents_test.go | 2 +- scenario/go/scenario_test.go | 2 +- scenario/go/transaction_test.go | 4 +-- 37 files changed, 133 insertions(+), 165 deletions(-) delete mode 100644 pkg/internal/util/protobuf.go delete mode 100644 pkg/internal/util/staticcheck.conf diff --git a/go.mod b/go.mod index efaeac49c..6a75cb98a 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,7 @@ require ( github.com/cucumber/godog v0.12.5 github.com/cucumber/messages-go/v16 v16.0.1 github.com/golang/mock v1.6.0 - github.com/golang/protobuf v1.5.2 - github.com/hyperledger/fabric-protos-go v0.0.0-20220315113721-7dc293e117f7 + github.com/hyperledger/fabric-protos-go-apiv2 v0.0.0-20220615102044-467be1c7b2e7 github.com/miekg/pkcs11 v1.1.1 github.com/stretchr/testify v1.7.1 google.golang.org/grpc v1.46.2 @@ -18,6 +17,7 @@ require ( github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/gofrs/uuid v4.2.0+incompatible // indirect + github.com/golang/protobuf v1.5.2 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect github.com/hashicorp/go-memdb v1.3.3 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect diff --git a/go.sum b/go.sum index de00d07f4..998fb2f76 100644 --- a/go.sum +++ b/go.sum @@ -147,8 +147,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ= github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I= github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc= -github.com/hyperledger/fabric-protos-go v0.0.0-20220315113721-7dc293e117f7 h1:YV+siZuYQZwENjRH00t7ZS0CTlywt8Qog/SzL/jf6kE= -github.com/hyperledger/fabric-protos-go v0.0.0-20220315113721-7dc293e117f7/go.mod h1:xVYTjK4DtZRBxZ2D9aE4y6AbLaPwue2o/criQyQbVD0= +github.com/hyperledger/fabric-protos-go-apiv2 v0.0.0-20220615102044-467be1c7b2e7 h1:loYDK6Vrf7z3fff6YBVKFkFeCGCoKr8O2ed02CESBUQ= +github.com/hyperledger/fabric-protos-go-apiv2 v0.0.0-20220615102044-467be1c7b2e7/go.mod h1:smwq1q6eKByqQAp0SYdVvE1MvDoneF373j11XwWajgA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= diff --git a/pkg/client/blockevents.go b/pkg/client/blockevents.go index aaf727827..74a7a518d 100644 --- a/pkg/client/blockevents.go +++ b/pkg/client/blockevents.go @@ -10,10 +10,10 @@ import ( "context" "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) type baseBlockEventsRequest struct { @@ -24,7 +24,7 @@ type baseBlockEventsRequest struct { // Bytes of the serialized block events request. func (events *baseBlockEventsRequest) Bytes() ([]byte, error) { - requestBytes, err := util.Marshal(events.request) + requestBytes, err := proto.Marshal(events.request) if err != nil { return nil, fmt.Errorf("failed to marshall Envelope protobuf: %w", err) } diff --git a/pkg/client/blockevents_test.go b/pkg/client/blockevents_test.go index ad1f6d9f1..2dedfe9c9 100644 --- a/pkg/client/blockevents_test.go +++ b/pkg/client/blockevents_test.go @@ -13,10 +13,10 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/msp" - "github.com/hyperledger/fabric-protos-go/orderer" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/msp" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/pkg/client/blockeventsbuilder.go b/pkg/client/blockeventsbuilder.go index d7bdd8187..b52f58efa 100644 --- a/pkg/client/blockeventsbuilder.go +++ b/pkg/client/blockeventsbuilder.go @@ -9,9 +9,9 @@ package client import ( "math" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -53,7 +53,7 @@ func (builder *baseBlockEventsBuilder) payloadBytes() ([]byte, error) { Data: data, } - return util.Marshal(payload) + return proto.Marshal(payload) } func (builder *baseBlockEventsBuilder) channelHeaderBytes() ([]byte, error) { @@ -64,7 +64,7 @@ func (builder *baseBlockEventsBuilder) channelHeaderBytes() ([]byte, error) { Epoch: 0, } - return util.Marshal(channelHeader) + return proto.Marshal(channelHeader) } func (builder *baseBlockEventsBuilder) signatureHeaderBytes() ([]byte, error) { @@ -77,7 +77,7 @@ func (builder *baseBlockEventsBuilder) signatureHeaderBytes() ([]byte, error) { Creator: creator, } - return util.Marshal(signatureHeader) + return proto.Marshal(signatureHeader) } func (builder *baseBlockEventsBuilder) dataBytes() ([]byte, error) { @@ -86,7 +86,7 @@ func (builder *baseBlockEventsBuilder) dataBytes() ([]byte, error) { Stop: seekLargestBlockNumber(), } - return util.Marshal(data) + return proto.Marshal(data) } type filteredBlockEventsBuilder struct { diff --git a/pkg/client/blockeventsfiltered_test.go b/pkg/client/blockeventsfiltered_test.go index 795f06723..96e5598ea 100644 --- a/pkg/client/blockeventsfiltered_test.go +++ b/pkg/client/blockeventsfiltered_test.go @@ -13,9 +13,9 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/orderer" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/pkg/client/blockeventswithprivatedata_test.go b/pkg/client/blockeventswithprivatedata_test.go index de1d4f8c7..f7abd0720 100644 --- a/pkg/client/blockeventswithprivatedata_test.go +++ b/pkg/client/blockeventswithprivatedata_test.go @@ -13,10 +13,10 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/ledger/rwset" - "github.com/hyperledger/fabric-protos-go/orderer" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/ledger/rwset" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/pkg/client/chaincodeevents.go b/pkg/client/chaincodeevents.go index 70efbfe3b..f5df4377e 100644 --- a/pkg/client/chaincodeevents.go +++ b/pkg/client/chaincodeevents.go @@ -10,9 +10,9 @@ import ( "context" "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // ChaincodeEventsRequest delivers events emitted by transaction functions in a specific chaincode. @@ -24,7 +24,7 @@ type ChaincodeEventsRequest struct { // Bytes of the serialized chaincode events request. func (events *ChaincodeEventsRequest) Bytes() ([]byte, error) { - requestBytes, err := util.Marshal(events.signedRequest) + requestBytes, err := proto.Marshal(events.signedRequest) if err != nil { return nil, fmt.Errorf("failed to marshall SignedChaincodeEventsRequest protobuf: %w", err) } diff --git a/pkg/client/chaincodeevents_test.go b/pkg/client/chaincodeevents_test.go index fe65e2045..c2b77d092 100644 --- a/pkg/client/chaincodeevents_test.go +++ b/pkg/client/chaincodeevents_test.go @@ -13,9 +13,9 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/orderer" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/pkg/client/chaincodeeventsbuilder.go b/pkg/client/chaincodeeventsbuilder.go index 74aea3214..38d6ee0ab 100644 --- a/pkg/client/chaincodeeventsbuilder.go +++ b/pkg/client/chaincodeeventsbuilder.go @@ -9,8 +9,8 @@ package client import ( "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "google.golang.org/protobuf/proto" ) type chaincodeEventsBuilder struct { @@ -38,7 +38,7 @@ func (builder *chaincodeEventsBuilder) newSignedChaincodeEventsRequestProto() (* return nil, err } - requestBytes, err := util.Marshal(request) + requestBytes, err := proto.Marshal(request) if err != nil { return nil, fmt.Errorf("failed to serialize chaincode events request: %w", err) } diff --git a/pkg/client/client.go b/pkg/client/client.go index 3452dc7ac..71e8c1407 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -9,11 +9,11 @@ package client import ( "context" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) type gatewayClient struct { @@ -73,7 +73,7 @@ func (client *gatewayClient) CommitStatusWithContext(ctx context.Context, in *ga func getTransactionIDFromSignedCommitStatusRequest(in *gateway.SignedCommitStatusRequest) string { request := &gateway.CommitStatusRequest{} - err := util.Unmarshal(in.GetRequest(), request) + err := proto.Unmarshal(in.GetRequest(), request) if err != nil { return "?" } diff --git a/pkg/client/commit.go b/pkg/client/commit.go index 624273167..caa07e9e1 100644 --- a/pkg/client/commit.go +++ b/pkg/client/commit.go @@ -10,10 +10,10 @@ import ( "context" "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // Commit provides access to a committed transaction. @@ -40,7 +40,7 @@ func newCommit( // Bytes of the serialized commit. func (commit *Commit) Bytes() ([]byte, error) { - requestBytes, err := util.Marshal(commit.signedRequest) + requestBytes, err := proto.Marshal(commit.signedRequest) if err != nil { return nil, fmt.Errorf("failed to marshall SignedCommitStatusRequest protobuf: %w", err) } diff --git a/pkg/client/errors.go b/pkg/client/errors.go index 0a41dd5fe..5d7cef50a 100644 --- a/pkg/client/errors.go +++ b/pkg/client/errors.go @@ -9,7 +9,7 @@ package client import ( "fmt" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc/status" ) diff --git a/pkg/client/evaluate_test.go b/pkg/client/evaluate_test.go index eb8ace028..faf79c87b 100644 --- a/pkg/client/evaluate_test.go +++ b/pkg/client/evaluate_test.go @@ -13,8 +13,8 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" diff --git a/pkg/client/eventsbuilder.go b/pkg/client/eventsbuilder.go index 7c22b32ce..fbf06f064 100644 --- a/pkg/client/eventsbuilder.go +++ b/pkg/client/eventsbuilder.go @@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0 package client import ( - "github.com/hyperledger/fabric-protos-go/orderer" + "github.com/hyperledger/fabric-protos-go-apiv2/orderer" ) type eventsBuilder struct { diff --git a/pkg/client/gateway.go b/pkg/client/gateway.go index e127d3cbc..6ab53e989 100644 --- a/pkg/client/gateway.go +++ b/pkg/client/gateway.go @@ -20,11 +20,11 @@ import ( "github.com/hyperledger/fabric-gateway/pkg/hash" "github.com/hyperledger/fabric-gateway/pkg/identity" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // Gateway representing the connection of a specific client identity to a Fabric Gateway. @@ -181,22 +181,22 @@ func (gw *Gateway) NewSignedProposal(bytes []byte, signature []byte) (*Proposal, // NewProposal recreates a proposal from serialized data. func (gw *Gateway) NewProposal(bytes []byte) (*Proposal, error) { proposedTransaction := &gateway.ProposedTransaction{} - if err := util.Unmarshal(bytes, proposedTransaction); err != nil { + if err := proto.Unmarshal(bytes, proposedTransaction); err != nil { return nil, fmt.Errorf("failed to deserialize proposed transaction: %w", err) } proposal := &peer.Proposal{} - if err := util.Unmarshal(proposedTransaction.GetProposal().GetProposalBytes(), proposal); err != nil { + if err := proto.Unmarshal(proposedTransaction.GetProposal().GetProposalBytes(), proposal); err != nil { return nil, fmt.Errorf("failed to deserialize proposal: %w", err) } header := &common.Header{} - if err := util.Unmarshal(proposal.GetHeader(), header); err != nil { + if err := proto.Unmarshal(proposal.GetHeader(), header); err != nil { return nil, fmt.Errorf("failed to deserialize header: %w", err) } channelHeader := &common.ChannelHeader{} - if err := util.Unmarshal(header.GetChannelHeader(), channelHeader); err != nil { + if err := proto.Unmarshal(header.GetChannelHeader(), channelHeader); err != nil { return nil, fmt.Errorf("failed to deserialize channel header: %w", err) } @@ -227,7 +227,7 @@ func (gw *Gateway) NewSignedTransaction(bytes []byte, signature []byte) (*Transa func (gw *Gateway) NewTransaction(bytes []byte) (*Transaction, error) { preparedTransaction := &gateway.PreparedTransaction{} - if err := util.Unmarshal(bytes, preparedTransaction); err != nil { + if err := proto.Unmarshal(bytes, preparedTransaction); err != nil { return nil, fmt.Errorf("failed to deserialize prepared transaction: %w", err) } @@ -253,12 +253,12 @@ func (gw *Gateway) NewSignedCommit(bytes []byte, signature []byte) (*Commit, err // NewCommit recreates a commit from serialized data. func (gw *Gateway) NewCommit(bytes []byte) (*Commit, error) { signedRequest := &gateway.SignedCommitStatusRequest{} - if err := util.Unmarshal(bytes, signedRequest); err != nil { + if err := proto.Unmarshal(bytes, signedRequest); err != nil { return nil, fmt.Errorf("failed to deserialize signed commit status request: %w", err) } request := &gateway.CommitStatusRequest{} - if err := util.Unmarshal(signedRequest.Request, request); err != nil { + if err := proto.Unmarshal(signedRequest.Request, request); err != nil { return nil, fmt.Errorf("failed to deserialize commit status request: %w", err) } @@ -282,7 +282,7 @@ func (gw *Gateway) NewSignedChaincodeEventsRequest(bytes []byte, signature []byt // NewChaincodeEventsRequest recreates a request to read chaincode events from serialized data. func (gw *Gateway) NewChaincodeEventsRequest(bytes []byte) (*ChaincodeEventsRequest, error) { request := &gateway.SignedChaincodeEventsRequest{} - if err := util.Unmarshal(bytes, request); err != nil { + if err := proto.Unmarshal(bytes, request); err != nil { return nil, fmt.Errorf("failed to deserialize signed chaincode events request: %w", err) } @@ -309,7 +309,7 @@ func (gw *Gateway) NewSignedBlockEventsRequest(bytes []byte, signature []byte) ( // NewBlockEventsRequest recreates a request to read block events from serialized data. func (gw *Gateway) NewBlockEventsRequest(bytes []byte) (*BlockEventsRequest, error) { request := &common.Envelope{} - if err := util.Unmarshal(bytes, request); err != nil { + if err := proto.Unmarshal(bytes, request); err != nil { return nil, fmt.Errorf("failed to deserialize block events request envelope: %w", err) } @@ -338,7 +338,7 @@ func (gw *Gateway) NewSignedFilteredBlockEventsRequest(bytes []byte, signature [ // NewFilteredBlockEventsRequest recreates a request to read filtered block events from serialized data. func (gw *Gateway) NewFilteredBlockEventsRequest(bytes []byte) (*FilteredBlockEventsRequest, error) { request := &common.Envelope{} - if err := util.Unmarshal(bytes, request); err != nil { + if err := proto.Unmarshal(bytes, request); err != nil { return nil, fmt.Errorf("failed to deserialize block events request envelope: %w", err) } @@ -367,7 +367,7 @@ func (gw *Gateway) NewSignedBlockAndPrivateDataEventsRequest(bytes []byte, signa // NewBlockAndPrivateDataEventsRequest recreates a request to read block and private data events from serialized data. func (gw *Gateway) NewBlockAndPrivateDataEventsRequest(bytes []byte) (*BlockAndPrivateDataEventsRequest, error) { request := &common.Envelope{} - if err := util.Unmarshal(bytes, request); err != nil { + if err := proto.Unmarshal(bytes, request); err != nil { return nil, fmt.Errorf("failed to deserialize block events request envelope: %w", err) } diff --git a/pkg/client/gateway_test.go b/pkg/client/gateway_test.go index eb133f8cf..10e2d7af9 100644 --- a/pkg/client/gateway_test.go +++ b/pkg/client/gateway_test.go @@ -12,14 +12,14 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/identity" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) -//go:generate mockgen -destination ./gateway_mock_test.go -package ${GOPACKAGE} github.com/hyperledger/fabric-protos-go/gateway GatewayClient,Gateway_ChaincodeEventsClient -//go:generate mockgen -destination ./deliver_mock_test.go -package ${GOPACKAGE} github.com/hyperledger/fabric-protos-go/peer DeliverClient,Deliver_DeliverClient,Deliver_DeliverFilteredClient,Deliver_DeliverWithPrivateDataClient +//go:generate mockgen -destination ./gateway_mock_test.go -package ${GOPACKAGE} github.com/hyperledger/fabric-protos-go-apiv2/gateway GatewayClient,Gateway_ChaincodeEventsClient +//go:generate mockgen -destination ./deliver_mock_test.go -package ${GOPACKAGE} github.com/hyperledger/fabric-protos-go-apiv2/peer DeliverClient,Deliver_DeliverClient,Deliver_DeliverFilteredClient,Deliver_DeliverWithPrivateDataClient // WithGatewayClient uses the supplied client for the Gateway. Allows a stub implementation to be used for testing. func WithGatewayClient(client gateway.GatewayClient) ConnectOption { diff --git a/pkg/client/identity_test.go b/pkg/client/identity_test.go index 0c0a9bee8..e2bf3b4ee 100644 --- a/pkg/client/identity_test.go +++ b/pkg/client/identity_test.go @@ -13,12 +13,12 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/identity" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/msp" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/msp" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) func TestIdentity(t *testing.T) { @@ -35,7 +35,7 @@ func TestIdentity(t *testing.T) { Mspid: id.MspID(), IdBytes: id.Credentials(), } - creator, err := util.Marshal(serializedIdentity) + creator, err := proto.Marshal(serializedIdentity) require.NoError(t, err) t.Run("Evaluate uses client identity for proposals", func(t *testing.T) { diff --git a/pkg/client/network.go b/pkg/client/network.go index a67022242..c25199c23 100644 --- a/pkg/client/network.go +++ b/pkg/client/network.go @@ -9,8 +9,8 @@ package client import ( "context" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" ) // Network represents a network of nodes that are members of a specific Fabric channel. The Network can be used to diff --git a/pkg/client/offlinesign_test.go b/pkg/client/offlinesign_test.go index a79a6ba45..7fef1f75e 100644 --- a/pkg/client/offlinesign_test.go +++ b/pkg/client/offlinesign_test.go @@ -12,9 +12,9 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) diff --git a/pkg/client/proposal.go b/pkg/client/proposal.go index b831baa0c..db283f45a 100644 --- a/pkg/client/proposal.go +++ b/pkg/client/proposal.go @@ -10,9 +10,9 @@ import ( "context" "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) // Proposal represents a transaction proposal that can be sent to peers for endorsement or evaluated as a query. @@ -25,7 +25,7 @@ type Proposal struct { // Bytes of the serialized proposal message. func (proposal *Proposal) Bytes() ([]byte, error) { - transactionBytes, err := util.Marshal(proposal.proposedTransaction) + transactionBytes, err := proto.Marshal(proposal.proposedTransaction) if err != nil { return nil, fmt.Errorf("failed to marshall Proposal protobuf: %w", err) } diff --git a/pkg/client/proposalbuilder.go b/pkg/client/proposalbuilder.go index 1db6998b2..3bf109d57 100644 --- a/pkg/client/proposalbuilder.go +++ b/pkg/client/proposalbuilder.go @@ -7,10 +7,10 @@ SPDX-License-Identifier: Apache-2.0 package client import ( - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" + "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" ) @@ -85,7 +85,7 @@ func (builder *proposalBuilder) proposalBytes() ([]byte, error) { Header: headerBytes, Payload: chaincodeProposalBytes, } - return util.Marshal(proposal) + return proto.Marshal(proposal) } func (builder *proposalBuilder) headerBytes() ([]byte, error) { @@ -94,7 +94,7 @@ func (builder *proposalBuilder) headerBytes() ([]byte, error) { return nil, err } - signatureHeaderBytes, err := util.Marshal(builder.transactionCtx.SignatureHeader) + signatureHeaderBytes, err := proto.Marshal(builder.transactionCtx.SignatureHeader) if err != nil { return nil, err } @@ -103,11 +103,11 @@ func (builder *proposalBuilder) headerBytes() ([]byte, error) { ChannelHeader: channelHeaderBytes, SignatureHeader: signatureHeaderBytes, } - return util.Marshal(header) + return proto.Marshal(header) } func (builder *proposalBuilder) channelHeaderBytes() ([]byte, error) { - extensionBytes, err := util.Marshal(&peer.ChaincodeHeaderExtension{ + extensionBytes, err := proto.Marshal(&peer.ChaincodeHeaderExtension{ ChaincodeId: &peer.ChaincodeID{ Name: builder.chaincodeName, }, @@ -124,11 +124,11 @@ func (builder *proposalBuilder) channelHeaderBytes() ([]byte, error) { Epoch: 0, Extension: extensionBytes, } - return util.Marshal(channelHeader) + return proto.Marshal(channelHeader) } func (builder *proposalBuilder) chaincodeProposalPayloadBytes() ([]byte, error) { - invocationSpecBytes, err := util.Marshal(&peer.ChaincodeInvocationSpec{ + invocationSpecBytes, err := proto.Marshal(&peer.ChaincodeInvocationSpec{ ChaincodeSpec: &peer.ChaincodeSpec{ ChaincodeId: &peer.ChaincodeID{ Name: builder.chaincodeName, @@ -146,7 +146,7 @@ func (builder *proposalBuilder) chaincodeProposalPayloadBytes() ([]byte, error) Input: invocationSpecBytes, TransientMap: builder.transient, } - return util.Marshal(chaincodeProposalPayload) + return proto.Marshal(chaincodeProposalPayload) } func (builder *proposalBuilder) chaincodeArgs() [][]byte { diff --git a/pkg/client/sign_test.go b/pkg/client/sign_test.go index 5d77d8528..5d4b81905 100644 --- a/pkg/client/sign_test.go +++ b/pkg/client/sign_test.go @@ -11,8 +11,8 @@ import ( "testing" "github.com/golang/mock/gomock" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" ) diff --git a/pkg/client/signingidentity.go b/pkg/client/signingidentity.go index 874f77ebd..2f9c38cd9 100644 --- a/pkg/client/signingidentity.go +++ b/pkg/client/signingidentity.go @@ -11,8 +11,8 @@ import ( "github.com/hyperledger/fabric-gateway/pkg/hash" "github.com/hyperledger/fabric-gateway/pkg/identity" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/msp" + "github.com/hyperledger/fabric-protos-go-apiv2/msp" + "google.golang.org/protobuf/proto" ) type signingIdentity struct { @@ -48,5 +48,5 @@ func (signingID *signingIdentity) Creator() ([]byte, error) { Mspid: signingID.id.MspID(), IdBytes: signingID.id.Credentials(), } - return util.Marshal(serializedIdentity) + return proto.Marshal(serializedIdentity) } diff --git a/pkg/client/submit_test.go b/pkg/client/submit_test.go index c86ca0f05..7a623b3c4 100644 --- a/pkg/client/submit_test.go +++ b/pkg/client/submit_test.go @@ -13,19 +13,19 @@ import ( "github.com/golang/mock/gomock" "github.com/hyperledger/fabric-gateway/pkg/internal/test" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" - "google.golang.org/protobuf/runtime/protoiface" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" ) -func AssertMarshal(t *testing.T, message protoiface.MessageV1, msgAndArgs ...interface{}) []byte { - bytes, err := util.Marshal(message) +func AssertMarshal(t *testing.T, message protoreflect.ProtoMessage, msgAndArgs ...interface{}) []byte { + bytes, err := proto.Marshal(message) require.NoError(t, err, msgAndArgs...) return bytes } diff --git a/pkg/client/transaction.go b/pkg/client/transaction.go index c0b74b508..9d5eb43dd 100644 --- a/pkg/client/transaction.go +++ b/pkg/client/transaction.go @@ -10,9 +10,9 @@ import ( "context" "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" "google.golang.org/grpc" + "google.golang.org/protobuf/proto" ) func newTransaction(client *gatewayClient, signingID *signingIdentity, preparedTransaction *gateway.PreparedTransaction) (*Transaction, error) { @@ -47,7 +47,7 @@ func (transaction *Transaction) Result() []byte { // Bytes of the serialized transaction. func (transaction *Transaction) Bytes() ([]byte, error) { - transactionBytes, err := util.Marshal(transaction.preparedTransaction) + transactionBytes, err := proto.Marshal(transaction.preparedTransaction) if err != nil { return nil, fmt.Errorf("failed to marshall PreparedTransaction protobuf: %w", err) } @@ -143,7 +143,7 @@ func (transaction *Transaction) newSignedCommitStatusRequest() (*gateway.SignedC Identity: creator, } - requestBytes, err := util.Marshal(request) + requestBytes, err := proto.Marshal(request) if err != nil { return nil, err } diff --git a/pkg/client/transactioncontext.go b/pkg/client/transactioncontext.go index afcd6d60a..af6c3fceb 100644 --- a/pkg/client/transactioncontext.go +++ b/pkg/client/transactioncontext.go @@ -10,7 +10,7 @@ import ( "crypto/rand" "encoding/hex" - "github.com/hyperledger/fabric-protos-go/common" + "github.com/hyperledger/fabric-protos-go-apiv2/common" ) type transactionContext struct { diff --git a/pkg/client/transactionparser.go b/pkg/client/transactionparser.go index 605b34aba..0f451df2b 100644 --- a/pkg/client/transactionparser.go +++ b/pkg/client/transactionparser.go @@ -9,9 +9,9 @@ package client import ( "fmt" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" + "google.golang.org/protobuf/proto" ) type transactionInfo struct { @@ -21,7 +21,7 @@ type transactionInfo struct { func parseTransactionEnvelope(envelope *common.Envelope) (*transactionInfo, error) { payload := &common.Payload{} - if err := util.Unmarshal(envelope.GetPayload(), payload); err != nil { + if err := proto.Unmarshal(envelope.GetPayload(), payload); err != nil { return nil, fmt.Errorf("failed to deserialize payload: %w", err) } @@ -44,7 +44,7 @@ func parseTransactionEnvelope(envelope *common.Envelope) (*transactionInfo, erro func parseChannelNameFromHeader(header *common.Header) (string, error) { channelHeader := &common.ChannelHeader{} - if err := util.Unmarshal(header.GetChannelHeader(), channelHeader); err != nil { + if err := proto.Unmarshal(header.GetChannelHeader(), channelHeader); err != nil { return "", fmt.Errorf("failed to deserialize channel header: %w", err) } @@ -53,7 +53,7 @@ func parseChannelNameFromHeader(header *common.Header) (string, error) { func parseResultFromPayload(payload *common.Payload) ([]byte, error) { transaction := &peer.Transaction{} - if err := util.Unmarshal(payload.GetData(), transaction); err != nil { + if err := proto.Unmarshal(payload.GetData(), transaction); err != nil { return nil, fmt.Errorf("failed to deserialize transaction: %w", err) } @@ -73,17 +73,17 @@ func parseResultFromPayload(payload *common.Payload) ([]byte, error) { func parseResultFromTransactionAction(transactionAction *peer.TransactionAction) ([]byte, error) { actionPayload := &peer.ChaincodeActionPayload{} - if err := util.Unmarshal(transactionAction.GetPayload(), actionPayload); err != nil { + if err := proto.Unmarshal(transactionAction.GetPayload(), actionPayload); err != nil { return nil, fmt.Errorf("failed to deserialize chaincode action payload: %w", err) } responsePayload := &peer.ProposalResponsePayload{} - if err := util.Unmarshal(actionPayload.GetAction().GetProposalResponsePayload(), responsePayload); err != nil { + if err := proto.Unmarshal(actionPayload.GetAction().GetProposalResponsePayload(), responsePayload); err != nil { return nil, fmt.Errorf("failed to deserialize proposal response payload: %w", err) } chaincodeAction := &peer.ChaincodeAction{} - if err := util.Unmarshal(responsePayload.GetExtension(), chaincodeAction); err != nil { + if err := proto.Unmarshal(responsePayload.GetExtension(), chaincodeAction); err != nil { return nil, fmt.Errorf("failed to deserialize chaincode action: %w", err) } diff --git a/pkg/internal/test/transaction.go b/pkg/internal/test/transaction.go index a0e461f2f..945e75bb8 100644 --- a/pkg/internal/test/transaction.go +++ b/pkg/internal/test/transaction.go @@ -9,21 +9,21 @@ package test import ( "testing" - "github.com/hyperledger/fabric-gateway/pkg/internal/util" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "github.com/stretchr/testify/require" - "google.golang.org/protobuf/runtime/protoiface" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/reflect/protoreflect" ) // AssertProtoEqual ensures an expected protobuf message matches an actual message -func AssertProtoEqual(t *testing.T, expected protoiface.MessageV1, actual protoiface.MessageV1) { - require.True(t, util.ProtoEqual(expected, actual), "Expected %v, got %v", expected, actual) +func AssertProtoEqual(t *testing.T, expected protoreflect.ProtoMessage, actual protoreflect.ProtoMessage) { + require.True(t, proto.Equal(expected, actual), "Expected %v, got %v", expected, actual) } // AssertUnmarshal ensures that a protobuf is umarshaled without error -func AssertUnmarshal(t *testing.T, b []byte, m protoiface.MessageV1) { - err := util.Unmarshal(b, m) +func AssertUnmarshal(t *testing.T, b []byte, m protoreflect.ProtoMessage) { + err := proto.Unmarshal(b, m) require.NoError(t, err) } diff --git a/pkg/internal/util/protobuf.go b/pkg/internal/util/protobuf.go deleted file mode 100644 index 7bc71aa19..000000000 --- a/pkg/internal/util/protobuf.go +++ /dev/null @@ -1,31 +0,0 @@ -/* -Copyright 2022 IBM All Rights Reserved. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package util - -import ( - proto1 "github.com/golang/protobuf/proto" - proto2 "google.golang.org/protobuf/proto" -) - -// Marshal returns the wire-format encoding of a message. The message can be either a protobuf v1 or v2 message. -func Marshal(message proto1.GeneratedMessage) ([]byte, error) { - messageV2 := proto1.MessageV2(message) - return proto2.Marshal(messageV2) -} - -// Unmarshal parses the wire-format message bytes and places the result in the provided message. The provided message -// must be mutable (e.g., a non-nil pointer to a message). The message can be either a protobuf v1 or v2 message. -func Unmarshal(bytes []byte, message proto1.GeneratedMessage) error { - messageV2 := proto1.MessageV2(message) - return proto2.Unmarshal(bytes, messageV2) -} - -// ProtoEqual reports whether two messages are equal, as with the standard proto.Equal function. The messages can be -// either protobuf v1 or v2 message. -func ProtoEqual(x proto1.GeneratedMessage, y proto1.GeneratedMessage) bool { - return proto2.Equal(proto1.MessageV2(x), proto1.MessageV2(y)) -} diff --git a/pkg/internal/util/staticcheck.conf b/pkg/internal/util/staticcheck.conf deleted file mode 100644 index 2e9a224ab..000000000 --- a/pkg/internal/util/staticcheck.conf +++ /dev/null @@ -1 +0,0 @@ -checks = ["inherit", "-SA1019"] diff --git a/scenario/go/blockandprivatedataevents_test.go b/scenario/go/blockandprivatedataevents_test.go index d42208dc9..addfd2e40 100644 --- a/scenario/go/blockandprivatedataevents_test.go +++ b/scenario/go/blockandprivatedataevents_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/hyperledger/fabric-gateway/pkg/client" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" ) type BlockAndPrivateDataEventListener struct { diff --git a/scenario/go/blockevents_test.go b/scenario/go/blockevents_test.go index 7172f2378..6ec23af76 100644 --- a/scenario/go/blockevents_test.go +++ b/scenario/go/blockevents_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/hyperledger/fabric-gateway/pkg/client" - "github.com/hyperledger/fabric-protos-go/common" + "github.com/hyperledger/fabric-protos-go-apiv2/common" ) type BlockEventListener struct { diff --git a/scenario/go/connection_test.go b/scenario/go/connection_test.go index 19220cb57..cdc42ad06 100644 --- a/scenario/go/connection_test.go +++ b/scenario/go/connection_test.go @@ -20,8 +20,8 @@ import ( "github.com/hyperledger/fabric-gateway/pkg/client" "github.com/hyperledger/fabric-gateway/pkg/identity" - "github.com/hyperledger/fabric-protos-go/common" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/common" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc" ) diff --git a/scenario/go/filteredblockevents_test.go b/scenario/go/filteredblockevents_test.go index 4e5e64796..7ecbd5c92 100644 --- a/scenario/go/filteredblockevents_test.go +++ b/scenario/go/filteredblockevents_test.go @@ -12,7 +12,7 @@ import ( "time" "github.com/hyperledger/fabric-gateway/pkg/client" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" ) type FilteredBlockEventListener struct { diff --git a/scenario/go/scenario_test.go b/scenario/go/scenario_test.go index 6bfb2277e..cdccee0e2 100644 --- a/scenario/go/scenario_test.go +++ b/scenario/go/scenario_test.go @@ -21,7 +21,7 @@ import ( "github.com/cucumber/godog" messages "github.com/cucumber/messages-go/v16" "github.com/hyperledger/fabric-gateway/pkg/client" - "github.com/hyperledger/fabric-protos-go/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" diff --git a/scenario/go/transaction_test.go b/scenario/go/transaction_test.go index 6a7b849fe..9742dd294 100644 --- a/scenario/go/transaction_test.go +++ b/scenario/go/transaction_test.go @@ -11,8 +11,8 @@ import ( "github.com/hyperledger/fabric-gateway/pkg/client" "github.com/hyperledger/fabric-gateway/pkg/identity" - "github.com/hyperledger/fabric-protos-go/gateway" - "github.com/hyperledger/fabric-protos-go/peer" + "github.com/hyperledger/fabric-protos-go-apiv2/gateway" + "github.com/hyperledger/fabric-protos-go-apiv2/peer" "google.golang.org/grpc/status" )