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

Commit cc9e96a

Browse files
committed
[FAB-5235] Normalize Getter Names
Change-Id: I640995f4507b8de54cac1218f2b53a30ab2b4bfb Signed-off-by: Troy Ronda <troy@troyronda.com>
1 parent fe06786 commit cc9e96a

File tree

16 files changed

+91
-109
lines changed

16 files changed

+91
-109
lines changed

api/apifabclient/fabricclient.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,23 @@ import (
3333
*/
3434
type FabricClient interface {
3535
NewChannel(name string) (Channel, error)
36-
GetChannel(name string) Channel
36+
Channel(name string) Channel
3737
ExtractChannelConfig(configEnvelope []byte) ([]byte, error)
3838
SignChannelConfig(config []byte) (*common.ConfigSignature, error)
3939
CreateChannel(request CreateChannelRequest) (txn.TransactionID, error)
4040
QueryChannelInfo(name string, peers []Peer) (Channel, error)
4141
SetStateStore(stateStore KeyValueStore)
42-
GetStateStore() KeyValueStore
42+
StateStore() KeyValueStore
4343
SetCryptoSuite(cryptoSuite bccsp.BCCSP)
44-
GetCryptoSuite() bccsp.BCCSP
44+
CryptoSuite() bccsp.BCCSP
4545
SaveUserToStateStore(user User, skipPersistence bool) error
4646
LoadUserFromStateStore(name string) (User, error)
4747
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*txn.TransactionProposalResponse, string, error)
4848
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)
4949
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
50-
GetUserContext() User
50+
UserContext() User
5151
SetUserContext(user User)
52-
GetConfig() config.Config // TODO: refactor to a fab client config interface
52+
Config() config.Config // TODO: refactor to a fab client config interface
5353
NewTxnID() (txn.TransactionID, error)
5454
}
5555

def/fabapi/fabapi.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ func NewClientWithUser(name string, pwd string, orgName string,
6060
return nil, fmt.Errorf("CreateNewFileKeyValueStore returned error[%s]", err)
6161
}
6262
client.SetStateStore(stateStore)
63-
mspID, err := client.GetConfig().MspID(orgName)
63+
mspID, err := client.Config().MspID(orgName)
6464
if err != nil {
6565
return nil, fmt.Errorf("Error reading MSP ID config: %s", err)
6666
}
6767

68-
user, err := NewUser(client.GetConfig(), msp, name, pwd, mspID)
68+
user, err := NewUser(client.Config(), msp, name, pwd, mspID)
6969
if err != nil {
7070
return nil, fmt.Errorf("NewUser returned error: %v", err)
7171
}
@@ -97,11 +97,11 @@ func NewClientWithPreEnrolledUser(config config.Config, stateStorePath string,
9797
}
9898
client.SetStateStore(stateStore)
9999
}
100-
mspID, err := client.GetConfig().MspID(orgName)
100+
mspID, err := client.Config().MspID(orgName)
101101
if err != nil {
102102
return nil, fmt.Errorf("Error reading MSP ID config: %s", err)
103103
}
104-
user, err := NewPreEnrolledUser(client.GetConfig(), keyDir, certDir, username, mspID, client.GetCryptoSuite())
104+
user, err := NewPreEnrolledUser(client.Config(), keyDir, certDir, username, mspID, client.CryptoSuite())
105105
if err != nil {
106106
return nil, fmt.Errorf("NewPreEnrolledUser returned error: %v", err)
107107
}

pkg/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func TestCSPConfig(t *testing.T) {
268268
}
269269
}
270270

271-
func TestGetPeersConfig(t *testing.T) {
271+
func TestPeersConfig(t *testing.T) {
272272
pc, err := configImpl.PeersConfig(org1)
273273
if err != nil {
274274
t.Fatalf(err.Error())

pkg/fabric-client/channel/block.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ func (c *Channel) GenesisBlock(request *fab.GenesisBlockRequest) (*common.Block,
4242
return nil, fmt.Errorf("GenesisBlock - error: Missing nonce input parameter with the required single use number")
4343
}
4444

45-
if c.clientContext.GetUserContext() == nil {
45+
if c.clientContext.UserContext() == nil {
4646
return nil, fmt.Errorf("User context needs to be set")
4747
}
48-
creator, err := c.clientContext.GetUserContext().Identity()
48+
creator, err := c.clientContext.UserContext().Identity()
4949
if err != nil {
5050
return nil, fmt.Errorf("Error getting creator: %v", err)
5151
}
@@ -93,10 +93,10 @@ func (c *Channel) block(pos *ab.SeekPosition) (*common.Block, error) {
9393
return nil, fmt.Errorf("error when generating nonce: %v", err)
9494
}
9595

96-
if c.clientContext.GetUserContext() == nil {
96+
if c.clientContext.UserContext() == nil {
9797
return nil, fmt.Errorf("User context needs to be set")
9898
}
99-
creator, err := c.clientContext.GetUserContext().Identity()
99+
creator, err := c.clientContext.UserContext().Identity()
100100
if err != nil {
101101
return nil, fmt.Errorf("error when serializing identity: %v", err)
102102
}

pkg/fabric-client/channel/channel.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ type Channel struct {
3434

3535
// ClientContext ...
3636
type ClientContext interface {
37-
GetUserContext() fab.User
38-
GetCryptoSuite() bccsp.BCCSP
37+
UserContext() fab.User
38+
CryptoSuite() bccsp.BCCSP
3939
NewTxnID() (apitxn.TransactionID, error)
4040
// TODO: ClientContext.IsSecurityEnabled()
4141
}
@@ -53,7 +53,7 @@ func NewChannel(name string, client fab.FabricClient) (*Channel, error) {
5353
}
5454
p := make(map[string]fab.Peer)
5555
o := make(map[string]fab.Orderer)
56-
c := Channel{name: name, securityEnabled: client.GetConfig().IsSecurityEnabled(), peers: p,
56+
c := Channel{name: name, securityEnabled: client.Config().IsSecurityEnabled(), peers: p,
5757
orderers: o, clientContext: client, mspManager: msp.NewMSPManager()}
5858
logger.Infof("Constructed channel instance: %v", c)
5959

pkg/fabric-client/channel/txnproposer.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ func newTransactionProposal(channelID string, request apitxn.ChaincodeInvokeRequ
113113
Input: &pb.ChaincodeInput{Args: argsArray}}}
114114

115115
// create a proposal from a ChaincodeInvocationSpec
116-
if clientContext.GetUserContext() == nil {
116+
if clientContext.UserContext() == nil {
117117
return nil, fmt.Errorf("User context needs to be set")
118118
}
119-
creator, err := clientContext.GetUserContext().Identity()
119+
creator, err := clientContext.UserContext().Identity()
120120
if err != nil {
121121
return nil, fmt.Errorf("Error getting creator: %v", err)
122122
}
@@ -132,13 +132,13 @@ func newTransactionProposal(channelID string, request apitxn.ChaincodeInvokeRequ
132132
return nil, fmt.Errorf("Error marshalling proposal: %v", err)
133133
}
134134

135-
user := clientContext.GetUserContext()
135+
user := clientContext.UserContext()
136136
if user == nil {
137137
return nil, fmt.Errorf("Error getting user context: %s", err)
138138
}
139139

140140
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(),
141-
&bccsp.SHAOpts{}, nil, clientContext.GetCryptoSuite())
141+
&bccsp.SHAOpts{}, nil, clientContext.CryptoSuite())
142142
if err != nil {
143143
return nil, err
144144
}
@@ -175,7 +175,7 @@ func (c *Channel) ProposalBytes(tp *apitxn.TransactionProposal) ([]byte, error)
175175
}
176176

177177
func (c *Channel) signProposal(proposal *pb.Proposal) (*pb.SignedProposal, error) {
178-
user := c.clientContext.GetUserContext()
178+
user := c.clientContext.UserContext()
179179
if user == nil {
180180
return nil, fmt.Errorf("User is nil")
181181
}
@@ -185,7 +185,7 @@ func (c *Channel) signProposal(proposal *pb.Proposal) (*pb.SignedProposal, error
185185
return nil, fmt.Errorf("Error mashalling proposal: %s", err)
186186
}
187187

188-
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.clientContext.GetCryptoSuite())
188+
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.clientContext.CryptoSuite())
189189
if err != nil {
190190
return nil, fmt.Errorf("Error signing proposal: %s", err)
191191
}
@@ -232,10 +232,10 @@ func (c *Channel) JoinChannel(request *fab.JoinChannelRequest) error {
232232
return fmt.Errorf("JoinChannel - error: Missing block input parameter with the required genesis block")
233233
}
234234

235-
if c.clientContext.GetUserContext() == nil {
235+
if c.clientContext.UserContext() == nil {
236236
return fmt.Errorf("User context needs to be set")
237237
}
238-
creator, err := c.clientContext.GetUserContext().Identity()
238+
creator, err := c.clientContext.UserContext().Identity()
239239
if err != nil {
240240
return fmt.Errorf("Error getting creator ID: %v", err)
241241
}

pkg/fabric-client/channel/txnsender.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,14 @@ func (c *Channel) SendInstantiateProposal(chaincodeName string,
188188
Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: chaincodeName, Path: chaincodePath, Version: chaincodeVersion},
189189
Input: &pb.ChaincodeInput{Args: argsArray}}}
190190

191-
if c.clientContext.GetUserContext() == nil {
191+
if c.clientContext.UserContext() == nil {
192192
return nil, apitxn.TransactionID{}, fmt.Errorf("User context needs to be set")
193193
}
194-
creator, err := c.clientContext.GetUserContext().Identity()
194+
creator, err := c.clientContext.UserContext().Identity()
195195
if err != nil {
196196
return nil, apitxn.TransactionID{}, fmt.Errorf("Error getting creator: %v", err)
197197
}
198-
chaincodePolicy, err := buildChaincodePolicy(c.clientContext.GetUserContext().MspID())
198+
chaincodePolicy, err := buildChaincodePolicy(c.clientContext.UserContext().MspID())
199199
if err != nil {
200200
return nil, apitxn.TransactionID{}, err
201201
}
@@ -228,13 +228,13 @@ func (c *Channel) SendInstantiateProposal(chaincodeName string,
228228
// SignPayload ... TODO.
229229
func (c *Channel) SignPayload(payload []byte) (*fab.SignedEnvelope, error) {
230230
//Get user info
231-
user := c.clientContext.GetUserContext()
231+
user := c.clientContext.UserContext()
232232
if user == nil {
233233
return nil, fmt.Errorf("User is nil")
234234
}
235235

236236
signature, err := fc.SignObjectWithKey(payload, user.PrivateKey(),
237-
&bccsp.SHAOpts{}, nil, c.clientContext.GetCryptoSuite())
237+
&bccsp.SHAOpts{}, nil, c.clientContext.CryptoSuite())
238238
if err != nil {
239239
return nil, err
240240
}

pkg/fabric-client/client.go

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,14 @@ func (c *Client) NewChannel(name string) (fab.Channel, error) {
6464
return c.channels[name], nil
6565
}
6666

67-
// GetConfig ...
68-
func (c *Client) GetConfig() config.Config {
67+
// Config returns the configuration of the client.
68+
func (c *Client) Config() config.Config {
6969
return c.config
7070
}
7171

72-
// GetChannel ...
73-
/*
74-
* Get a {@link Channel} instance from the state storage. This allows existing channel instances to be saved
75-
* for retrieval later and to be shared among instances of the application. Note that it’s the
76-
* application/SDK’s responsibility to record the channel information. If an application is not able
77-
* to look up the channel information from storage, it may call another API that queries one or more
78-
* Peers for that information.
79-
* @param {string} name The name of the channel.
80-
* @returns {Channel} The channel instance
81-
*/
82-
func (c *Client) GetChannel(name string) fab.Channel {
83-
return c.channels[name]
72+
// Channel returns the channel by ID
73+
func (c *Client) Channel(id string) fab.Channel {
74+
return c.channels[id]
8475
}
8576

8677
// QueryChannelInfo ...
@@ -107,27 +98,18 @@ func (c *Client) SetStateStore(stateStore fab.KeyValueStore) {
10798
c.stateStore = stateStore
10899
}
109100

110-
// GetStateStore ...
111-
/*
112-
* A convenience method for obtaining the state store object in use for this client.
113-
*/
114-
func (c *Client) GetStateStore() fab.KeyValueStore {
101+
// StateStore is a convenience method for obtaining the state store object in use for this client.
102+
func (c *Client) StateStore() fab.KeyValueStore {
115103
return c.stateStore
116104
}
117105

118-
// SetCryptoSuite ...
119-
/*
120-
* A convenience method for obtaining the state store object in use for this client.
121-
*/
106+
// SetCryptoSuite is a convenience method for obtaining the state store object in use for this client.
122107
func (c *Client) SetCryptoSuite(cryptoSuite bccsp.BCCSP) {
123108
c.cryptoSuite = cryptoSuite
124109
}
125110

126-
// GetCryptoSuite ...
127-
/*
128-
* A convenience method for obtaining the CryptoSuite object in use for this client.
129-
*/
130-
func (c *Client) GetCryptoSuite() bccsp.BCCSP {
111+
// CryptoSuite is a convenience method for obtaining the CryptoSuite object in use for this client.
112+
func (c *Client) CryptoSuite() bccsp.BCCSP {
131113
return c.cryptoSuite
132114
}
133115

@@ -280,14 +262,14 @@ func (c *Client) SignChannelConfig(config []byte) (*common.ConfigSignature, erro
280262
return nil, fmt.Errorf("Error marshalling signatureHeader: %v", err)
281263
}
282264

283-
user := c.GetUserContext()
265+
user := c.UserContext()
284266
if user == nil {
285267
return nil, fmt.Errorf("User is nil")
286268
}
287269

288270
// get all the bytes to be signed together, then sign
289271
signingBytes := fcutils.ConcatenateBytes(signatureHeaderBytes, config)
290-
signature, err := fc.SignObjectWithKey(signingBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.GetCryptoSuite())
272+
signature, err := fc.SignObjectWithKey(signingBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.CryptoSuite())
291273
if err != nil {
292274
return nil, fmt.Errorf("error singing config: %v", err)
293275
}
@@ -416,7 +398,7 @@ func (c *Client) createOrUpdateChannel(request fab.CreateChannelRequest, haveEnv
416398
return fmt.Errorf("error marshaling payload: %v", err)
417399
}
418400

419-
signature, err = fc.SignObjectWithKey(payloadBytes, c.userContext.PrivateKey(), &bccsp.SHAOpts{}, nil, c.GetCryptoSuite())
401+
signature, err = fc.SignObjectWithKey(payloadBytes, c.userContext.PrivateKey(), &bccsp.SHAOpts{}, nil, c.CryptoSuite())
420402
if err != nil {
421403
return fmt.Errorf("error singing payload: %v", err)
422404
}
@@ -518,11 +500,11 @@ func (c *Client) InstallChaincode(chaincodeName string, chaincodePath string, ch
518500
if err != nil {
519501
return nil, "", err
520502
}
521-
user := c.GetUserContext()
503+
user := c.UserContext()
522504
if user == nil {
523505
return nil, "", fmt.Errorf("User is nil")
524506
}
525-
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.GetCryptoSuite())
507+
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.CryptoSuite())
526508
if err != nil {
527509
return nil, "", err
528510
}
@@ -540,8 +522,8 @@ func (c *Client) InstallChaincode(chaincodeName string, chaincodePath string, ch
540522
return transactionProposalResponse, txID, err
541523
}
542524

543-
// GetUserContext ...
544-
func (c *Client) GetUserContext() fab.User {
525+
// UserContext returns the current User.
526+
func (c *Client) UserContext() fab.User {
545527
return c.userContext
546528
}
547529

pkg/fabric-client/client_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var testMsp = "testMsp"
2424

2525
func TestClientMethods(t *testing.T) {
2626
client := NewClient(mocks.NewMockConfig())
27-
if client.GetCryptoSuite() != nil {
28-
t.Fatalf("Client getCryptoSuite should initially be nil")
27+
if client.CryptoSuite() != nil {
28+
t.Fatalf("Client CryptoSuite should initially be nil")
2929
}
3030
err := bccspFactory.InitFactories(nil)
3131
if err != nil {
@@ -34,8 +34,8 @@ func TestClientMethods(t *testing.T) {
3434
cryptoSuite := bccspFactory.GetDefault()
3535

3636
client.SetCryptoSuite(cryptoSuite)
37-
if client.GetCryptoSuite() == nil {
38-
t.Fatalf("Client getCryptoSuite should not be nil after setCryptoSuite")
37+
if client.CryptoSuite() == nil {
38+
t.Fatalf("Client CryptoSuite should not be nil after setCryptoSuite")
3939
}
4040

4141
//Client tests: LoadUserFromStateStore successful nill user
@@ -103,7 +103,7 @@ func TestClientMethods(t *testing.T) {
103103
if chain.Name() != "someChain" {
104104
t.Fatalf("client.NewChain create wrong chain")
105105
}
106-
chain1 := client.GetChannel("someChain")
106+
chain1 := client.Channel("someChain")
107107
if chain1.Name() != "someChain" {
108108
t.Fatalf("client.NewChain create wrong chain")
109109
}
@@ -113,13 +113,13 @@ func TestClientMethods(t *testing.T) {
113113
t.Fatalf("CreateNewFileKeyValueStore return error[%s]", err)
114114
}
115115
client.SetStateStore(stateStore)
116-
client.GetStateStore().SetValue("testvalue", []byte("data"))
117-
value, err := client.GetStateStore().Value("testvalue")
116+
client.StateStore().SetValue("testvalue", []byte("data"))
117+
value, err := client.StateStore().Value("testvalue")
118118
if err != nil {
119-
t.Fatalf("client.GetStateStore().GetValue() return error[%s]", err)
119+
t.Fatalf("client.StateStore().GetValue() return error[%s]", err)
120120
}
121121
if string(value) != "data" {
122-
t.Fatalf("client.GetStateStore().GetValue() didn't return the right value")
122+
t.Fatalf("client.StateStore().GetValue() didn't return the right value")
123123
}
124124

125125
}

pkg/fabric-client/events/consumer/consumer.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func (ec *eventsClient) send(emsg *ehpb.Event) error {
9090
return fmt.Errorf("Error marshaling message: %s", err)
9191
}
9292
signature, err := fc.SignObjectWithKey(payload, user.PrivateKey(),
93-
&bccsp.SHAOpts{}, nil, ec.client.GetCryptoSuite())
93+
&bccsp.SHAOpts{}, nil, ec.client.CryptoSuite())
9494
if err != nil {
9595
return fmt.Errorf("Error signing message: %s", err)
9696
}
@@ -101,10 +101,10 @@ func (ec *eventsClient) send(emsg *ehpb.Event) error {
101101

102102
// RegisterAsync - registers interest in a event and doesn't wait for a response
103103
func (ec *eventsClient) RegisterAsync(ies []*ehpb.Interest) error {
104-
if ec.client.GetUserContext() == nil {
104+
if ec.client.UserContext() == nil {
105105
return fmt.Errorf("User context needs to be set")
106106
}
107-
creator, err := ec.client.GetUserContext().Identity()
107+
creator, err := ec.client.UserContext().Identity()
108108
if err != nil {
109109
return fmt.Errorf("Error getting creator: %v", err)
110110
}
@@ -237,7 +237,7 @@ func (ec *eventsClient) processEvents() error {
237237

238238
//Start establishes connection with Event hub and registers interested events with it
239239
func (ec *eventsClient) Start() error {
240-
conn, err := newEventsClientConnectionWithAddress(ec.peerAddress, ec.TLSCertificate, ec.TLSServerHostOverride, ec.client.GetConfig())
240+
conn, err := newEventsClientConnectionWithAddress(ec.peerAddress, ec.TLSCertificate, ec.TLSServerHostOverride, ec.client.Config())
241241
if err != nil {
242242
return fmt.Errorf("Could not create client conn to %s (%v)", ec.peerAddress, err)
243243
}

0 commit comments

Comments
 (0)