Skip to content

Commit

Permalink
[FAB-7998] Move client APIs to apifabclient
Browse files Browse the repository at this point in the history
Change-Id: I58b23bb2f9f662acbc6d0fe7921f101651f37284
Signed-off-by: Troy Ronda <troy@troyronda.com>
  • Loading branch information
troyronda committed Feb 2, 2018
1 parent cb5e581 commit 913ef17
Show file tree
Hide file tree
Showing 41 changed files with 239 additions and 267 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ dockerenv-latest-up: clean

.PHONY: mock-gen
mock-gen:
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apitxn ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apitxn/mocks/mockapitxn.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apifabclient ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apifabclient/mocks/mockfabclient.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apiconfig Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apiconfig/mocks/mockconfig.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/api/apifabca FabricCAClient | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > api/apifabca/mocks/mockfabriccaclient.gen.go
mockgen -build_flags '$(GO_LDFLAGS_ARG)' github.com/hyperledger/fabric-sdk-go/pkg/fabsdk/api CoreProviders,SvcProviders,Providers,CoreProviderFactory,ServiceProviderFactory,OrgClientFactory,SessionClientFactory | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" | goimports > pkg/fabsdk/api/mocks/mocksdkapi.gen.go
Expand Down
13 changes: 6 additions & 7 deletions api/apifabclient/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
package apifabclient

import (
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
Expand All @@ -24,14 +23,14 @@ import (
* primary orderer to retrieve the configuration settings for this channel.
*/
type Channel interface {
txn.Sender
txn.ProposalSender
Sender
ProposalSender

Name() string
ChannelConfig() (*common.ConfigEnvelope, error)
SendInstantiateProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope,
collConfig []*common.CollectionConfig, targets []txn.ProposalProcessor) ([]*txn.TransactionProposalResponse, txn.TransactionID, error)
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []txn.ProposalProcessor) ([]*txn.TransactionProposalResponse, txn.TransactionID, error)
collConfig []*common.CollectionConfig, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)
SendUpgradeProposal(chaincodeName string, args [][]byte, chaincodePath string, chaincodeVersion string, chaincodePolicy *common.SignaturePolicyEnvelope, targets []ProposalProcessor) ([]*TransactionProposalResponse, TransactionID, error)

// Network
// TODO: Use PeerEndorser
Expand Down Expand Up @@ -60,8 +59,8 @@ type Channel interface {
QueryBlockByHash(blockHash []byte) (*common.Block, error)
QueryTransaction(transactionID string) (*pb.ProcessedTransaction, error)
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
QueryByChaincode(txn.ChaincodeInvokeRequest) ([][]byte, error)
QueryBySystemChaincode(request txn.ChaincodeInvokeRequest) ([][]byte, error)
QueryByChaincode(ChaincodeInvokeRequest) ([][]byte, error)
QueryBySystemChaincode(request ChaincodeInvokeRequest) ([][]byte, error)
QueryConfigBlock(peers []Peer, minResponses int) (*common.ConfigEnvelope, error)
}

Expand Down
5 changes: 2 additions & 3 deletions api/apifabclient/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package apifabclient
import (
"crypto/x509"

"github.com/hyperledger/fabric-sdk-go/api/apitxn"
common "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
ehpb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
Expand All @@ -23,8 +22,8 @@ type EventHub interface {
Disconnect() error
RegisterChaincodeEvent(ccid string, eventname string, callback func(*ChaincodeEvent)) *ChainCodeCBE
UnregisterChaincodeEvent(cbe *ChainCodeCBE)
RegisterTxEvent(txnID apitxn.TransactionID, callback func(string, pb.TxValidationCode, error))
UnregisterTxEvent(txnID apitxn.TransactionID)
RegisterTxEvent(txnID TransactionID, callback func(string, pb.TxValidationCode, error))
UnregisterTxEvent(txnID TransactionID)
RegisterBlockEvent(callback func(*common.Block))
UnregisterBlockEvent(callback func(*common.Block))
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions api/apifabclient/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ package apifabclient

import (
"encoding/pem"

txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
)

// The Peer class represents a peer in the target blockchain network to which
Expand All @@ -26,7 +24,7 @@ import (
// It should be noted that Peer event streams function at the Peer level and not at the
// channel and chaincode levels.
type Peer interface {
txn.ProposalProcessor
ProposalProcessor

// ECert Client (need verb)
EnrollmentCertificate() *pem.Block
Expand Down
3 changes: 1 addition & 2 deletions api/apitxn/proposer.go → api/apifabclient/proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// Package apitxn allows SDK users to plugin their own implementations of transaction processing.
package apitxn
package apifabclient

import (
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
Expand Down
9 changes: 4 additions & 5 deletions api/apifabclient/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ SPDX-License-Identifier: Apache-2.0
package apifabclient

import (
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

// Resource is a client that provides access to fabric resources such as chaincode.
type Resource interface {
CreateChannel(request CreateChannelRequest) (txn.TransactionID, error)
InstallChaincode(request InstallChaincodeRequest) ([]*txn.TransactionProposalResponse, string, error)
CreateChannel(request CreateChannelRequest) (TransactionID, error)
InstallChaincode(request InstallChaincodeRequest) ([]*TransactionProposalResponse, string, error)
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)

Expand Down Expand Up @@ -45,7 +44,7 @@ type CreateChannelRequest struct {

// TODO: InvokeChannelRequest allows the TransactionID to be passed in.
// This request struct also has the field for consistency but perhaps it should be removed.
TxnID txn.TransactionID
TxnID TransactionID
}

// InstallChaincodeRequest requests chaincode installation on the network
Expand All @@ -59,7 +58,7 @@ type InstallChaincodeRequest struct {
// required - package (chaincode package type and bytes)
Package *CCPackage
// required - proposal processor list
Targets []txn.ProposalProcessor
Targets []ProposalProcessor
}

// CCPackage contains package type and bytes required to create CDS
Expand Down
3 changes: 1 addition & 2 deletions api/apitxn/sender.go → api/apifabclient/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

// Package apitxn allows SDK users to plugin their own implementations of transaction processing.
package apitxn
package apifabclient

import (
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
Expand Down
10 changes: 5 additions & 5 deletions api/apitxn/chclient/chclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package chclient
import (
"time"

"github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/retry"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)
Expand All @@ -25,14 +25,14 @@ type Request struct {
//Response contains response parameters for query and execute transaction
type Response struct {
Payload []byte
TransactionID apitxn.TransactionID
TransactionID apifabclient.TransactionID
TxValidationCode pb.TxValidationCode
Responses []*apitxn.TransactionProposalResponse
Responses []*apifabclient.TransactionProposalResponse
}

// Opts allows the user to specify more advanced options
type Opts struct {
ProposalProcessors []apitxn.ProposalProcessor // targets
ProposalProcessors []apifabclient.ProposalProcessor // targets
Timeout time.Duration
Retry retry.Opts
}
Expand All @@ -43,7 +43,7 @@ type Option func(opts *Opts) error
// TxProposalResponseFilter allows the user to inspect/modify response before commit
type TxProposalResponseFilter interface {
// process transaction proposal response (there will be no commit if an error is returned)
ProcessTxProposalResponse(txProposalResponse []*apitxn.TransactionProposalResponse) ([]*apitxn.TransactionProposalResponse, error)
ProcessTxProposalResponse(txProposalResponse []*apifabclient.TransactionProposalResponse) ([]*apifabclient.TransactionProposalResponse, error)
}

// Registration is a handle that is returned from a successful Register Chaincode Event.
Expand Down
4 changes: 2 additions & 2 deletions api/apitxn/chclient/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ package chclient
import (
"time"

"github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/pkg/errors/retry"
)

Expand All @@ -22,7 +22,7 @@ func WithTimeout(timeout time.Duration) Option {
}

//WithProposalProcessor encapsulates ProposalProcessors to Option
func WithProposalProcessor(proposalProcessors ...apitxn.ProposalProcessor) Option {
func WithProposalProcessor(proposalProcessors ...apifabclient.ProposalProcessor) Option {
return func(opts *Opts) error {
opts.ProposalProcessors = proposalProcessors
return nil
Expand Down
25 changes: 12 additions & 13 deletions pkg/fabric-client/channel/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ import (
"strconv"

"github.com/golang/protobuf/proto"
"github.com/pkg/errors"

fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -133,8 +132,8 @@ func (c *Channel) QueryTransaction(transactionID string) (*pb.ProcessedTransacti
// This query will be made to the primary peer.
func (c *Channel) QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error) {

targets := []txn.ProposalProcessor{c.PrimaryPeer()}
request := txn.ChaincodeInvokeRequest{
targets := []fab.ProposalProcessor{c.PrimaryPeer()}
request := fab.ChaincodeInvokeRequest{
Targets: targets,
ChaincodeID: "lscc",
Fcn: "getchaincodes",
Expand All @@ -159,15 +158,15 @@ func (c *Channel) QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, err
// from the arguments that this is a query request. The chaincode must also return
// results in the byte array format and the caller will have to be able to decode.
// these results.
func (c *Channel) QueryByChaincode(request txn.ChaincodeInvokeRequest) ([][]byte, error) {
func (c *Channel) QueryByChaincode(request fab.ChaincodeInvokeRequest) ([][]byte, error) {
request, err := c.chaincodeInvokeRequestAddDefaultPeers(request)
if err != nil {
return nil, err
}
return queryByChaincode(c.name, request, c.clientContext)
}

func filterProposalResponses(tpr []*txn.TransactionProposalResponse) ([][]byte, error) {
func filterProposalResponses(tpr []*fab.TransactionProposalResponse) ([][]byte, error) {
var responses [][]byte
errMsg := ""
for _, response := range tpr {
Expand All @@ -184,7 +183,7 @@ func filterProposalResponses(tpr []*txn.TransactionProposalResponse) ([][]byte,
return responses, nil
}

func queryByChaincode(channelID string, request txn.ChaincodeInvokeRequest, clientContext fab.Context) ([][]byte, error) {
func queryByChaincode(channelID string, request fab.ChaincodeInvokeRequest, clientContext fab.Context) ([][]byte, error) {
if err := validateChaincodeInvokeRequest(request); err != nil {
return nil, err
}
Expand All @@ -200,9 +199,9 @@ func queryByChaincode(channelID string, request txn.ChaincodeInvokeRequest, clie
// queryBySystemChaincodeByTarget is an internal helper function that queries system chaincode.
// This function is not exported to keep the external interface of this package to only expose
// request structs.
func (c *Channel) queryBySystemChaincodeByTarget(chaincodeID string, fcn string, args [][]byte, target txn.ProposalProcessor) ([]byte, error) {
targets := []txn.ProposalProcessor{target}
request := txn.ChaincodeInvokeRequest{
func (c *Channel) queryBySystemChaincodeByTarget(chaincodeID string, fcn string, args [][]byte, target fab.ProposalProcessor) ([]byte, error) {
targets := []fab.ProposalProcessor{target}
request := fab.ChaincodeInvokeRequest{
ChaincodeID: chaincodeID,
Fcn: fcn,
Args: args,
Expand All @@ -221,7 +220,7 @@ func (c *Channel) queryBySystemChaincodeByTarget(chaincodeID string, fcn string,
// QueryBySystemChaincode invokes a chaincode that isn't part of a channel.
//
// TODO: This function's name is confusing - call the normal QueryByChaincode for system chaincode on a channel.
func (c *Channel) QueryBySystemChaincode(request txn.ChaincodeInvokeRequest) ([][]byte, error) {
func (c *Channel) QueryBySystemChaincode(request fab.ChaincodeInvokeRequest) ([][]byte, error) {
request, err := c.chaincodeInvokeRequestAddDefaultPeers(request)
if err != nil {
return nil, err
Expand All @@ -231,7 +230,7 @@ func (c *Channel) QueryBySystemChaincode(request txn.ChaincodeInvokeRequest) ([]

// QueryBySystemChaincode invokes a system chaincode
// TODO - should be moved.
func QueryBySystemChaincode(request txn.ChaincodeInvokeRequest, clientContext fab.Context) ([][]byte, error) {
func QueryBySystemChaincode(request fab.ChaincodeInvokeRequest, clientContext fab.Context) ([][]byte, error) {
return queryByChaincode(systemChannel, request, clientContext)
}

Expand All @@ -247,7 +246,7 @@ func (c *Channel) QueryConfigBlock(peers []fab.Peer, minResponses int) (*common.
return nil, errors.New("Minimum endorser has to be greater than zero")
}

request := txn.ChaincodeInvokeRequest{
request := fab.ChaincodeInvokeRequest{
ChaincodeID: "cscc",
Fcn: "GetConfigBlock",
Args: [][]byte{[]byte(c.Name())},
Expand Down
17 changes: 8 additions & 9 deletions pkg/fabric-client/channel/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/golang/protobuf/proto"
fab "github.com/hyperledger/fabric-sdk-go/api/apifabclient"
"github.com/hyperledger/fabric-sdk-go/api/apitxn"
"github.com/hyperledger/fabric-sdk-go/pkg/fabric-client/mocks"
)

Expand All @@ -28,7 +27,7 @@ func TestQueryMethods(t *testing.T) {
t.Fatalf("Query hash cannot be nil")
}

badRequest1 := apitxn.ChaincodeInvokeRequest{
badRequest1 := fab.ChaincodeInvokeRequest{
Fcn: "method",
Args: [][]byte{[]byte("arg")},
}
Expand All @@ -37,15 +36,15 @@ func TestQueryMethods(t *testing.T) {
t.Fatalf("QueryByChannelcode: name cannot be empty")
}

badRequest2 := apitxn.ChaincodeInvokeRequest{
badRequest2 := fab.ChaincodeInvokeRequest{
ChaincodeID: "qscc",
}
_, err = channel.QueryByChaincode(badRequest2)
if err == nil {
t.Fatalf("QueryByChannelcode: arguments cannot be empty")
}

badRequest3 := apitxn.ChaincodeInvokeRequest{
badRequest3 := fab.ChaincodeInvokeRequest{
ChaincodeID: "qscc",
Fcn: "method",
Args: [][]byte{[]byte("arg")},
Expand Down Expand Up @@ -121,7 +120,7 @@ func TestQueryInfo(t *testing.T) {
func TestQueryMissingParams(t *testing.T) {
channel, _ := setupTestChannel()

request := apitxn.ChaincodeInvokeRequest{
request := fab.ChaincodeInvokeRequest{
ChaincodeID: "cc",
Fcn: "Hello",
}
Expand All @@ -137,23 +136,23 @@ func TestQueryMissingParams(t *testing.T) {
peer := mocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", MockRoles: []string{}, MockCert: nil, Payload: []byte("A")}
channel.AddPeer(&peer)

request = apitxn.ChaincodeInvokeRequest{
request = fab.ChaincodeInvokeRequest{
Fcn: "Hello",
}
_, err = channel.QueryByChaincode(request)
if err == nil {
t.Fatalf("Expected error")
}

request = apitxn.ChaincodeInvokeRequest{
request = fab.ChaincodeInvokeRequest{
ChaincodeID: "cc",
}
_, err = channel.QueryByChaincode(request)
if err == nil {
t.Fatalf("Expected error")
}

request = apitxn.ChaincodeInvokeRequest{
request = fab.ChaincodeInvokeRequest{
ChaincodeID: "cc",
Fcn: "Hello",
}
Expand All @@ -169,7 +168,7 @@ func TestQueryBySystemChaincode(t *testing.T) {
peer := mocks.MockPeer{MockName: "Peer1", MockURL: "http://peer1.com", MockRoles: []string{}, MockCert: nil, Payload: []byte("A")}
channel.AddPeer(&peer)

request := apitxn.ChaincodeInvokeRequest{
request := fab.ChaincodeInvokeRequest{
ChaincodeID: "cc",
Fcn: "Hello",
}
Expand Down
Loading

0 comments on commit 913ef17

Please sign in to comment.