Skip to content

Commit 4ac43e8

Browse files
author
Srinivasan Muralidharan
committed
FAB-1040 use new protos for constructing transactions
https://jira.hyperledger.org/browse/FAB-1040 New protos needs transaction to be packaged into Envelope with approprate headers (ENDORSER_TRANSACTION). Change-Id: I1e5bc88f0eebfbabf0b260efd6fd9475cf50b352 Signed-off-by: Srinivasan Muralidharan <[email protected]>
1 parent 8c9dcc9 commit 4ac43e8

File tree

3 files changed

+33
-7
lines changed

3 files changed

+33
-7
lines changed

core/committer/noopssinglechain/committer.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/hyperledger/fabric/core/committer"
2929
"github.com/hyperledger/fabric/core/ledger/kvledger"
3030
ab "github.com/hyperledger/fabric/protos/orderer"
31+
putils "github.com/hyperledger/fabric/protos/utils"
3132
"golang.org/x/net/context"
3233
"google.golang.org/grpc"
3334

@@ -135,12 +136,13 @@ func (r *deliverClient) readUntilClose() {
135136
txs := []*pb.Transaction2{}
136137
for _, d := range t.Block.Data.Data {
137138
if d != nil {
138-
tx := &pb.Transaction2{}
139-
if err = proto.Unmarshal(d, tx); err != nil {
140-
fmt.Printf("Error getting tx(%s)...dropping block\n", err)
141-
continue
139+
if tx, err := putils.GetEndorserTxFromBlock(d); err != nil {
140+
fmt.Printf("Error getting tx from block(%s)\n", err)
141+
} else if tx != nil {
142+
txs = append(txs, tx)
143+
} else {
144+
fmt.Printf("Nil tx from block\n")
142145
}
143-
txs = append(txs, tx)
144146
}
145147
}
146148
if err = r.commit(txs); err != nil {
@@ -178,7 +180,7 @@ type solo struct {
178180

179181
const defaultTimeout = time.Second * 3
180182

181-
//Start establishes communication with an orders
183+
//Start establishes communication with an orderer
182184
func (s *solo) Start() error {
183185
if s.client != nil {
184186
return fmt.Errorf("Client to (%s) exists", s.orderer)

peer/chaincode/noopsordererclient.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func newBroadcastClient(client ab.AtomicBroadcast_BroadcastClient) *broadcastCli
4242
}
4343

4444
func (s *broadcastClient) broadcast(transaction []byte) error {
45-
payload, err := proto.Marshal(&cb.Payload{Header: &cb.Header{}, Data: transaction})
45+
payload, err := proto.Marshal(&cb.Payload{Header: &cb.Header{ChainHeader: &cb.ChainHeader{Type: int32(cb.HeaderType_ENDORSER_TRANSACTION)}}, Data: transaction})
4646
if err != nil {
4747
return fmt.Errorf("Unable to marshal: %s", err)
4848
}

protos/utils/txutils.go

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/golang/protobuf/proto"
2323
"github.com/hyperledger/fabric/protos"
24+
"github.com/hyperledger/fabric/protos/common"
2425
)
2526

2627
// GetPayloads get's the underlying payload objects in a TransactionAction
@@ -118,3 +119,26 @@ func CreateTxFromProposalResponse(pResp *protos.ProposalResponse) (*protos.Trans
118119
}
119120
return CreateTx(protos.Header_CHAINCODE, pRespPayload.ProposalHash, ccAction.Events, ccAction.Results, []*protos.Endorsement{pResp.Endorsement})
120121
}
122+
123+
// GetEndorserTxFromBlock gets Transaction2 from Block.Data.Data
124+
func GetEndorserTxFromBlock(data []byte) (*protos.Transaction2, error) {
125+
//Block always begins with an envelope
126+
var err error
127+
env := &common.Envelope{}
128+
if err = proto.Unmarshal(data, env); err != nil {
129+
return nil, fmt.Errorf("Error getting envelope(%s)\n", err)
130+
}
131+
payload := &common.Payload{}
132+
if err = proto.Unmarshal(env.Payload, payload); err != nil {
133+
return nil, fmt.Errorf("Error getting payload(%s)\n", err)
134+
}
135+
136+
if common.HeaderType(payload.Header.ChainHeader.Type) == common.HeaderType_ENDORSER_TRANSACTION {
137+
tx := &protos.Transaction2{}
138+
if err = proto.Unmarshal(payload.Data, tx); err != nil {
139+
return nil, fmt.Errorf("Error getting tx(%s)\n", err)
140+
}
141+
return tx, nil
142+
}
143+
return nil, nil
144+
}

0 commit comments

Comments
 (0)