Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit 50281db

Browse files
committed
[FAB-5137] Split txn APIs into their own pkg
Change-Id: I418ccb1fc00931c8e25fcd60bc53db596bb2f6a3 Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent f7b2f4f commit 50281db

29 files changed

+217
-178
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ integration-tests: integration-test
4747
mock-gen:
4848
go get -u github.com/golang/mock/gomock
4949
go get -u github.com/golang/mock/mockgen
50-
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/txnapi TxnProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/txnapi/mocks/mocktxnapi.gen.go
50+
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api/apitxn ProposalProcessor | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/apitxn/mocks/mockapitxn.gen.go
5151
mockgen -build_flags '$(LDFLAGS)' github.com/hyperledger/fabric-sdk-go/api Config | sed "s/github.com\/hyperledger\/fabric-sdk-go\/vendor\///g" > api/mocks/mockconfig.gen.go
5252

5353
clean:

api/apitxn/mocks/mockapitxn.gen.go

Lines changed: 45 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ Copyright SecureKey Technologies Inc. All Rights Reserved.
44
SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
// Package txnapi allows SDK users to plugin their own implementations of transaction processing.
8-
package txnapi
7+
// Package apitxn allows SDK users to plugin their own implementations of transaction processing.
8+
package apitxn
99

1010
import (
1111
pb "github.com/hyperledger/fabric/protos/peer"
1212
)
1313

14-
// TxnProposalProcessor simulates transaction proposal, so that a client can submit the result for ordering.
15-
type TxnProposalProcessor interface {
14+
// ProposalProcessor simulates transaction proposal, so that a client can submit the result for ordering.
15+
type ProposalProcessor interface {
1616
ProcessTransactionProposal(proposal TransactionProposal) (TransactionProposalResult, error)
1717
}
1818

api/apitxn/sender.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright SecureKey Technologies Inc. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// Package apitxn allows SDK users to plugin their own implementations of transaction processing.
8+
package apitxn
9+
10+
import (
11+
pb "github.com/hyperledger/fabric/protos/peer"
12+
)
13+
14+
// Sender provides the ability for a transaction to be created and sent.
15+
type Sender interface {
16+
CreateTransaction(resps []*TransactionProposalResponse) (*Transaction, error)
17+
SendTransaction(tx *Transaction) ([]*TransactionResponse, error)
18+
}
19+
20+
// ProposalSender provides the ability for a transaction proposal to be created and sent.
21+
type ProposalSender interface {
22+
CreateTransactionProposal(chaincodeName string, channelID string, args []string, sign bool, transientData map[string][]byte) (*TransactionProposal, error)
23+
SendTransactionProposal(proposal *TransactionProposal, retry int, targets []ProposalProcessor) ([]*TransactionProposalResponse, error)
24+
}
25+
26+
// The Transaction object created from an endorsed proposal.
27+
type Transaction struct {
28+
Proposal *TransactionProposal
29+
Transaction *pb.Transaction
30+
}
31+
32+
// TransactionResponse contains information returned by the orderer.
33+
type TransactionResponse struct {
34+
Orderer string
35+
Err error
36+
}

api/channel.go

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package api
88

99
import (
10-
"github.com/hyperledger/fabric-sdk-go/api/txnapi"
10+
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
1111
"github.com/hyperledger/fabric/msp"
1212
"github.com/hyperledger/fabric/protos/common"
1313
pb "github.com/hyperledger/fabric/protos/peer"
@@ -24,12 +24,22 @@ import (
2424
* primary orderer to retrieve the configuration settings for this channel.
2525
*/
2626
type Channel interface {
27+
txn.Sender
28+
txn.ProposalSender
29+
2730
Name() string
2831
Initialize(data []byte) error
2932
IsInitialized() bool
3033
IsSecurityEnabled() bool
34+
QueryExtensionInterface() ChannelExtension
35+
LoadConfigUpdateEnvelope(data []byte) error
36+
SendInstantiateProposal(chaincodeName string, channelID string, args []string, chaincodePath string, chaincodeVersion string, targets []txn.ProposalProcessor) ([]*txn.TransactionProposalResponse, string, error)
37+
38+
// TCerts
3139
TCertBatchSize() int
3240
SetTCertBatchSize(batchSize int)
41+
42+
// Network
3343
AddPeer(peer Peer) error
3444
RemovePeer(peer Peer)
3545
Peers() []Peer
@@ -41,37 +51,32 @@ type Channel interface {
4151
Orderers() []Orderer
4252
SetMSPManager(mspManager msp.MSPManager)
4353
MSPManager() msp.MSPManager
54+
OrganizationUnits() ([]string, error)
55+
56+
// Channel Info
4457
GenesisBlock(request *GenesisBlockRequest) (*common.Block, error)
4558
JoinChannel(request *JoinChannelRequest) error
4659
UpdateChannel() bool
4760
IsReadonly() bool
61+
62+
// Query
4863
QueryInfo() (*common.BlockchainInfo, error)
4964
QueryBlock(blockNumber int) (*common.Block, error)
5065
QueryBlockByHash(blockHash []byte) (*common.Block, error)
5166
QueryTransaction(transactionID string) (*pb.ProcessedTransaction, error)
5267
QueryInstantiatedChaincodes() (*pb.ChaincodeQueryResponse, error)
53-
QueryByChaincode(chaincodeName string, args []string, targets []Peer) ([][]byte, error)
54-
SendInstantiateProposal(chaincodeName string, channelID string, args []string, chaincodePath string, chaincodeVersion string, targets []Peer) ([]*txnapi.TransactionProposalResponse, string, error)
55-
OrganizationUnits() ([]string, error)
56-
QueryExtensionInterface() ChannelExtension
57-
LoadConfigUpdateEnvelope(data []byte) error
58-
59-
// Transaction Proposal
60-
CreateTransactionProposal(chaincodeName string, channelID string, args []string, sign bool, transientData map[string][]byte) (*txnapi.TransactionProposal, error)
61-
SendTransactionProposal(proposal *txnapi.TransactionProposal, retry int, targets []Peer) ([]*txnapi.TransactionProposalResponse, error)
62-
CreateTransaction(resps []*txnapi.TransactionProposalResponse) (*Transaction, error)
63-
SendTransaction(tx *Transaction) ([]*TransactionResponse, error)
68+
QueryByChaincode(chaincodeName string, args []string, targets []txn.ProposalProcessor) ([][]byte, error)
6469
}
6570

6671
// The ChannelExtension interface allows extensions of the SDK to add functionality to Channel overloads.
6772
type ChannelExtension interface {
6873
ClientContext() FabricClient
6974

7075
SignPayload(payload []byte) (*SignedEnvelope, error)
71-
BroadcastEnvelope(envelope *SignedEnvelope) ([]*TransactionResponse, error)
76+
BroadcastEnvelope(envelope *SignedEnvelope) ([]*txn.TransactionResponse, error)
7277

7378
// TODO: This should go somewhere else - see TransactionProposal.GetBytes(). - deprecated
74-
ProposalBytes(tp *txnapi.TransactionProposal) ([]byte, error)
79+
ProposalBytes(tp *txn.TransactionProposal) ([]byte, error)
7580
}
7681

7782
// OrgAnchorPeer contains information about an anchor peer on this channel
@@ -94,18 +99,3 @@ type JoinChannelRequest struct {
9499
TxID string
95100
Nonce []byte
96101
}
97-
98-
// The Transaction object created from an endorsed proposal
99-
type Transaction struct {
100-
Proposal *txnapi.TransactionProposal
101-
Transaction *pb.Transaction
102-
}
103-
104-
// TransactionResponse ...
105-
/**
106-
* The TransactionProposalResponse result object returned from orderers.
107-
*/
108-
type TransactionResponse struct {
109-
Orderer string
110-
Err error
111-
}

api/fabricclient.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ SPDX-License-Identifier: Apache-2.0
77
package api
88

99
import (
10-
"github.com/hyperledger/fabric-sdk-go/api/txnapi"
10+
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
1111
"github.com/hyperledger/fabric/bccsp"
1212
"github.com/hyperledger/fabric/protos/common"
1313
pb "github.com/hyperledger/fabric/protos/peer"
@@ -43,7 +43,7 @@ type FabricClient interface {
4343
GetCryptoSuite() bccsp.BCCSP
4444
SaveUserToStateStore(user User, skipPersistence bool) error
4545
LoadUserFromStateStore(name string) (User, error)
46-
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*txnapi.TransactionProposalResponse, string, error)
46+
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*txn.TransactionProposalResponse, string, error)
4747
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)
4848
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
4949
GetIdentity() ([]byte, error)

api/peer.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package api
99
import (
1010
"encoding/pem"
1111

12-
"github.com/hyperledger/fabric-sdk-go/api/txnapi"
12+
txn "github.com/hyperledger/fabric-sdk-go/api/apitxn"
1313
)
1414

1515
// The Peer class represents a peer in the target blockchain network to which
@@ -26,7 +26,7 @@ import (
2626
// It should be noted that Peer event streams function at the Peer level and not at the
2727
// channel and chaincode levels.
2828
type Peer interface {
29-
txnapi.TxnProposalProcessor
29+
txn.ProposalProcessor
3030

3131
// Events (need verb)
3232
ConnectEventSource()
@@ -45,3 +45,13 @@ type Peer interface {
4545
SetRoles(roles []string)
4646
URL() string
4747
}
48+
49+
// PeersToTxnProcessors converts a slice of Peers to a slice of TxnProposalProcessors
50+
func PeersToTxnProcessors(peers []Peer) []txn.ProposalProcessor {
51+
tpp := make([]txn.ProposalProcessor, len(peers))
52+
53+
for i := range peers {
54+
tpp[i] = peers[i]
55+
}
56+
return tpp
57+
}

api/txnapi/mocks/mocktxnapi.gen.go

Lines changed: 0 additions & 45 deletions
This file was deleted.

pkg/config/config.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import (
1818
"strings"
1919
"time"
2020

21-
api "github.com/hyperledger/fabric-sdk-go/api"
22-
21+
"github.com/hyperledger/fabric-sdk-go/api"
2322
bccspFactory "github.com/hyperledger/fabric/bccsp/factory"
2423
"github.com/op/go-logging"
2524
"github.com/spf13/viper"

pkg/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"testing"
1515

16-
api "github.com/hyperledger/fabric-sdk-go/api"
16+
"github.com/hyperledger/fabric-sdk-go/api"
1717
"github.com/spf13/viper"
1818
)
1919

0 commit comments

Comments
 (0)