@@ -494,7 +494,7 @@ func (handler *Handler) handleDelState(key string, txid string) error {
494
494
return errors .New ("Incorrect chaincode message received" )
495
495
}
496
496
497
- func (handler * Handler ) handleRangeQueryState (startKey , endKey string , txid string ) (* pb.RangeQueryStateResponse , error ) {
497
+ func (handler * Handler ) handleRangeQueryState (startKey , endKey string , txid string ) (* pb.QueryStateResponse , error ) {
498
498
// Create the channel on which to communicate the response from validating peer
499
499
respChan , uniqueReqErr := handler .createChannel (txid )
500
500
if uniqueReqErr != nil {
@@ -522,7 +522,7 @@ func (handler *Handler) handleRangeQueryState(startKey, endKey string, txid stri
522
522
// Success response
523
523
chaincodeLogger .Debugf ("[%s]Received %s. Successfully got range" , shorttxid (responseMsg .Txid ), pb .ChaincodeMessage_RESPONSE )
524
524
525
- rangeQueryResponse := & pb.RangeQueryStateResponse {}
525
+ rangeQueryResponse := & pb.QueryStateResponse {}
526
526
unmarshalErr := proto .Unmarshal (responseMsg .Payload , rangeQueryResponse )
527
527
if unmarshalErr != nil {
528
528
chaincodeLogger .Errorf ("[%s]unmarshall error" , shorttxid (responseMsg .Txid ))
@@ -542,7 +542,7 @@ func (handler *Handler) handleRangeQueryState(startKey, endKey string, txid stri
542
542
return nil , errors .New ("Incorrect chaincode message received" )
543
543
}
544
544
545
- func (handler * Handler ) handleRangeQueryStateNext (id , txid string ) (* pb.RangeQueryStateResponse , error ) {
545
+ func (handler * Handler ) handleQueryStateNext (id , txid string ) (* pb.QueryStateResponse , error ) {
546
546
// Create the channel on which to communicate the response from validating peer
547
547
respChan , uniqueReqErr := handler .createChannel (txid )
548
548
if uniqueReqErr != nil {
@@ -553,31 +553,31 @@ func (handler *Handler) handleRangeQueryStateNext(id, txid string) (*pb.RangeQue
553
553
defer handler .deleteChannel (txid )
554
554
555
555
// Send RANGE_QUERY_STATE_NEXT message to validator chaincode support
556
- payload := & pb.RangeQueryStateNext {ID : id }
556
+ payload := & pb.QueryStateNext {ID : id }
557
557
payloadBytes , err := proto .Marshal (payload )
558
558
if err != nil {
559
559
return nil , errors .New ("Failed to process range query state next request" )
560
560
}
561
- msg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_RANGE_QUERY_STATE_NEXT , Payload : payloadBytes , Txid : txid }
562
- chaincodeLogger .Debugf ("[%s]Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_RANGE_QUERY_STATE_NEXT )
561
+ msg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_QUERY_STATE_NEXT , Payload : payloadBytes , Txid : txid }
562
+ chaincodeLogger .Debugf ("[%s]Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_QUERY_STATE_NEXT )
563
563
responseMsg , err := handler .sendReceive (msg , respChan )
564
564
if err != nil {
565
- chaincodeLogger .Errorf ("[%s]error sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_RANGE_QUERY_STATE_NEXT )
565
+ chaincodeLogger .Errorf ("[%s]error sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_QUERY_STATE_NEXT )
566
566
return nil , errors .New ("could not send msg" )
567
567
}
568
568
569
569
if responseMsg .Type .String () == pb .ChaincodeMessage_RESPONSE .String () {
570
570
// Success response
571
571
chaincodeLogger .Debugf ("[%s]Received %s. Successfully got range" , shorttxid (responseMsg .Txid ), pb .ChaincodeMessage_RESPONSE )
572
572
573
- rangeQueryResponse := & pb.RangeQueryStateResponse {}
574
- unmarshalErr := proto .Unmarshal (responseMsg .Payload , rangeQueryResponse )
573
+ queryResponse := & pb.QueryStateResponse {}
574
+ unmarshalErr := proto .Unmarshal (responseMsg .Payload , queryResponse )
575
575
if unmarshalErr != nil {
576
576
chaincodeLogger .Errorf ("[%s]unmarshall error" , shorttxid (responseMsg .Txid ))
577
577
return nil , errors .New ("Error unmarshalling RangeQueryStateResponse." )
578
578
}
579
579
580
- return rangeQueryResponse , nil
580
+ return queryResponse , nil
581
581
}
582
582
if responseMsg .Type .String () == pb .ChaincodeMessage_ERROR .String () {
583
583
// Error response
@@ -590,7 +590,7 @@ func (handler *Handler) handleRangeQueryStateNext(id, txid string) (*pb.RangeQue
590
590
return nil , errors .New ("Incorrect chaincode message received" )
591
591
}
592
592
593
- func (handler * Handler ) handleRangeQueryStateClose (id , txid string ) (* pb.RangeQueryStateResponse , error ) {
593
+ func (handler * Handler ) handleQueryStateClose (id , txid string ) (* pb.QueryStateResponse , error ) {
594
594
// Create the channel on which to communicate the response from validating peer
595
595
respChan , uniqueReqErr := handler .createChannel (txid )
596
596
if uniqueReqErr != nil {
@@ -601,31 +601,79 @@ func (handler *Handler) handleRangeQueryStateClose(id, txid string) (*pb.RangeQu
601
601
defer handler .deleteChannel (txid )
602
602
603
603
// Send RANGE_QUERY_STATE_CLOSE message to validator chaincode support
604
- payload := & pb.RangeQueryStateClose {ID : id }
604
+ payload := & pb.QueryStateClose {ID : id }
605
605
payloadBytes , err := proto .Marshal (payload )
606
606
if err != nil {
607
607
return nil , errors .New ("Failed to process range query state close request" )
608
608
}
609
- msg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_RANGE_QUERY_STATE_CLOSE , Payload : payloadBytes , Txid : txid }
610
- chaincodeLogger .Debugf ("[%s]Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_RANGE_QUERY_STATE_CLOSE )
609
+ msg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_QUERY_STATE_CLOSE , Payload : payloadBytes , Txid : txid }
610
+ chaincodeLogger .Debugf ("[%s]Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_QUERY_STATE_CLOSE )
611
611
responseMsg , err := handler .sendReceive (msg , respChan )
612
612
if err != nil {
613
- chaincodeLogger .Errorf ("[%s]error sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_RANGE_QUERY_STATE_CLOSE )
613
+ chaincodeLogger .Errorf ("[%s]error sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_QUERY_STATE_CLOSE )
614
614
return nil , errors .New ("could not send msg" )
615
615
}
616
616
617
617
if responseMsg .Type .String () == pb .ChaincodeMessage_RESPONSE .String () {
618
618
// Success response
619
619
chaincodeLogger .Debugf ("[%s]Received %s. Successfully got range" , shorttxid (responseMsg .Txid ), pb .ChaincodeMessage_RESPONSE )
620
620
621
- rangeQueryResponse := & pb.RangeQueryStateResponse {}
622
- unmarshalErr := proto .Unmarshal (responseMsg .Payload , rangeQueryResponse )
621
+ queryResponse := & pb.QueryStateResponse {}
622
+ unmarshalErr := proto .Unmarshal (responseMsg .Payload , queryResponse )
623
623
if unmarshalErr != nil {
624
624
chaincodeLogger .Errorf ("[%s]unmarshall error" , shorttxid (responseMsg .Txid ))
625
625
return nil , errors .New ("Error unmarshalling RangeQueryStateResponse." )
626
626
}
627
627
628
- return rangeQueryResponse , nil
628
+ return queryResponse , nil
629
+ }
630
+ if responseMsg .Type .String () == pb .ChaincodeMessage_ERROR .String () {
631
+ // Error response
632
+ chaincodeLogger .Errorf ("[%s]Received %s" , shorttxid (responseMsg .Txid ), pb .ChaincodeMessage_ERROR )
633
+ return nil , errors .New (string (responseMsg .Payload [:]))
634
+ }
635
+
636
+ // Incorrect chaincode message received
637
+ chaincodeLogger .Errorf ("Incorrect chaincode message %s recieved. Expecting %s or %s" , responseMsg .Type , pb .ChaincodeMessage_RESPONSE , pb .ChaincodeMessage_ERROR )
638
+ return nil , errors .New ("Incorrect chaincode message received" )
639
+ }
640
+
641
+ func (handler * Handler ) handleExecuteQueryState (query string , txid string ) (* pb.QueryStateResponse , error ) {
642
+ // Create the channel on which to communicate the response from validating peer
643
+ respChan , uniqueReqErr := handler .createChannel (txid )
644
+ if uniqueReqErr != nil {
645
+ chaincodeLogger .Debugf ("[%s]Another state request pending for this Txid. Cannot process." , shorttxid (txid ))
646
+ return nil , uniqueReqErr
647
+ }
648
+
649
+ defer handler .deleteChannel (txid )
650
+
651
+ // Send EXECUTE_QUERY_STATE message to validator chaincode support
652
+ payload := & pb.ExecuteQueryState {Query : query }
653
+ payloadBytes , err := proto .Marshal (payload )
654
+ if err != nil {
655
+ return nil , errors .New ("Failed to process range query state request" )
656
+ }
657
+ msg := & pb.ChaincodeMessage {Type : pb .ChaincodeMessage_EXECUTE_QUERY_STATE , Payload : payloadBytes , Txid : txid }
658
+ chaincodeLogger .Debugf ("[%s]Sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_EXECUTE_QUERY_STATE )
659
+ responseMsg , err := handler .sendReceive (msg , respChan )
660
+ if err != nil {
661
+ chaincodeLogger .Errorf ("[%s]error sending %s" , shorttxid (msg .Txid ), pb .ChaincodeMessage_EXECUTE_QUERY_STATE )
662
+ return nil , errors .New ("could not send msg" )
663
+ }
664
+
665
+ if responseMsg .Type .String () == pb .ChaincodeMessage_RESPONSE .String () {
666
+ // Success response
667
+ chaincodeLogger .Debugf ("[%s]Received %s. Successfully got range" , shorttxid (responseMsg .Txid ), pb .ChaincodeMessage_RESPONSE )
668
+
669
+ executeQueryResponse := & pb.QueryStateResponse {}
670
+ unmarshalErr := proto .Unmarshal (responseMsg .Payload , executeQueryResponse )
671
+ if unmarshalErr != nil {
672
+ chaincodeLogger .Errorf ("[%s]unmarshall error" , shorttxid (responseMsg .Txid ))
673
+ return nil , errors .New ("Error unmarshalling QueryStateResponse." )
674
+ }
675
+
676
+ return executeQueryResponse , nil
629
677
}
630
678
if responseMsg .Type .String () == pb .ChaincodeMessage_ERROR .String () {
631
679
// Error response
0 commit comments