Skip to content

Commit

Permalink
Merge "FAB-1040 use new protos for constructing transactions"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Nov 9, 2016
2 parents e04d01b + 4ac43e8 commit 2eb7691
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
14 changes: 8 additions & 6 deletions core/committer/noopssinglechain/committer.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/hyperledger/fabric/core/committer"
"github.com/hyperledger/fabric/core/ledger/kvledger"
ab "github.com/hyperledger/fabric/protos/orderer"
putils "github.com/hyperledger/fabric/protos/utils"
"golang.org/x/net/context"
"google.golang.org/grpc"

Expand Down Expand Up @@ -135,12 +136,13 @@ func (r *deliverClient) readUntilClose() {
txs := []*pb.Transaction2{}
for _, d := range t.Block.Data.Data {
if d != nil {
tx := &pb.Transaction2{}
if err = proto.Unmarshal(d, tx); err != nil {
fmt.Printf("Error getting tx(%s)...dropping block\n", err)
continue
if tx, err := putils.GetEndorserTxFromBlock(d); err != nil {
fmt.Printf("Error getting tx from block(%s)\n", err)
} else if tx != nil {
txs = append(txs, tx)
} else {
fmt.Printf("Nil tx from block\n")
}
txs = append(txs, tx)
}
}
if err = r.commit(txs); err != nil {
Expand Down Expand Up @@ -178,7 +180,7 @@ type solo struct {

const defaultTimeout = time.Second * 3

//Start establishes communication with an orders
//Start establishes communication with an orderer
func (s *solo) Start() error {
if s.client != nil {
return fmt.Errorf("Client to (%s) exists", s.orderer)
Expand Down
2 changes: 1 addition & 1 deletion peer/chaincode/noopsordererclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newBroadcastClient(client ab.AtomicBroadcast_BroadcastClient) *broadcastCli
}

func (s *broadcastClient) broadcast(transaction []byte) error {
payload, err := proto.Marshal(&cb.Payload{Header: &cb.Header{}, Data: transaction})
payload, err := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)}}, Data: transaction})
if err != nil {
return fmt.Errorf("Unable to marshal: %s", err)
}
Expand Down
24 changes: 24 additions & 0 deletions protos/utils/txutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric/protos"
"github.com/hyperledger/fabric/protos/common"
)

// GetPayloads get's the underlying payload objects in a TransactionAction
Expand Down Expand Up @@ -118,3 +119,26 @@ func CreateTxFromProposalResponse(pResp *protos.ProposalResponse) (*protos.Trans
}
return CreateTx(protos.Header_CHAINCODE, pRespPayload.ProposalHash, ccAction.Events, ccAction.Results, []*protos.Endorsement{pResp.Endorsement})
}

// GetEndorserTxFromBlock gets Transaction2 from Block.Data.Data
func GetEndorserTxFromBlock(data []byte) (*protos.Transaction2, error) {
//Block always begins with an envelope
var err error
env := &common.Envelope{}
if err = proto.Unmarshal(data, env); err != nil {
return nil, fmt.Errorf("Error getting envelope(%s)\n", err)
}
payload := &common.Payload{}
if err = proto.Unmarshal(env.Payload, payload); err != nil {
return nil, fmt.Errorf("Error getting payload(%s)\n", err)
}

if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
tx := &protos.Transaction2{}
if err = proto.Unmarshal(payload.Data, tx); err != nil {
return nil, fmt.Errorf("Error getting tx(%s)\n", err)
}
return tx, nil
}
return nil, nil
}

0 comments on commit 2eb7691

Please sign in to comment.