@@ -97,6 +97,7 @@ type ChaincodeEvent struct {
9797 TxId string
9898 EventName string
9999 Payload []byte
100+ ChannelID string
100101}
101102
102103// ChainCodeCBE ...
@@ -294,10 +295,10 @@ func (eventHub *eventHub) Recv(msg *pb.Event) (bool, error) {
294295 }
295296
296297 for _ , tdata := range blockEvent .Block .Data .Data {
297- if ccEvent , err := getChainCodeEvent (tdata ); err != nil {
298+ if ccEvent , channelID , err := getChainCodeEvent (tdata ); err != nil {
298299 logger .Warningf ("getChainCodeEvent return error: %v\n " , err )
299300 } else if ccEvent != nil {
300- eventHub .notifyChaincodeRegistrants (ccEvent , true )
301+ eventHub .notifyChaincodeRegistrants (channelID , ccEvent , true )
301302 }
302303 }
303304 return true , nil
@@ -306,7 +307,7 @@ func (eventHub *eventHub) Recv(msg *pb.Event) (bool, error) {
306307 logger .Debugf ("Recv ccEvent:%v\n " , ccEvent )
307308
308309 if ccEvent != nil {
309- eventHub .notifyChaincodeRegistrants (ccEvent .ChaincodeEvent , false )
310+ eventHub .notifyChaincodeRegistrants ("" , ccEvent .ChaincodeEvent , false )
310311 }
311312 return true , nil
312313 default :
@@ -493,58 +494,60 @@ func (eventHub *eventHub) getTXRegistrant(txID string) func(string, error) {
493494}
494495
495496// getChainCodeEvents parses block events for chaincode events associated with individual transactions
496- func getChainCodeEvent (tdata []byte ) (* pb.ChaincodeEvent , error ) {
497+ func getChainCodeEvent (tdata []byte ) (event * pb.ChaincodeEvent , channelID string , err error ) {
497498
498499 if tdata == nil {
499- return nil , errors .New ("Cannot extract payload from nil transaction" )
500+ return nil , "" , errors .New ("Cannot extract payload from nil transaction" )
500501 }
501502
502503 if env , err := utils .GetEnvelopeFromBlock (tdata ); err != nil {
503- return nil , fmt .Errorf ("Error getting tx from block(%s)" , err )
504+ return nil , "" , fmt .Errorf ("Error getting tx from block(%s)" , err )
504505 } else if env != nil {
505506 // get the payload from the envelope
506507 payload , err := utils .GetPayload (env )
507508 if err != nil {
508- return nil , fmt .Errorf ("Could not extract payload from envelope, err %s" , err )
509+ return nil , "" , fmt .Errorf ("Could not extract payload from envelope, err %s" , err )
509510 }
510511
511512 channelHeaderBytes := payload .Header .ChannelHeader
512513 channelHeader := & common.ChannelHeader {}
513514 err = proto .Unmarshal (channelHeaderBytes , channelHeader )
514515 if err != nil {
515- return nil , fmt .Errorf ("Could not extract channel header from envelope, err %s" , err )
516+ return nil , "" , fmt .Errorf ("Could not extract channel header from envelope, err %s" , err )
516517 }
517518
519+ channelID := channelHeader .ChannelId
520+
518521 // Chaincode events apply to endorser transaction only
519522 if common .HeaderType (channelHeader .Type ) == common .HeaderType_ENDORSER_TRANSACTION {
520523 tx , err := utils .GetTransaction (payload .Data )
521524 if err != nil {
522- return nil , fmt .Errorf ("Error unmarshalling transaction payload for block event: %s" , err )
525+ return nil , "" , fmt .Errorf ("Error unmarshalling transaction payload for block event: %s" , err )
523526 }
524527 chaincodeActionPayload , err := utils .GetChaincodeActionPayload (tx .Actions [0 ].Payload )
525528 if err != nil {
526- return nil , fmt .Errorf ("Error unmarshalling transaction action payload for block event: %s" , err )
529+ return nil , "" , fmt .Errorf ("Error unmarshalling transaction action payload for block event: %s" , err )
527530 }
528531 propRespPayload , err := utils .GetProposalResponsePayload (chaincodeActionPayload .Action .ProposalResponsePayload )
529532 if err != nil {
530- return nil , fmt .Errorf ("Error unmarshalling proposal response payload for block event: %s" , err )
533+ return nil , "" , fmt .Errorf ("Error unmarshalling proposal response payload for block event: %s" , err )
531534 }
532535 caPayload , err := utils .GetChaincodeAction (propRespPayload .Extension )
533536 if err != nil {
534- return nil , fmt .Errorf ("Error unmarshalling chaincode action for block event: %s" , err )
537+ return nil , "" , fmt .Errorf ("Error unmarshalling chaincode action for block event: %s" , err )
535538 }
536539 ccEvent , err := utils .GetChaincodeEvents (caPayload .Events )
537540
538541 if ccEvent != nil {
539- return ccEvent , nil
542+ return ccEvent , channelID , nil
540543 }
541544 }
542545 }
543- return nil , nil
546+ return nil , "" , nil
544547}
545548
546549// Utility function to fire callbacks for chaincode registrants
547- func (eventHub * eventHub ) notifyChaincodeRegistrants (ccEvent * pb.ChaincodeEvent , patternMatch bool ) {
550+ func (eventHub * eventHub ) notifyChaincodeRegistrants (channelID string , ccEvent * pb.ChaincodeEvent , patternMatch bool ) {
548551
549552 cbeArray := eventHub .getChaincodeRegistrants (ccEvent .ChaincodeId )
550553 if len (cbeArray ) <= 0 {
@@ -564,6 +567,7 @@ func (eventHub *eventHub) notifyChaincodeRegistrants(ccEvent *pb.ChaincodeEvent,
564567 TxId : ccEvent .TxId ,
565568 EventName : ccEvent .EventName ,
566569 Payload : ccEvent .Payload ,
570+ ChannelID : channelID ,
567571 })
568572 }
569573 }
0 commit comments