diff --git a/protos/common/block.go b/protos/common/block.go index ff2dda73601..96635f611f1 100644 --- a/protos/common/block.go +++ b/protos/common/block.go @@ -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{} @@ -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 { @@ -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 { diff --git a/protos/utils/blockutils.go b/protos/utils/blockutils.go index b3bc0e36d0c..8ecf350ad81 100644 --- a/protos/utils/blockutils.go +++ b/protos/utils/blockutils.go @@ -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, @@ -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 @@ -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) } diff --git a/protos/utils/commonutils.go b/protos/utils/commonutils.go index f9f899445ef..02b3679f991 100644 --- a/protos/utils/commonutils.go +++ b/protos/utils/commonutils.go @@ -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.")) @@ -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.")) diff --git a/protos/utils/configtxutils.go b/protos/utils/configtxutils.go index 9221262589f..bca1cf51eb8 100644 --- a/protos/utils/configtxutils.go +++ b/protos/utils/configtxutils.go @@ -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) } diff --git a/protos/utils/proputils.go b/protos/utils/proputils.go index ef3fe91c721..6c959e20460 100644 --- a/protos/utils/proputils.go +++ b/protos/utils/proputils.go @@ -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{} diff --git a/protos/utils/txutils.go b/protos/utils/txutils.go index 6bb6739c784..944e83b1cd5 100644 --- a/protos/utils/txutils.go +++ b/protos/utils/txutils.go @@ -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 @@ -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) { @@ -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)