Commit 76c0dc56 authored by Baohua Yang's avatar Baohua Yang
Browse files

[FAB-5194] Fix usage problems in code



This patchset helps clean up the code and docs:

* Fix redundant parenthesese.
* Fix mismatching params in func return.
* Fix variable name collides with imported package name and builtin
  function or reserved words.
* Fix word typos.

Change-Id: I30304c233067ead7e74d18e3caf2604b3ed1490a
Signed-off-by: default avatarBaohua Yang <yangbaohua@gmail.com>
parent 65a9ceb3
......@@ -23,7 +23,7 @@
# - behave-deps - ensures pre-requisites are available for running behave manually
# - gotools - installs go tools like golint
# - linter - runs all code checks
# - license - checks go sourrce files for Apache license header
# - license - checks go source files for Apache license header
# - native - ensures all native binaries are available
# - docker[-clean] - ensures all docker images are available[/cleaned]
# - peer-docker[-clean] - ensures the peer container is available[/cleaned]
......
......@@ -127,7 +127,7 @@ func (csp *impl) returnSession(session pkcs11.SessionHandle) {
}
// Look for an EC key by SKI, stored in CKA_ID
// This function can probably be addapted for both EC and RSA keys.
// This function can probably be adapted for both EC and RSA keys.
func (csp *impl) getECKey(ski []byte) (pubKey *ecdsa.PublicKey, isPriv bool, err error) {
p11lib := csp.ctx
session := csp.getSession()
......@@ -510,7 +510,7 @@ func findKeyPairFromSKI(mod *pkcs11.Ctx, session pkcs11.SessionHandle, ski []byt
//
// [mis-parsing encountered with v3.5.1, 2016-10-22]
//
// SoftHSM reports extra two bytes before the uncrompressed point
// SoftHSM reports extra two bytes before the uncompressed point
// 0x04 || <Length*2+1>
// VV< Actual start of point
// 00000000 04 41 04 6c c8 57 32 13 02 12 6a 19 23 1d 5a 64 |.A.l.W2...j.#.Zd|
......
......@@ -21,7 +21,7 @@ import (
"os"
)
// DirMissingOrEmpty checks is a directory is missin or empty
// DirMissingOrEmpty checks is a directory is missing or empty
func DirMissingOrEmpty(path string) (bool, error) {
dirExists, err := DirExists(path)
if err != nil {
......
......@@ -202,7 +202,7 @@ func DERToPrivateKey(der []byte) (key interface{}, err error) {
return
}
return nil, errors.New("Invalid key type. The DER must contain an rsa.PrivareKey or ecdsa.PrivateKey")
return nil, errors.New("Invalid key type. The DER must contain an rsa.PrivateKey or ecdsa.PrivateKey")
}
// PEMtoPrivateKey unmarshals a pem to private key
......
......@@ -292,7 +292,7 @@ func startConsumer(serverAddr string, chainID string, ordererIndex int, channelI
logger(fmt.Sprintf("Error on Consumer ord[%d] ch[%d] connecting (grpc) to %s, err: %v", ordererIndex, channelIndex, serverAddr, err))
return
}
(*consumerConnP) = conn
*consumerConnP = conn
client, err := ab.NewAtomicBroadcastClient(*consumerConnP).Deliver(context.TODO())
if err != nil {
logger(fmt.Sprintf("Error on Consumer ord[%d] ch[%d] invoking Deliver() on grpc connection to %s, err: %v", ordererIndex, channelIndex, serverAddr, err))
......@@ -317,7 +317,7 @@ func startConsumerMaster(serverAddr string, chainIDsP *[]string, ordererIndex in
logger(fmt.Sprintf("Error on MasterConsumer ord[%d] connecting (grpc) to %s, err: %v", ordererIndex, serverAddr, err))
return
}
(*consumerConnP) = conn
*consumerConnP = conn
// create an orderer driver client for every channel on this orderer
//[][]*ordererdriveClient // numChannels
......@@ -475,7 +475,7 @@ func startProducer(serverAddr string, chainID string, ordererIndex int, channelI
if printProgressLogs && (*txSentCntrP)%printLogCnt == 0 {
mult++
if debugflag1 {
logger(fmt.Sprintf("Producer ord[%d] ch[%d] sent %4d /%4d = %3d%%, %v", ordererIndex, channelIndex, (*txSentCntrP), txReq, progressPercentage*mult, time.Now()))
logger(fmt.Sprintf("Producer ord[%d] ch[%d] sent %4d /%4d = %3d%%, %v", ordererIndex, channelIndex, *txSentCntrP, txReq, progressPercentage*mult, time.Now()))
} else {
logger(fmt.Sprintf("Sent %3d%%, %v", progressPercentage*mult, time.Now()))
}
......
......@@ -77,7 +77,7 @@ func (og *OrganizationGroup) NewGroup(name string) (ValueProposer, error) {
return nil, fmt.Errorf("Organization does not support subgroups")
}
// Allocate creates the proto resources neeeded for a proposal
// Allocate creates the proto resources needed for a proposal
func (og *OrganizationGroup) Allocate() Values {
return NewOrganizationConfig(og)
}
......
......@@ -37,7 +37,7 @@ type ValueDeserializer interface {
Deserialize(key string, value []byte) (proto.Message, error)
}
// Values defines a mechanism to supply messages to unamrshal from config
// Values defines a mechanism to supply messages to unmarshal from config
// and a mechanism to validate the results
type Values interface {
ValueDeserializer
......
......@@ -95,7 +95,7 @@ type PolicyHandler interface {
ProposePolicy(tx interface{}, key string, path []string, policy *cb.ConfigPolicy) (proto.Message, error)
}
// Proposer contains the references necesssary to appropriately unmarshal
// Proposer contains the references necessary to appropriately unmarshal
// a cb.ConfigGroup
type Proposer interface {
// ValueProposer return the root value proposer
......
......@@ -59,8 +59,8 @@ func TestSerializedBlockInfo(t *testing.T) {
testutil.AssertEquals(t, txid, indexTxID)
b := bb[indexOffset.offset:]
len, num := proto.DecodeVarint(b)
txEnvBytesFromBB := b[num : num+int(len)]
length, num := proto.DecodeVarint(b)
txEnvBytesFromBB := b[num : num+int(length)]
testutil.AssertEquals(t, txEnvBytesFromBB, txEnvBytes)
}
}
......@@ -26,7 +26,7 @@ var FakeLocalSigner = &LocalSigner{
Nonce: []byte("NonceValue"),
}
// LocalSigner is a mock implmeentation of crypto.LocalSigner
// LocalSigner is a mock implementation of crypto.LocalSigner
type LocalSigner struct {
Identity []byte
Nonce []byte
......
......@@ -23,7 +23,7 @@ import (
)
type MockQueryExecutor struct {
// State keeps all namepspaces
// State keeps all namespaces
State map[string]map[string][]byte
}
......
......@@ -24,7 +24,7 @@ import (
type noopmsp struct {
}
// NewNoopMsp returns a no-op implementation of the MSP inteface
// NewNoopMsp returns a no-op implementation of the MSP interface
func NewNoopMsp() m.MSP {
return &noopmsp{}
}
......
......@@ -50,7 +50,7 @@ type Manager struct {
// PolicyNames panics
func (m *Manager) PolicyNames() []string {
panic("Unimplimented")
panic("Unimplemented")
}
// BasePath returns BasePathVal
......
......@@ -163,7 +163,7 @@ func (rp rejectPolicy) Evaluate(signedData []*cb.SignedData) error {
return fmt.Errorf("No such policy type: %s", rp)
}
// Basepath returns the basePath the manager was instnatiated with
// Basepath returns the basePath the manager was instantiated with
func (pm *ManagerImpl) BasePath() string {
return pm.basePath
}
......
......@@ -103,12 +103,12 @@ func (c *ccProviderImpl) Execute(ctxt context.Context, cccid interface{}, spec i
return Execute(ctxt, cccid.(*ccProviderContextImpl).ctx, spec)
}
// ExecuteWithErrorFilder executes the chaincode given context and spec and returns payload
// ExecuteWithErrorFilter executes the chaincode given context and spec and returns payload
func (c *ccProviderImpl) ExecuteWithErrorFilter(ctxt context.Context, cccid interface{}, spec interface{}) ([]byte, *pb.ChaincodeEvent, error) {
return ExecuteWithErrorFilter(ctxt, cccid.(*ccProviderContextImpl).ctx, spec)
}
// ExecuteWithErrorFilder executes the chaincode given context and spec and returns payload
// Stop stops the chaincode given context and spec
func (c *ccProviderImpl) Stop(ctxt context.Context, cccid interface{}, spec *pb.ChaincodeDeploymentSpec) error {
if theChaincodeSupport != nil {
return theChaincodeSupport.Stop(ctxt, cccid.(*ccProviderContextImpl).ctx, spec)
......
......@@ -296,8 +296,8 @@ func (chaincodeSupport *ChaincodeSupport) registerHandler(chaincodehandler *Hand
func (chaincodeSupport *ChaincodeSupport) deregisterHandler(chaincodehandler *Handler) error {
// clean up queryIteratorMap
for _, context := range chaincodehandler.txCtxs {
for _, v := range context.queryIteratorMap {
for _, txcontext := range chaincodehandler.txCtxs {
for _, v := range txcontext.queryIteratorMap {
v.Close()
}
}
......
......@@ -167,7 +167,7 @@ func (handler *Handler) serialSend(msg *pb.ChaincodeMessage) error {
return err
}
//serialSendAsync serves the same purpose as serialSend (serializ msgs so gRPC will
//serialSendAsync serves the same purpose as serialSend (serialize msgs so gRPC will
//be happy). In addition, it is also asynchronous so send-remoterecv--localrecv loop
//can be nonblocking. Only errors need to be handled and these are handled by
//communication on supplied error channel. A typical use will be a non-blocking or
......@@ -283,7 +283,7 @@ func (handler *Handler) waitForKeepaliveTimer() <-chan time.Time {
c := time.After(handler.chaincodeSupport.keepalive)
return c
}
//no one will signal this channel, listner blocks forever
//no one will signal this channel, listener blocks forever
c := make(chan time.Time, 1)
return c
}
......@@ -1265,7 +1265,7 @@ func (handler *Handler) enterBusyState(e *fsm.Event, state string) {
err = ccprovider.CheckInsantiationPolicy(calledCcIns.ChaincodeName, cd.Version, cd)
if err != nil {
errHandler([]byte(err.Error()), "[%s]CheckInsantiationPolicy, error %s. Sending %s", shorttxid(msg.Txid), err, pb.ChaincodeMessage_ERROR)
errHandler([]byte(err.Error()), "[%s]CheckInstantiationPolicy, error %s. Sending %s", shorttxid(msg.Txid), err, pb.ChaincodeMessage_ERROR)
return
}
} else {
......
......@@ -102,7 +102,7 @@ func (goPlatform *Platform) ValidateSpec(spec *pb.ChaincodeSpec) error {
return fmt.Errorf("invalid path: %s", err)
}
//we have no real good way of checking existence of remote urls except by downloading and testin
//we have no real good way of checking existence of remote urls except by downloading and testing
//which we do later anyway. But we *can* - and *should* - test for existence of local paths.
//Treat empty scheme as a local filesystem path
if path.Scheme == "" {
......
......@@ -122,7 +122,7 @@ func generateDockerfile(platform Platform, cds *pb.ChaincodeDeploymentSpec, tls
// ----------------------------------------------------------------------------------------------------
// Then augment it with any general options
// ----------------------------------------------------------------------------------------------------
//append version so chaincode build version can be campared against peer build version
//append version so chaincode build version can be compared against peer build version
buf = append(buf, fmt.Sprintf("ENV CORE_CHAINCODE_BUILDLEVEL=%s", metadata.Version))
if tls {
......
......@@ -74,7 +74,7 @@ func (handler *Handler) serialSend(msg *pb.ChaincodeMessage) error {
return err
}
//serialSendAsync serves the same purpose as serialSend (serializ msgs so gRPC will
//serialSendAsync serves the same purpose as serialSend (serialize msgs so gRPC will
//be happy). In addition, it is also asynchronous so send-remoterecv--localrecv loop
//can be nonblocking. Only errors need to be handled and these are handled by
//communication on supplied error channel. A typical use will be a non-blocking or
......@@ -748,7 +748,7 @@ func (handler *Handler) handleInvokeChaincode(chaincodeName string, args [][]byt
}
if respMsg.Type == pb.ChaincodeMessage_COMPLETED {
// Success response
chaincodeLogger.Debugf("[%s]Received %s. Successfully invoed chaincode", shorttxid(responseMsg.Txid), pb.ChaincodeMessage_RESPONSE)
chaincodeLogger.Debugf("[%s]Received %s. Successfully invoked chaincode", shorttxid(responseMsg.Txid), pb.ChaincodeMessage_RESPONSE)
res := &pb.Response{}
if err = proto.Unmarshal(respMsg.Payload, res); err != nil {
return handler.createResponse(ERROR, []byte(err.Error()))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment