Skip to content

Commit

Permalink
[FAB-5235] Normalize Getter Names
Browse files Browse the repository at this point in the history
Change-Id: I640995f4507b8de54cac1218f2b53a30ab2b4bfb
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Jul 10, 2017
1 parent fe06786 commit cc9e96a
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 109 deletions.
10 changes: 5 additions & 5 deletions api/apifabclient/fabricclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ import (
*/
type FabricClient interface {
NewChannel(name string) (Channel, error)
GetChannel(name string) Channel
Channel(name string) Channel
ExtractChannelConfig(configEnvelope []byte) ([]byte, error)
SignChannelConfig(config []byte) (*common.ConfigSignature, error)
CreateChannel(request CreateChannelRequest) (txn.TransactionID, error)
QueryChannelInfo(name string, peers []Peer) (Channel, error)
SetStateStore(stateStore KeyValueStore)
GetStateStore() KeyValueStore
StateStore() KeyValueStore
SetCryptoSuite(cryptoSuite bccsp.BCCSP)
GetCryptoSuite() bccsp.BCCSP
CryptoSuite() bccsp.BCCSP
SaveUserToStateStore(user User, skipPersistence bool) error
LoadUserFromStateStore(name string) (User, error)
InstallChaincode(chaincodeName string, chaincodePath string, chaincodeVersion string, chaincodePackage []byte, targets []Peer) ([]*txn.TransactionProposalResponse, string, error)
QueryChannels(peer Peer) (*pb.ChannelQueryResponse, error)
QueryInstalledChaincodes(peer Peer) (*pb.ChaincodeQueryResponse, error)
GetUserContext() User
UserContext() User
SetUserContext(user User)
GetConfig() config.Config // TODO: refactor to a fab client config interface
Config() config.Config // TODO: refactor to a fab client config interface
NewTxnID() (txn.TransactionID, error)
}

Expand Down
8 changes: 4 additions & 4 deletions def/fabapi/fabapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ func NewClientWithUser(name string, pwd string, orgName string,
return nil, fmt.Errorf("CreateNewFileKeyValueStore returned error[%s]", err)
}
client.SetStateStore(stateStore)
mspID, err := client.GetConfig().MspID(orgName)
mspID, err := client.Config().MspID(orgName)
if err != nil {
return nil, fmt.Errorf("Error reading MSP ID config: %s", err)
}

user, err := NewUser(client.GetConfig(), msp, name, pwd, mspID)
user, err := NewUser(client.Config(), msp, name, pwd, mspID)
if err != nil {
return nil, fmt.Errorf("NewUser returned error: %v", err)
}
Expand Down Expand Up @@ -97,11 +97,11 @@ func NewClientWithPreEnrolledUser(config config.Config, stateStorePath string,
}
client.SetStateStore(stateStore)
}
mspID, err := client.GetConfig().MspID(orgName)
mspID, err := client.Config().MspID(orgName)
if err != nil {
return nil, fmt.Errorf("Error reading MSP ID config: %s", err)
}
user, err := NewPreEnrolledUser(client.GetConfig(), keyDir, certDir, username, mspID, client.GetCryptoSuite())
user, err := NewPreEnrolledUser(client.Config(), keyDir, certDir, username, mspID, client.CryptoSuite())
if err != nil {
return nil, fmt.Errorf("NewPreEnrolledUser returned error: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func TestCSPConfig(t *testing.T) {
}
}

func TestGetPeersConfig(t *testing.T) {
func TestPeersConfig(t *testing.T) {
pc, err := configImpl.PeersConfig(org1)
if err != nil {
t.Fatalf(err.Error())
Expand Down
8 changes: 4 additions & 4 deletions pkg/fabric-client/channel/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (c *Channel) GenesisBlock(request *fab.GenesisBlockRequest) (*common.Block,
return nil, fmt.Errorf("GenesisBlock - error: Missing nonce input parameter with the required single use number")
}

if c.clientContext.GetUserContext() == nil {
if c.clientContext.UserContext() == nil {
return nil, fmt.Errorf("User context needs to be set")
}
creator, err := c.clientContext.GetUserContext().Identity()
creator, err := c.clientContext.UserContext().Identity()
if err != nil {
return nil, fmt.Errorf("Error getting creator: %v", err)
}
Expand Down Expand Up @@ -93,10 +93,10 @@ func (c *Channel) block(pos *ab.SeekPosition) (*common.Block, error) {
return nil, fmt.Errorf("error when generating nonce: %v", err)
}

if c.clientContext.GetUserContext() == nil {
if c.clientContext.UserContext() == nil {
return nil, fmt.Errorf("User context needs to be set")
}
creator, err := c.clientContext.GetUserContext().Identity()
creator, err := c.clientContext.UserContext().Identity()
if err != nil {
return nil, fmt.Errorf("error when serializing identity: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/fabric-client/channel/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ type Channel struct {

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

Expand Down
16 changes: 8 additions & 8 deletions pkg/fabric-client/channel/txnproposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ func newTransactionProposal(channelID string, request apitxn.ChaincodeInvokeRequ
Input: &pb.ChaincodeInput{Args: argsArray}}}

// create a proposal from a ChaincodeInvocationSpec
if clientContext.GetUserContext() == nil {
if clientContext.UserContext() == nil {
return nil, fmt.Errorf("User context needs to be set")
}
creator, err := clientContext.GetUserContext().Identity()
creator, err := clientContext.UserContext().Identity()
if err != nil {
return nil, fmt.Errorf("Error getting creator: %v", err)
}
Expand All @@ -132,13 +132,13 @@ func newTransactionProposal(channelID string, request apitxn.ChaincodeInvokeRequ
return nil, fmt.Errorf("Error marshalling proposal: %v", err)
}

user := clientContext.GetUserContext()
user := clientContext.UserContext()
if user == nil {
return nil, fmt.Errorf("Error getting user context: %s", err)
}

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

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

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

if c.clientContext.GetUserContext() == nil {
if c.clientContext.UserContext() == nil {
return fmt.Errorf("User context needs to be set")
}
creator, err := c.clientContext.GetUserContext().Identity()
creator, err := c.clientContext.UserContext().Identity()
if err != nil {
return fmt.Errorf("Error getting creator ID: %v", err)
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/fabric-client/channel/txnsender.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,14 @@ func (c *Channel) SendInstantiateProposal(chaincodeName string,
Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: &pb.ChaincodeID{Name: chaincodeName, Path: chaincodePath, Version: chaincodeVersion},
Input: &pb.ChaincodeInput{Args: argsArray}}}

if c.clientContext.GetUserContext() == nil {
if c.clientContext.UserContext() == nil {
return nil, apitxn.TransactionID{}, fmt.Errorf("User context needs to be set")
}
creator, err := c.clientContext.GetUserContext().Identity()
creator, err := c.clientContext.UserContext().Identity()
if err != nil {
return nil, apitxn.TransactionID{}, fmt.Errorf("Error getting creator: %v", err)
}
chaincodePolicy, err := buildChaincodePolicy(c.clientContext.GetUserContext().MspID())
chaincodePolicy, err := buildChaincodePolicy(c.clientContext.UserContext().MspID())
if err != nil {
return nil, apitxn.TransactionID{}, err
}
Expand Down Expand Up @@ -228,13 +228,13 @@ func (c *Channel) SendInstantiateProposal(chaincodeName string,
// SignPayload ... TODO.
func (c *Channel) SignPayload(payload []byte) (*fab.SignedEnvelope, error) {
//Get user info
user := c.clientContext.GetUserContext()
user := c.clientContext.UserContext()
if user == nil {
return nil, fmt.Errorf("User is nil")
}

signature, err := fc.SignObjectWithKey(payload, user.PrivateKey(),
&bccsp.SHAOpts{}, nil, c.clientContext.GetCryptoSuite())
&bccsp.SHAOpts{}, nil, c.clientContext.CryptoSuite())
if err != nil {
return nil, err
}
Expand Down
52 changes: 17 additions & 35 deletions pkg/fabric-client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,14 @@ func (c *Client) NewChannel(name string) (fab.Channel, error) {
return c.channels[name], nil
}

// GetConfig ...
func (c *Client) GetConfig() config.Config {
// Config returns the configuration of the client.
func (c *Client) Config() config.Config {
return c.config
}

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

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

// GetStateStore ...
/*
* A convenience method for obtaining the state store object in use for this client.
*/
func (c *Client) GetStateStore() fab.KeyValueStore {
// StateStore is a convenience method for obtaining the state store object in use for this client.
func (c *Client) StateStore() fab.KeyValueStore {
return c.stateStore
}

// SetCryptoSuite ...
/*
* A convenience method for obtaining the state store object in use for this client.
*/
// SetCryptoSuite is a convenience method for obtaining the state store object in use for this client.
func (c *Client) SetCryptoSuite(cryptoSuite bccsp.BCCSP) {
c.cryptoSuite = cryptoSuite
}

// GetCryptoSuite ...
/*
* A convenience method for obtaining the CryptoSuite object in use for this client.
*/
func (c *Client) GetCryptoSuite() bccsp.BCCSP {
// CryptoSuite is a convenience method for obtaining the CryptoSuite object in use for this client.
func (c *Client) CryptoSuite() bccsp.BCCSP {
return c.cryptoSuite
}

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

user := c.GetUserContext()
user := c.UserContext()
if user == nil {
return nil, fmt.Errorf("User is nil")
}

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

signature, err = fc.SignObjectWithKey(payloadBytes, c.userContext.PrivateKey(), &bccsp.SHAOpts{}, nil, c.GetCryptoSuite())
signature, err = fc.SignObjectWithKey(payloadBytes, c.userContext.PrivateKey(), &bccsp.SHAOpts{}, nil, c.CryptoSuite())
if err != nil {
return fmt.Errorf("error singing payload: %v", err)
}
Expand Down Expand Up @@ -518,11 +500,11 @@ func (c *Client) InstallChaincode(chaincodeName string, chaincodePath string, ch
if err != nil {
return nil, "", err
}
user := c.GetUserContext()
user := c.UserContext()
if user == nil {
return nil, "", fmt.Errorf("User is nil")
}
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.GetCryptoSuite())
signature, err := fc.SignObjectWithKey(proposalBytes, user.PrivateKey(), &bccsp.SHAOpts{}, nil, c.CryptoSuite())
if err != nil {
return nil, "", err
}
Expand All @@ -540,8 +522,8 @@ func (c *Client) InstallChaincode(chaincodeName string, chaincodePath string, ch
return transactionProposalResponse, txID, err
}

// GetUserContext ...
func (c *Client) GetUserContext() fab.User {
// UserContext returns the current User.
func (c *Client) UserContext() fab.User {
return c.userContext
}

Expand Down
18 changes: 9 additions & 9 deletions pkg/fabric-client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ var testMsp = "testMsp"

func TestClientMethods(t *testing.T) {
client := NewClient(mocks.NewMockConfig())
if client.GetCryptoSuite() != nil {
t.Fatalf("Client getCryptoSuite should initially be nil")
if client.CryptoSuite() != nil {
t.Fatalf("Client CryptoSuite should initially be nil")
}
err := bccspFactory.InitFactories(nil)
if err != nil {
Expand All @@ -34,8 +34,8 @@ func TestClientMethods(t *testing.T) {
cryptoSuite := bccspFactory.GetDefault()

client.SetCryptoSuite(cryptoSuite)
if client.GetCryptoSuite() == nil {
t.Fatalf("Client getCryptoSuite should not be nil after setCryptoSuite")
if client.CryptoSuite() == nil {
t.Fatalf("Client CryptoSuite should not be nil after setCryptoSuite")
}

//Client tests: LoadUserFromStateStore successful nill user
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestClientMethods(t *testing.T) {
if chain.Name() != "someChain" {
t.Fatalf("client.NewChain create wrong chain")
}
chain1 := client.GetChannel("someChain")
chain1 := client.Channel("someChain")
if chain1.Name() != "someChain" {
t.Fatalf("client.NewChain create wrong chain")
}
Expand All @@ -113,13 +113,13 @@ func TestClientMethods(t *testing.T) {
t.Fatalf("CreateNewFileKeyValueStore return error[%s]", err)
}
client.SetStateStore(stateStore)
client.GetStateStore().SetValue("testvalue", []byte("data"))
value, err := client.GetStateStore().Value("testvalue")
client.StateStore().SetValue("testvalue", []byte("data"))
value, err := client.StateStore().Value("testvalue")
if err != nil {
t.Fatalf("client.GetStateStore().GetValue() return error[%s]", err)
t.Fatalf("client.StateStore().GetValue() return error[%s]", err)
}
if string(value) != "data" {
t.Fatalf("client.GetStateStore().GetValue() didn't return the right value")
t.Fatalf("client.StateStore().GetValue() didn't return the right value")
}

}
Expand Down
8 changes: 4 additions & 4 deletions pkg/fabric-client/events/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func (ec *eventsClient) send(emsg *ehpb.Event) error {
return fmt.Errorf("Error marshaling message: %s", err)
}
signature, err := fc.SignObjectWithKey(payload, user.PrivateKey(),
&bccsp.SHAOpts{}, nil, ec.client.GetCryptoSuite())
&bccsp.SHAOpts{}, nil, ec.client.CryptoSuite())
if err != nil {
return fmt.Errorf("Error signing message: %s", err)
}
Expand All @@ -101,10 +101,10 @@ func (ec *eventsClient) send(emsg *ehpb.Event) error {

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

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

0 comments on commit cc9e96a

Please sign in to comment.