MCPcopy
hub / github.com/hyperledger/fabric / getMultiple

Method getMultiple

integration/chaincode/multi/chaincode.go:107–144  ·  view source on GitHub ↗

getMultiple - get multiple states

(stub shim.ChaincodeStubInterface, countKeys string)

Source from the content-addressed store, hash-verified

105
106// getMultiple - get multiple states
107func (t *Operations) getMultiple(stub shim.ChaincodeStubInterface, countKeys string) *pb.Response {
108 num, _ := strconv.Atoi(countKeys)
109
110 keys := make([]string, 0, num)
111
112 keys = append(keys, "non-exist-key")
113 for i := range num {
114 key := "key" + strconv.Itoa(i)
115 keys = append(keys, key)
116 }
117
118 resps, err := stub.GetMultipleStates(keys...)
119 if err != nil {
120 return shim.Error(err.Error())
121 }
122
123 if len(resps) != num+1 {
124 return shim.Error("number of results is not correct")
125 }
126
127 // non exist key return nil
128 if resps[0] != nil {
129 errStr := fmt.Sprintf("incorrect result %d elem, got %v", 0, string(resps[0]))
130 return shim.Error(errStr)
131 }
132
133 if string(resps[1]) != "key"+strconv.Itoa(0) {
134 errStr := fmt.Sprintf("incorrect result %d elem, got %v", 0, string(resps[1]))
135 return shim.Error(errStr)
136 }
137
138 if string(resps[num]) != "key"+strconv.Itoa(num-1) {
139 errStr := fmt.Sprintf("incorrect result %d elem, got %v", 0, string(resps[num]))
140 return shim.Error(errStr)
141 }
142
143 return shim.Success(nil)
144}

Callers 1

InvokeMethod · 0.95

Calls 2

ErrorMethod · 0.65
GetMultipleStatesMethod · 0.45

Tested by

no test coverage detected