Skip to content

Commit

Permalink
FAB-491 Ledger not using correct protobuf
Browse files Browse the repository at this point in the history
Change-Id: Ic6803b6f19d4ce28774b53aad4abd4d9c6b849da
Signed-off-by: denyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Sep 29, 2016
1 parent a069514 commit 9826d54
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion core/ledgernext/kvledger/example/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,12 @@ func (app *App) QueryBalances(accounts []string) ([]int, error) {
}

func constructTransaction(simulationResults []byte) *protos.Transaction2 {
action := &protos.Action{ProposalHash: []byte{}, SimulationResult: simulationResults}
actionBytes, _ := proto.Marshal(action)

tx := &protos.Transaction2{}
tx.EndorsedActions = []*protos.EndorsedAction{
&protos.EndorsedAction{ActionBytes: simulationResults, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
&protos.EndorsedAction{ActionBytes: actionBytes, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
return tx
}

Expand Down
20 changes: 18 additions & 2 deletions core/ledgernext/kvledger/txmgmt/lockbasedtxmgmt/lockbased_txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,33 @@ func (txmgr *LockBasedTxMgr) ValidateAndPrepare(block *protos.Block2) (*protos.B
if err != nil {
return nil, nil, err
}
txRWSet := &txmgmt.TxReadWriteSet{}
numEndorsements := len(tx.EndorsedActions)
if numEndorsements == 0 {
return nil, nil, fmt.Errorf("Tx contains no EndorsedActions")
}

// Eventually we'll want to support multiple EndorsedActions in a tran, see FAB-445
// But for now, we'll return an error if there are multiple EndorsedActions
if numEndorsements > 1 {
return nil, nil, fmt.Errorf("Tx contains more than one [%d] EndorsedActions", numEndorsements)
}
if err = txRWSet.Unmarshal(tx.EndorsedActions[0].ActionBytes); err != nil {

// Get the actionBytes from the EndorsedAction
// and then Unmarshal it into an Action using protobuf unmarshalling
action := &protos.Action{}
actionBytes := tx.EndorsedActions[0].ActionBytes
err = proto.Unmarshal(actionBytes, action)
if err != nil {
return nil, nil, err
}

// Get the SimulationResult from the Action
// and then Unmarshal it into a TxReadWriteSet using custom unmarshalling
txRWSet := &txmgmt.TxReadWriteSet{}
if err = txRWSet.Unmarshal(action.SimulationResult); err != nil {
return nil, nil, err
}

logger.Debugf("validating txRWSet:[%s]", txRWSet)
if valid, err = txmgr.validateTx(txRWSet); err != nil {
return nil, nil, err
Expand Down
6 changes: 5 additions & 1 deletion core/ledgernext/testutil/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ func ConstructTestBlock(t *testing.T, numTx int, startingTxID int) *protos.Block

// ConstructTestTransaction constructs a transaction for testing
func ConstructTestTransaction(t *testing.T, simulationResults []byte) *protos.Transaction2 {

action := &protos.Action{ProposalHash: []byte{}, SimulationResult: simulationResults}
actionBytes, _ := proto.Marshal(action)

tx := &protos.Transaction2{}
tx.EndorsedActions = []*protos.EndorsedAction{
&protos.EndorsedAction{ActionBytes: simulationResults, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
&protos.EndorsedAction{ActionBytes: actionBytes, Endorsements: []*protos.Endorsement{}, ProposalBytes: []byte{}}}
return tx
}

Expand Down

0 comments on commit 9826d54

Please sign in to comment.