Skip to content

Commit 52e116e

Browse files
committed
[FAB-1772] Fix lint issues and errors
https://jira.hyperledger.org/browse/FAB-1772 Bumped into this accidentally while working on FAB-1623. Change-Id: Id1afcd3de59b936f5d73df9f041a5c04bf47b864 Signed-off-by: Kostas Christidis <[email protected]>
1 parent 6e30e75 commit 52e116e

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

protos/common/block.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/hyperledger/fabric/common/util"
2222
)
2323

24-
// NewBlock construct a block with no data and no metadata
24+
// NewBlock construct a block with no data and no metadata.
2525
func NewBlock(seqNum uint64, previousHash []byte) *Block {
2626
block := &Block{}
2727
block.Header = &BlockHeader{}
@@ -34,6 +34,7 @@ func NewBlock(seqNum uint64, previousHash []byte) *Block {
3434
return block
3535
}
3636

37+
// Bytes returns the marshaled representation of the block header.
3738
func (b *BlockHeader) Bytes() []byte {
3839
data, err := proto.Marshal(b) // XXX this is wrong, protobuf is not the right mechanism to serialize for a hash
3940
if err != nil {
@@ -42,10 +43,12 @@ func (b *BlockHeader) Bytes() []byte {
4243
return data
4344
}
4445

46+
// Hash returns the hash of the block header.
4547
func (b *BlockHeader) Hash() []byte {
4648
return util.ComputeCryptoHash(b.Bytes())
4749
}
4850

51+
// Hash returns the hash of the marshaled representation of the block data.
4952
func (b *BlockData) Hash() []byte {
5053
data, err := proto.Marshal(b) // XXX this is wrong, protobuf is not the right mechanism to serialize for a hash, AND, it is not a MerkleTree hash
5154
if err != nil {

protos/utils/blockutils.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ func InitBlockMetadata(block *cb.Block) {
9696
}
9797

9898
const (
99-
epoch = uint64(0)
100-
messageVersion = int32(1)
101-
lastModified = uint64(0)
102-
mspKey = "MSP"
103-
XXX_DefaultModificationPolicyID = "DefaultModificationPolicy" // Break an import cycle during work to remove the below configtx construction methods
99+
epoch = uint64(0)
100+
messageVersion = int32(1)
101+
lastModified = uint64(0)
102+
mspKey = "MSP"
103+
xxxDefaultModificationPolicyID = "DefaultModificationPolicy" // Break an import cycle during work to remove the below configtx construction methods
104104
)
105105

106106
func createConfigItem(chainID string,
@@ -151,7 +151,7 @@ func EncodeMSPUnsigned(testChainID string) *cb.ConfigurationItem {
151151
return createConfigItem(testChainID,
152152
mspKey,
153153
MarshalOrPanic(conf),
154-
XXX_DefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
154+
xxxDefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
155155
}
156156

157157
// EncodeMSP gets the signed configuration item with the default MSP
@@ -166,5 +166,5 @@ func EncodeMSP(testChainID string) *cb.SignedConfigurationItem {
166166
return createSignedConfigItem(testChainID,
167167
mspKey,
168168
MarshalOrPanic(conf),
169-
XXX_DefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
169+
xxxDefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
170170
}

protos/utils/commonutils.go

+2
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ func MakePayloadHeader(ch *cb.ChainHeader, sh *cb.SignatureHeader) *cb.Header {
177177
}
178178
}
179179

180+
// NewSignatureHeaderOrPanic returns a signature header and panics on error.
180181
func NewSignatureHeaderOrPanic(signer crypto.LocalSigner) *cb.SignatureHeader {
181182
if signer == nil {
182183
panic(errors.New("Invalid signer. Must be different from nil."))
@@ -189,6 +190,7 @@ func NewSignatureHeaderOrPanic(signer crypto.LocalSigner) *cb.SignatureHeader {
189190
return signatureHeader
190191
}
191192

193+
// SignOrPanic signs a message and panics on error.
192194
func SignOrPanic(signer crypto.LocalSigner, msg []byte) []byte {
193195
if signer == nil {
194196
panic(errors.New("Invalid signer. Must be different from nil."))

protos/utils/configtxutils.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ func BreakOutBlockToConfigurationEnvelope(block *pb.Block) (*pb.ConfigurationEnv
143143
return nil, nil, fmt.Errorf("Block.BlockData is not an array of 1. This is not a configuration transaction\n")
144144
}
145145

146-
payloads, envelopeSignatures, err := BreakOutBlockData(block.Data)
146+
payloads, envelopeSignatures, _ := BreakOutBlockData(block.Data)
147147

148148
if payloads[0].Header.ChainHeader.Type != int32(pb.HeaderType_CONFIGURATION_TRANSACTION) {
149149
return nil, nil, fmt.Errorf("Payload Header type is not configuration_transaction. This is not a configuration transaction\n")
150150
}
151-
var configEnvelope *pb.ConfigurationEnvelope
152-
configEnvelope, err = BreakOutPayloadDataToConfigurationEnvelope(payloads[0].Data)
151+
configEnvelope, err := BreakOutPayloadDataToConfigurationEnvelope(payloads[0].Data)
153152
if err != nil {
154153
return nil, nil, fmt.Errorf("Error breaking out configurationEnvelope: %v\n", err)
155154
}

protos/utils/proputils.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ func GetChaincodeProposalContext(prop *peer.Proposal) (*peer.ChaincodeProposalCo
5252
// get back the header
5353
hdr, err := GetHeader(prop.Header)
5454
if err != nil {
55-
return nil, fmt.Errorf("Could not extract the header from the proposal, err %s\n", err)
55+
return nil, fmt.Errorf("Could not extract the header from the proposal: %s", err)
5656
}
5757
if common.HeaderType(hdr.ChainHeader.Type) != common.HeaderType_ENDORSER_TRANSACTION &&
5858
common.HeaderType(hdr.ChainHeader.Type) != common.HeaderType_CONFIGURATION_TRANSACTION {
59-
return nil, fmt.Errorf("invalid proposal type expected ENDORSER_TRANSACTION or CONFIGURATION_TRANSACTION. Was [%s]", hdr.ChainHeader.Type)
59+
return nil, fmt.Errorf("Invalid proposal type expected ENDORSER_TRANSACTION or CONFIGURATION_TRANSACTION. Was: %d", hdr.ChainHeader.Type)
6060
}
6161

6262
if hdr.SignatureHeader == nil {
63-
return nil, errors.New("invalid signature header. It must be different from nil")
63+
return nil, errors.New("Invalid signature header. It must be different from nil.")
6464
}
6565

6666
ccPropPayload := &peer.ChaincodeProposalPayload{}

protos/utils/txutils.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func GetPayloads(txActions *peer.TransactionAction) (*peer.ChaincodeActionPayloa
6060
return ccPayload, respPayload, nil
6161
}
6262

63-
// GetEndorserTxFromBlock gets Transaction from Block.Data.Data
63+
// GetEnvelopeFromBlock gets an envelope from a block's Data field.
6464
func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
6565
//Block always begins with an envelope
6666
var err error
@@ -72,7 +72,7 @@ func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
7272
return env, nil
7373
}
7474

75-
// assemble an Envelope message from proposal, endorsements and a signer.
75+
// CreateSignedTx assembles an Envelope message from proposal, endorsements, and a signer.
7676
// This function should be called by a client when it has collected enough endorsements
7777
// for a proposal to create a transaction and submit it to peers for ordering
7878
func CreateSignedTx(proposal *peer.Proposal, signer msp.SigningIdentity, resps ...*peer.ProposalResponse) (*common.Envelope, error) {
@@ -182,6 +182,7 @@ func CreateSignedTx(proposal *peer.Proposal, signer msp.SigningIdentity, resps .
182182
return &common.Envelope{Payload: paylBytes, Signature: sig}, nil
183183
}
184184

185+
// CreateProposalResponse creates a proposal response.
185186
func CreateProposalResponse(hdr []byte, payl []byte, results []byte, events []byte, visibility []byte, signingEndorser msp.SigningIdentity) (*peer.ProposalResponse, error) {
186187
// obtain the proposal hash given proposal header, payload and the requested visibility
187188
pHashBytes, err := GetProposalHash1(hdr, payl, visibility)

0 commit comments

Comments
 (0)