@@ -19,18 +19,20 @@ limitations under the License.
19
19
package shim
20
20
21
21
import (
22
+ "bytes"
22
23
"errors"
23
24
"flag"
24
25
"fmt"
25
26
"io"
26
27
"os"
28
+ "regexp"
29
+ "strconv"
27
30
"strings"
28
31
29
32
"github.com/golang/protobuf/proto"
30
33
"github.com/golang/protobuf/ptypes/timestamp"
31
34
"github.com/hyperledger/fabric/common/util"
32
35
"github.com/hyperledger/fabric/core/comm"
33
- coder "github.com/hyperledger/fabric/core/ledger/util"
34
36
pb "github.com/hyperledger/fabric/protos/peer"
35
37
"github.com/op/go-logging"
36
38
"github.com/spf13/viper"
@@ -356,14 +358,14 @@ func (stub *ChaincodeStub) CreateCompositeKey(objectType string, attributes []st
356
358
}
357
359
358
360
func createCompositeKey (stub ChaincodeStubInterface , objectType string , attributes []string ) (string , error ) {
359
- var compositeKey [] byte
360
- compositeKey = append ( compositeKey , coder . EncodeOrderPreservingVarUint64 ( uint64 ( len ( objectType ))) ... )
361
- compositeKey = append ( compositeKey , [] byte (objectType )... )
361
+ var compositeKey bytes. Buffer
362
+ replacer := strings . NewReplacer ( " \x1E " , " \x1E \x1E " , " \x1F " , " \x1E \x1F " )
363
+ compositeKey . WriteString ( replacer . Replace (objectType ))
362
364
for _ , attribute := range attributes {
363
- compositeKey = append ( compositeKey , coder . EncodeOrderPreservingVarUint64 ( uint64 ( len (attribute ))) ... )
364
- compositeKey = append ( compositeKey , [] byte (attribute )... )
365
+ compositeKey . WriteString ( " \x1F " + strconv . Itoa ( len (attribute )) + " \x1F " )
366
+ compositeKey . WriteString ( replacer . Replace (attribute ))
365
367
}
366
- return string ( compositeKey ), nil
368
+ return compositeKey . String ( ), nil
367
369
}
368
370
369
371
//Given a composite key, SplitCompositeKey function splits the key into attributes
@@ -373,17 +375,15 @@ func (stub *ChaincodeStub) SplitCompositeKey(compositeKey string) (string, []str
373
375
}
374
376
375
377
func splitCompositeKey (stub ChaincodeStubInterface , compositeKey string ) (string , []string , error ) {
376
- startIndex := 0
377
- cKey := []byte (compositeKey )
378
- attributes := []string {}
379
- for startIndex < len (compositeKey ) {
380
- len , bytesConsumed := coder .DecodeOrderPreservingVarUint64 (cKey [startIndex :])
381
- attrBeginIndex := startIndex + int (bytesConsumed )
382
- attrEndIndex := attrBeginIndex + int (len )
383
- attributes = append (attributes , compositeKey [attrBeginIndex :attrEndIndex ])
384
- startIndex = attrEndIndex
378
+ re := regexp .MustCompile ("\x1F [0-9]+\x1F " )
379
+ splittedKey := re .Split (compositeKey , - 1 )
380
+ attributes := make ([]string , 0 )
381
+ replacer := strings .NewReplacer ("\x1E \x1F " , "\x1F " , "\x1E \x1E " , "\x1E " )
382
+ objectType := replacer .Replace (splittedKey [0 ])
383
+ for _ , attr := range splittedKey [1 :] {
384
+ attributes = append (attributes , replacer .Replace (attr ))
385
385
}
386
- return attributes [ 0 ] , attributes [ 1 :] , nil
386
+ return objectType , attributes , nil
387
387
}
388
388
389
389
//PartialCompositeKeyQuery function can be invoked by a chaincode to query the
0 commit comments