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

Commit 7c71a98

Browse files
committed
[FAB-6391] Remove deprecated fabrictxn functions
Change-Id: I554d5039784b4b4b837d837aea74657ee9e8ba2d Signed-off-by: Sandra Vrtikapa <sandra.vrtikapa@securekey.com>
1 parent 20ff232 commit 7c71a98

File tree

22 files changed

+831
-308
lines changed

22 files changed

+831
-308
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ populate-clean:
146146

147147
clean:
148148
$(GO_CMD) clean
149-
rm -Rf /tmp/enroll_user /tmp/msp /tmp/keyvaluestore
149+
rm -Rf /tmp/enroll_user /tmp/msp /tmp/keyvaluestore /tmp/hfc-kvs
150150
rm -f integration-report.xml report.xml
151151
rm -f test/fixtures/tls/fabricca/certs/server/ca.org*.example.com-cert.pem
152152
cd test/fixtures && $(DOCKER_COMPOSE_CMD) -f docker-compose.yaml -f docker-compose-nopkcs11-test.yaml -f docker-compose-pkcs11-test.yaml down

api/apiconfig/configprovider.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const (
6161
Query
6262
// ExecuteTx timeout
6363
ExecuteTx
64-
// OrdererConnection Orderer connection timeout
64+
// OrdererConnection orderer connection timeout
6565
OrdererConnection
66-
// OrdererSendDeliver Orderer SendDeliver timeout
66+
// OrdererResponse orderer response timeout
6767
OrdererResponse
6868
)

api/apiconfig/network.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type PeerChannelConfig struct {
7777
type ChannelPeer struct {
7878
PeerChannelConfig
7979
PeerConfig
80+
MspID string
8081
}
8182

8283
// OrganizationConfig provides the definition of an organization in the network

api/apitxn/txn.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ type ExecuteTxRequest struct {
4949

5050
// ExecuteTxOpts allows the user to specify more advanced options
5151
type ExecuteTxOpts struct {
52-
Notifier chan ExecuteTxResponse // async
53-
TxFilter ExecuteTxFilter
54-
Timeout time.Duration
52+
Notifier chan ExecuteTxResponse // async
53+
TxFilter ExecuteTxFilter
54+
ProposalProcessors []ProposalProcessor // targets
55+
Timeout time.Duration
5556
}
5657

5758
// ExecuteTxFilter allows the user to inspect/modify response before commit

def/fabapi/context/defprovider/sdk.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ func (f *DefaultProviderFactory) NewConfigProvider(o opt.ConfigOpts, a opt.SDKOp
3737

3838
// NewStateStoreProvider creates a KeyValueStore using the SDK's default implementation
3939
func (f *DefaultProviderFactory) NewStateStoreProvider(o opt.StateStoreOpts, config apiconfig.Config) (fab.KeyValueStore, error) {
40-
stateStore, err := kvs.CreateNewFileKeyValueStore(o.Path)
40+
41+
var stateStorePath = o.Path
42+
if stateStorePath == "" {
43+
clientCofig, err := config.Client()
44+
if err != nil {
45+
return nil, err
46+
}
47+
stateStorePath = clientCofig.CredentialStore.Path
48+
}
49+
50+
stateStore, err := kvs.CreateNewFileKeyValueStore(stateStorePath)
4151
if err != nil {
4252
return nil, fmt.Errorf("CreateNewFileKeyValueStore returned error[%s]", err)
4353
}

def/fabapi/context/defprovider/session.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (f *SessionClientFactory) NewChannelClient(sdk context.SDK, session context
5959
return nil, fmt.Errorf("Unable to create discovery service:%v", err)
6060
}
6161

62-
eventHub, err := getEventHub(client, channelName)
62+
eventHub, err := getEventHub(client, channelName, session)
6363
if err != nil {
6464
return nil, err
6565
}
@@ -103,7 +103,7 @@ func getChannel(client fab.FabricClient, channelID string) (fab.Channel, error)
103103
return channel, nil
104104
}
105105

106-
func getEventHub(client fab.FabricClient, channelID string) (*events.EventHub, error) {
106+
func getEventHub(client fab.FabricClient, channelID string, session context.Session) (*events.EventHub, error) {
107107

108108
peerConfig, err := client.Config().ChannelPeers(channelID)
109109
if err != nil {
@@ -115,7 +115,7 @@ func getEventHub(client fab.FabricClient, channelID string) (*events.EventHub, e
115115

116116
for _, p := range peerConfig {
117117

118-
if p.EventSource {
118+
if p.EventSource && p.MspID == session.Identity().MspID() {
119119
serverHostOverride = ""
120120
if str, ok := p.GRPCOptions["ssl-target-name-override"].(string); ok {
121121
serverHostOverride = str

pkg/config/config.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,20 @@ func (c *Config) ChannelPeers(name string) ([]apiconfig.ChannelPeer, error) {
470470
p.TLSCACerts.Path = strings.Replace(p.TLSCACerts.Path, "$GOPATH", os.Getenv("GOPATH"), -1)
471471
}
472472

473-
peer := apiconfig.ChannelPeer{PeerChannelConfig: chPeerConfig, PeerConfig: p}
473+
var mspID string
474+
475+
// Find organisation/msp that peer belongs to
476+
for _, org := range netConfig.Organizations {
477+
for i := 0; i < len(org.Peers); i++ {
478+
if strings.EqualFold(org.Peers[i], peerName) {
479+
// peer belongs to this org add org msp
480+
mspID = org.MspID
481+
break
482+
}
483+
}
484+
}
485+
486+
peer := apiconfig.ChannelPeer{PeerChannelConfig: chPeerConfig, PeerConfig: p, MspID: mspID}
474487

475488
peers = append(peers, peer)
476489
}

pkg/fabric-client/mocks/mockconfig.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ func (c *MockConfig) CAClientCertFile(org string) (string, error) {
6161

6262
//TimeoutOrDefault not implemented
6363
func (c *MockConfig) TimeoutOrDefault(arg config.TimeoutType) time.Duration {
64-
65-
if arg == config.Query || arg == config.ExecuteTx {
66-
return time.Second * 10
67-
}
68-
return 0
64+
return time.Second * 10
6965
}
7066

7167
// FabricClientViper returns the internal viper instance used by the

pkg/fabric-txn/chclient/chclient.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,16 @@ func (cc *ChannelClient) QueryWithOpts(request apitxn.QueryRequest, opts apitxn.
5555
notifier = make(chan apitxn.QueryResponse)
5656
}
5757

58-
peers, err := cc.discovery.GetPeers(request.ChaincodeID)
59-
if err != nil {
60-
return nil, fmt.Errorf("Unable to get peers: %v", err)
58+
txProcessors := opts.ProposalProcessors
59+
if len(txProcessors) == 0 {
60+
// Use discovery service to figure out proposal processors
61+
peers, err := cc.discovery.GetPeers(request.ChaincodeID)
62+
if err != nil {
63+
return nil, fmt.Errorf("Unable to get peers: %v", err)
64+
}
65+
txProcessors = peer.PeersToTxnProcessors(peers)
6166
}
6267

63-
txProcessors := peer.PeersToTxnProcessors(peers)
64-
6568
go sendTransactionProposal(request, cc.channel, txProcessors, notifier)
6669

6770
if opts.Notifier != nil {
@@ -113,15 +116,20 @@ func (cc *ChannelClient) ExecuteTxWithOpts(request apitxn.ExecuteTxRequest, opts
113116
return apitxn.TransactionID{}, fmt.Errorf("Chaincode name and function name must be provided")
114117
}
115118

116-
peers, err := cc.discovery.GetPeers(request.ChaincodeID)
117-
if err != nil {
118-
return apitxn.TransactionID{}, fmt.Errorf("Unable to get peers: %v", err)
119+
txProcessors := opts.ProposalProcessors
120+
if len(txProcessors) == 0 {
121+
// Use discovery service to figure out proposal processors
122+
peers, err := cc.discovery.GetPeers(request.ChaincodeID)
123+
if err != nil {
124+
return apitxn.TransactionID{}, fmt.Errorf("Unable to get peers: %v", err)
125+
}
126+
txProcessors = peer.PeersToTxnProcessors(peers)
119127
}
120128

121129
// TODO: Temporary conversion until proposal sender is changed to handle [][]byte arguments
122130
ccArgs := toStringArray(request.Args)
123131
txProposalResponses, txID, err := internal.CreateAndSendTransactionProposal(cc.channel,
124-
request.ChaincodeID, request.Fcn, ccArgs, peer.PeersToTxnProcessors(peers), request.TransientMap)
132+
request.ChaincodeID, request.Fcn, ccArgs, txProcessors, request.TransientMap)
125133
if err != nil {
126134
return apitxn.TransactionID{}, fmt.Errorf("CreateAndSendTransactionProposal returned error: %v", err)
127135
}

pkg/fabric-txn/transaction.go

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

0 commit comments

Comments
 (0)