Skip to content

Commit

Permalink
[FAB-1772] Fix lint issues and errors
Browse files Browse the repository at this point in the history
https://jira.hyperledger.org/browse/FAB-1772

Bumped into this accidentally while working on FAB-1623.

Change-Id: Id1afcd3de59b936f5d73df9f041a5c04bf47b864
Signed-off-by: Kostas Christidis <kostas@christidis.io>
  • Loading branch information
kchristidis committed Jan 20, 2017
1 parent 6e30e75 commit 52e116e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
5 changes: 4 additions & 1 deletion protos/common/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/hyperledger/fabric/common/util"
)

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

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

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

// Hash returns the hash of the marshaled representation of the block data.
func (b *BlockData) Hash() []byte {
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
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions protos/utils/blockutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ func InitBlockMetadata(block *cb.Block) {
}

const (
epoch = uint64(0)
messageVersion = int32(1)
lastModified = uint64(0)
mspKey = "MSP"
XXX_DefaultModificationPolicyID = "DefaultModificationPolicy" // Break an import cycle during work to remove the below configtx construction methods
epoch = uint64(0)
messageVersion = int32(1)
lastModified = uint64(0)
mspKey = "MSP"
xxxDefaultModificationPolicyID = "DefaultModificationPolicy" // Break an import cycle during work to remove the below configtx construction methods
)

func createConfigItem(chainID string,
Expand Down Expand Up @@ -151,7 +151,7 @@ func EncodeMSPUnsigned(testChainID string) *cb.ConfigurationItem {
return createConfigItem(testChainID,
mspKey,
MarshalOrPanic(conf),
XXX_DefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
xxxDefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
}

// EncodeMSP gets the signed configuration item with the default MSP
Expand All @@ -166,5 +166,5 @@ func EncodeMSP(testChainID string) *cb.SignedConfigurationItem {
return createSignedConfigItem(testChainID,
mspKey,
MarshalOrPanic(conf),
XXX_DefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
xxxDefaultModificationPolicyID, cb.ConfigurationItem_Orderer)
}
2 changes: 2 additions & 0 deletions protos/utils/commonutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ func MakePayloadHeader(ch *cb.ChainHeader, sh *cb.SignatureHeader) *cb.Header {
}
}

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

// SignOrPanic signs a message and panics on error.
func SignOrPanic(signer crypto.LocalSigner, msg []byte) []byte {
if signer == nil {
panic(errors.New("Invalid signer. Must be different from nil."))
Expand Down
5 changes: 2 additions & 3 deletions protos/utils/configtxutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ func BreakOutBlockToConfigurationEnvelope(block *pb.Block) (*pb.ConfigurationEnv
return nil, nil, fmt.Errorf("Block.BlockData is not an array of 1. This is not a configuration transaction\n")
}

payloads, envelopeSignatures, err := BreakOutBlockData(block.Data)
payloads, envelopeSignatures, _ := BreakOutBlockData(block.Data)

if payloads[0].Header.ChainHeader.Type != int32(pb.HeaderType_CONFIGURATION_TRANSACTION) {
return nil, nil, fmt.Errorf("Payload Header type is not configuration_transaction. This is not a configuration transaction\n")
}
var configEnvelope *pb.ConfigurationEnvelope
configEnvelope, err = BreakOutPayloadDataToConfigurationEnvelope(payloads[0].Data)
configEnvelope, err := BreakOutPayloadDataToConfigurationEnvelope(payloads[0].Data)
if err != nil {
return nil, nil, fmt.Errorf("Error breaking out configurationEnvelope: %v\n", err)
}
Expand Down
6 changes: 3 additions & 3 deletions protos/utils/proputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func GetChaincodeProposalContext(prop *peer.Proposal) (*peer.ChaincodeProposalCo
// get back the header
hdr, err := GetHeader(prop.Header)
if err != nil {
return nil, fmt.Errorf("Could not extract the header from the proposal, err %s\n", err)
return nil, fmt.Errorf("Could not extract the header from the proposal: %s", err)
}
if common.HeaderType(hdr.ChainHeader.Type) != common.HeaderType_ENDORSER_TRANSACTION &&
common.HeaderType(hdr.ChainHeader.Type) != common.HeaderType_CONFIGURATION_TRANSACTION {
return nil, fmt.Errorf("invalid proposal type expected ENDORSER_TRANSACTION or CONFIGURATION_TRANSACTION. Was [%s]", hdr.ChainHeader.Type)
return nil, fmt.Errorf("Invalid proposal type expected ENDORSER_TRANSACTION or CONFIGURATION_TRANSACTION. Was: %d", hdr.ChainHeader.Type)
}

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

ccPropPayload := &peer.ChaincodeProposalPayload{}
Expand Down
5 changes: 3 additions & 2 deletions protos/utils/txutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func GetPayloads(txActions *peer.TransactionAction) (*peer.ChaincodeActionPayloa
return ccPayload, respPayload, nil
}

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

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

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

0 comments on commit 52e116e

Please sign in to comment.