Commit 152ce786 authored by Artem Barger's avatar Artem Barger
Browse files

Code cleanup, removing duplicates of envelope decoding



There are several places in the code which implements
logic of decoding byte array into Envelope, there is
method available inside txutils.go called GetEnvelopeFromBlock,
there is GetEnvelope from proputils.go and there is
ExtractEnvelope from commonutils.go.

This commits removes duplicate and switching to reuse single
method from txutils.go.

Change-Id: Ia7a963cfd0df85377ef4294d2dba33cca1eb904b
Signed-off-by: default avatarArtem Barger <bartem@il.ibm.com>
parent 94e282ff
......@@ -199,7 +199,7 @@ func extractMetadata(buf *ledgerutil.Buffer) (*common.BlockMetadata, error) {
}
func extractTxID(txEnvelopBytes []byte) (string, error) {
txEnvelope, err := utils.GetEnvelope(txEnvelopBytes)
txEnvelope, err := utils.GetEnvelopeFromBlock(txEnvelopBytes)
if err != nil {
return "", err
}
......
......@@ -575,7 +575,7 @@ func extractTransaction(txEnvelopeBytes []byte) (*pb.Transaction, error) {
var txPayload *common.Payload
var tx *pb.Transaction
if txEnvelope, err = putil.GetEnvelope(txEnvelopeBytes); err != nil {
if txEnvelope, err = putil.GetEnvelopeFromBlock(txEnvelopeBytes); err != nil {
return nil, err
}
if txPayload, err = putil.GetPayload(txEnvelope); err != nil {
......
......@@ -65,7 +65,7 @@ func (vscc *ValidatorOneValidSignature) Invoke(stub shim.ChaincodeStubInterface)
logger.Infof("VSCC invoked")
// get the envelope...
env, err := utils.GetEnvelope(args[1])
env, err := utils.GetEnvelopeFromBlock(args[1])
if err != nil {
logger.Errorf("VSCC error: GetEnvelope failed, err %s", err)
return nil, err
......
......@@ -119,8 +119,8 @@ func ExtractEnvelope(block *cb.Block, index int) (*cb.Envelope, error) {
return nil, fmt.Errorf("Envelope index out of bounds")
}
marshaledEnvelope := block.Data.Data[index]
envelope := &cb.Envelope{}
if err := proto.Unmarshal(marshaledEnvelope, envelope); err != nil {
envelope, err := GetEnvelopeFromBlock(marshaledEnvelope)
if err != nil {
return nil, fmt.Errorf("Block data does not carry an envelope at index %d: %s", index, err)
}
return envelope, nil
......
......@@ -184,17 +184,6 @@ func GetSignatureHeader(bytes []byte) (*common.SignatureHeader, error) {
return sh, nil
}
// GetEnvelope Get Envelope from bytes
func GetEnvelope(bytes []byte) (*common.Envelope, error) {
env := &common.Envelope{}
err := proto.Unmarshal(bytes, env)
if err != nil {
return nil, err
}
return env, nil
}
// CreateChaincodeProposal creates a proposal from given input
func CreateChaincodeProposal(txid string, chainID string, cis *peer.ChaincodeInvocationSpec, creator []byte) (*peer.Proposal, error) {
ccHdrExt := &peer.ChaincodeHeaderExtension{ChaincodeID: cis.ChaincodeSpec.ChaincodeID}
......@@ -353,7 +342,7 @@ func GetBytesEnvelope(env *common.Envelope) ([]byte, error) {
// GetActionFromEnvelope extracts a ChaincodeAction message from a serialized Envelope
func GetActionFromEnvelope(envBytes []byte) (*peer.ChaincodeAction, error) {
env, err := GetEnvelope(envBytes)
env, err := GetEnvelopeFromBlock(envBytes)
if err != nil {
return nil, err
}
......
......@@ -225,7 +225,7 @@ func TestEnvelope(t *testing.T) {
return
}
tx, err = GetEnvelope(envBytes)
tx, err = GetEnvelopeFromBlock(envBytes)
if err != nil {
t.Fatalf("Could not unmarshal envelope, err %s\n", err)
return
......
......@@ -66,7 +66,7 @@ func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
var err error
env := &common.Envelope{}
if err = proto.Unmarshal(data, env); err != nil {
return nil, fmt.Errorf("Error getting envelope(%s)\n", err)
return nil, fmt.Errorf("Error getting envelope(%s)", err)
}
return env, nil
......
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