@@ -434,6 +434,14 @@ const (
434
434
HISTORY_QUERY_RESULT
435
435
)
436
436
437
+ func (stub * ChaincodeStub ) handleGetStateByRange (startKey , endKey string ) (StateQueryIteratorInterface , error ) {
438
+ response , err := stub .handler .handleGetStateByRange (startKey , endKey , stub .TxID )
439
+ if err != nil {
440
+ return nil , err
441
+ }
442
+ return & StateQueryIterator {CommonIterator : & CommonIterator {stub .handler , stub .TxID , response , 0 }}, nil
443
+ }
444
+
437
445
// GetStateByRange function can be invoked by a chaincode to query of a range
438
446
// of keys in the state. Assuming the startKey and endKey are in lexical order,
439
447
// an iterator will be returned that can be used to iterate over all keys
@@ -448,11 +456,7 @@ func (stub *ChaincodeStub) GetStateByRange(startKey, endKey string) (StateQueryI
448
456
if err := validateSimpleKeys (startKey , endKey ); err != nil {
449
457
return nil , err
450
458
}
451
- response , err := stub .handler .handleGetStateByRange (startKey , endKey , stub .TxID )
452
- if err != nil {
453
- return nil , err
454
- }
455
- return & StateQueryIterator {CommonIterator : & CommonIterator {stub .handler , stub .TxID , response , 0 }}, nil
459
+ return stub .handleGetStateByRange (startKey , endKey )
456
460
}
457
461
458
462
// GetQueryResult function can be invoked by a chaincode to perform a
@@ -547,31 +551,27 @@ func validateSimpleKeys(simpleKeys ...string) error {
547
551
//a partial composite key. For a full composite key, an iter with empty response
548
552
//would be returned.
549
553
func (stub * ChaincodeStub ) GetStateByPartialCompositeKey (objectType string , attributes []string ) (StateQueryIteratorInterface , error ) {
550
- partialCompositeKey , err := stub .CreateCompositeKey (objectType , attributes )
551
- if err != nil {
552
- return nil , err
553
- }
554
- response , err := stub .handler .handleGetStateByRange (partialCompositeKey , partialCompositeKey + string (maxUnicodeRuneValue ), stub .TxID )
555
- if err != nil {
554
+ if partialCompositeKey , err := stub .CreateCompositeKey (objectType , attributes ); err == nil {
555
+ return stub .handleGetStateByRange (partialCompositeKey , partialCompositeKey + string (maxUnicodeRuneValue ))
556
+ } else {
556
557
return nil , err
557
558
}
558
- return & StateQueryIterator {CommonIterator : & CommonIterator {stub .handler , stub .TxID , response , 0 }}, nil
559
559
}
560
560
561
561
func (iter * StateQueryIterator ) Next () (* queryresult.KV , error ) {
562
- result , err := iter .nextResult (STATE_QUERY_RESULT )
563
- if err != nil {
562
+ if result , err := iter .nextResult (STATE_QUERY_RESULT ); err == nil {
563
+ return result .(* queryresult.KV ), err
564
+ } else {
564
565
return nil , err
565
566
}
566
- return result .(* queryresult.KV ), err
567
567
}
568
568
569
569
func (iter * HistoryQueryIterator ) Next () (* queryresult.KeyModification , error ) {
570
- result , err := iter .nextResult (HISTORY_QUERY_RESULT )
571
- if err != nil {
570
+ if result , err := iter .nextResult (HISTORY_QUERY_RESULT ); err == nil {
571
+ return result .(* queryresult.KeyModification ), err
572
+ } else {
572
573
return nil , err
573
574
}
574
- return result .(* queryresult.KeyModification ), err
575
575
}
576
576
577
577
// HasNext returns true if the range query iterator contains additional keys
@@ -608,15 +608,13 @@ func (iter *CommonIterator) getResultFromBytes(queryResultBytes *pb.QueryResultB
608
608
}
609
609
610
610
func (iter * CommonIterator ) fetchNextQueryResult () error {
611
- response , err := iter .handler .handleQueryStateNext (iter .response .Id , iter .uuid )
612
-
613
- if err != nil {
611
+ if response , err := iter .handler .handleQueryStateNext (iter .response .Id , iter .uuid ); err == nil {
612
+ iter .currentLoc = 0
613
+ iter .response = response
614
+ return nil
615
+ } else {
614
616
return err
615
617
}
616
-
617
- iter .currentLoc = 0
618
- iter .response = response
619
- return nil
620
618
}
621
619
622
620
// nextResult returns the next QueryResult (i.e., either a KV struct or KeyModification)
0 commit comments