@@ -127,34 +127,37 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
127
127
getStateByRange ccs startKey endKey =
128
128
let payload = getStateByRangePayload startKey endKey
129
129
message = buildChaincodeMessage GET_STATE_BY_RANGE payload (txId ccs) (channelId ccs)
130
- -- We have listenForResponse a :: IO (Either Error ByteString)
131
- -- and the function bsToSqi :: ByteString -> IO (Either Error StateQueryIterator)
132
- -- And want IO (Either Error StateQueryIterator)
133
130
-- ExceptT is a monad transformer that allows us to compose these by binding over IO Either
134
131
bsToSqi :: ByteString -> ExceptT Error IO StateQueryIterator
135
- bsToSqi bs = let eeaQueryResponse = parse (decodeMessage (FieldNumber 1 )) bs :: Either ParseError Pb. QueryResponse in
136
- case eeaQueryResponse of
137
- -- TODO: refactor out pattern matching, e.g. using >>= or <*>
138
- Left err -> ExceptT $ pure $ Left $ DecodeError err
139
- Right queryResponse -> ExceptT $ do
140
- -- queryResponse and currentLoc are IORefs as they need to be mutated
141
- -- as a part of the next() function
142
- queryResponseIORef <- newIORef queryResponse
143
- currentLocIORef <- newIORef 0
144
- pure $ Right StateQueryIterator
145
- { sqiChaincodeStub = ccs
146
- , sqiChannelId = getChannelId ccs
147
- , sqiTxId = getTxId ccs
148
- , sqiResponse = queryResponseIORef
149
- , sqiCurrentLoc = currentLocIORef
150
- }
151
- in do
132
+ bsToSqi bs =
133
+ let eeaQueryResponse = parse (decodeMessage (FieldNumber 1 )) bs :: Either ParseError Pb. QueryResponse
134
+ in
135
+ case eeaQueryResponse of
136
+ -- TODO: refactor out pattern matching, e.g. using >>= or <*>
137
+ Left err -> ExceptT $ pure $ Left $ DecodeError err
138
+ Right queryResponse -> ExceptT $ do
139
+ -- queryResponse and currentLoc are IORefs as they need to be mutated
140
+ -- as a part of the next() function
141
+ queryResponseIORef <- newIORef queryResponse
142
+ currentLocIORef <- newIORef 0
143
+ pure $ Right StateQueryIterator {
144
+ sqiChaincodeStub = ccs
145
+ , sqiChannelId = getChannelId ccs
146
+ , sqiTxId = getTxId ccs
147
+ , sqiResponse = queryResponseIORef
148
+ , sqiCurrentLoc = currentLocIORef
149
+ }
150
+ in do
152
151
e <- (sendStream ccs) message
153
152
case e of
154
153
Left err -> error (" Error while streaming: " ++ show err)
155
154
Right _ -> pure ()
156
155
runExceptT $ ExceptT (listenForResponse (recvStream ccs)) >>= bsToSqi
157
156
157
+ -- TODO: We need to implement this so we can test the fetchNextQueryResult functionality
158
+ -- getStateByRangeWithPagination :: ccs -> String -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
159
+ getStateByRangeWithPagination ccs startKey endKey pageSize bookmark = pure $ Left $ Error " Not implemented"
160
+
158
161
-- TODO : implement all these interface functions
159
162
instance StateQueryIteratorInterface StateQueryIterator where
160
163
-- hasNext :: sqi -> IO Bool
@@ -221,75 +224,73 @@ fetchNextQueryResult sqi = do
221
224
Right _ -> pure ()
222
225
runExceptT $ ExceptT (listenForResponse (recvStream $ sqiChaincodeStub sqi)) >>= bsToQueryResponse
223
226
224
- --
225
- -- -- getStateByRangeWithPagination :: ccs -> String -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
226
- -- getStateByRangeWithPagination ccs startKey endKey pageSize bookmark = Left notImplemented
227
- --
228
- -- -- getStateByPartialCompositeKey :: ccs -> String -> [String] -> Either Error StateQueryIterator
229
- -- getStateByPartialCompositeKey ccs objectType keys = Left notImplemented
230
- --
231
- -- --getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
232
- -- getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark = Left notImplemented
233
- --
234
- -- --createCompositeKey :: ccs -> String -> [String] -> Either Error String
235
- -- createCompositeKey ccs objectType keys = Left notImplemented
236
- --
237
- -- --splitCompositeKey :: ccs -> String -> Either Error (String, [String])
238
- -- splitCompositeKey ccs key = Left notImplemented
239
- --
240
- -- --getQueryResult :: ccs -> String -> Either Error StateQueryIterator
241
- -- getQueryResult ccs query = Left notImplemented
242
- --
243
- -- --getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
244
- -- getQueryResultWithPagination ccs key pageSize bookmark = Left notImplemented
245
- --
246
- -- --getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
247
- -- getHistoryForKey ccs key = Left notImplemented
248
- --
249
- -- --getPrivateData :: ccs -> String -> String -> Either Error ByteString
250
- -- getPrivateData ccs collection key = Left notImplemented
251
- --
252
- -- --getPrivateDataHash :: ccs -> String -> String -> Either Error ByteString
253
- -- getPrivateDataHash ccs collection key = Left notImplemented
254
- --
255
- -- --putPrivateData :: ccs -> String -> String -> ByteString -> Maybe Error
256
- -- putPrivateData ccs collection string value = Right notImplemented
257
- --
258
- -- --delPrivateData :: ccs -> String -> String -> Maybe Error
259
- -- delPrivateData ccs collection key = Right notImplemented
260
- --
261
- -- --setPrivateDataValidationParameter :: ccs -> String -> String -> ByteArray -> Maybe Error
262
- -- setPrivateDataValidationParameter ccs collection key params = Right notImplemented
263
- --
264
- -- --getPrivateDataValidationParameter :: ccs -> String -> String -> Either Error ByteString
265
- -- getPrivateDataValidationParameter ccs collection key = Left notImplemented
266
- --
267
- -- --getPrivateDataByRange :: ccs -> String -> String -> String -> Either Error StateQueryIterator
268
- -- getPrivateDataByRange ccs collection startKey endKey = Left notImplemented
269
- --
270
- -- --getPrivateDataByPartialCompositeKey :: ccs -> String -> String -> [String] -> Either Error StateQueryIterator
271
- -- getPrivateDataByPartialCompositeKey ccs collection objectType keys = Left notImplemented
272
- --
273
- -- -- getPrivateDataQueryResult :: ccs -> String -> String -> Either Error StateQueryIterator
274
- -- getPrivateDataQueryResult ccs collection query = Left notImplemented
275
- --
276
- -- -- getCreator :: ccs -> Either Error ByteArray
277
- -- getCreator ccs = Right creator
278
- --
279
- -- -- getTransient :: ccs -> Either Error MapStringBytes
280
- -- getTransient ccs = Right transient
281
- --
282
- -- -- getBinding :: ccs -> Either Error MapStringBytes
283
- -- getBinding ccs = Right binding
284
- --
285
- -- -- getDecorations :: ccs -> MapStringBytes
286
- -- getDecorations ccs = Right decorations
287
- --
288
- -- -- getSignedProposal :: ccs -> Either Error Pb.SignedProposal
289
- -- getSignedProposal ccs = Right signedProposal
290
- --
291
- -- -- getTxTimestamp :: ccs -> Either Error Pb.Timestamp
292
- -- getTxTimestamp ccs = Right txTimestamp
293
- --
294
- -- -- setEvent :: ccs -> String -> ByteArray -> Maybe Error
295
- -- setEvent ccs = Right notImplemented
227
+
228
+ --
229
+ -- -- getStateByPartialCompositeKey :: ccs -> String -> [String] -> Either Error StateQueryIterator
230
+ -- getStateByPartialCompositeKey ccs objectType keys = Left notImplemented
231
+ --
232
+ -- --getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
233
+ -- getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark = Left notImplemented
234
+ --
235
+ -- --createCompositeKey :: ccs -> String -> [String] -> Either Error String
236
+ -- createCompositeKey ccs objectType keys = Left notImplemented
237
+ --
238
+ -- --splitCompositeKey :: ccs -> String -> Either Error (String, [String])
239
+ -- splitCompositeKey ccs key = Left notImplemented
240
+ --
241
+ -- --getQueryResult :: ccs -> String -> Either Error StateQueryIterator
242
+ -- getQueryResult ccs query = Left notImplemented
243
+ --
244
+ -- --getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
245
+ -- getQueryResultWithPagination ccs key pageSize bookmark = Left notImplemented
246
+ --
247
+ -- --getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
248
+ -- getHistoryForKey ccs key = Left notImplemented
249
+ --
250
+ -- --getPrivateData :: ccs -> String -> String -> Either Error ByteString
251
+ -- getPrivateData ccs collection key = Left notImplemented
252
+ --
253
+ -- --getPrivateDataHash :: ccs -> String -> String -> Either Error ByteString
254
+ -- getPrivateDataHash ccs collection key = Left notImplemented
255
+ --
256
+ -- --putPrivateData :: ccs -> String -> String -> ByteString -> Maybe Error
257
+ -- putPrivateData ccs collection string value = Right notImplemented
258
+ --
259
+ -- --delPrivateData :: ccs -> String -> String -> Maybe Error
260
+ -- delPrivateData ccs collection key = Right notImplemented
261
+ --
262
+ -- --setPrivateDataValidationParameter :: ccs -> String -> String -> ByteArray -> Maybe Error
263
+ -- setPrivateDataValidationParameter ccs collection key params = Right notImplemented
264
+ --
265
+ -- --getPrivateDataValidationParameter :: ccs -> String -> String -> Either Error ByteString
266
+ -- getPrivateDataValidationParameter ccs collection key = Left notImplemented
267
+ --
268
+ -- --getPrivateDataByRange :: ccs -> String -> String -> String -> Either Error StateQueryIterator
269
+ -- getPrivateDataByRange ccs collection startKey endKey = Left notImplemented
270
+ --
271
+ -- --getPrivateDataByPartialCompositeKey :: ccs -> String -> String -> [String] -> Either Error StateQueryIterator
272
+ -- getPrivateDataByPartialCompositeKey ccs collection objectType keys = Left notImplemented
273
+ --
274
+ -- -- getPrivateDataQueryResult :: ccs -> String -> String -> Either Error StateQueryIterator
275
+ -- getPrivateDataQueryResult ccs collection query = Left notImplemented
276
+ --
277
+ -- -- getCreator :: ccs -> Either Error ByteArray
278
+ -- getCreator ccs = Right creator
279
+ --
280
+ -- -- getTransient :: ccs -> Either Error MapStringBytes
281
+ -- getTransient ccs = Right transient
282
+ --
283
+ -- -- getBinding :: ccs -> Either Error MapStringBytes
284
+ -- getBinding ccs = Right binding
285
+ --
286
+ -- -- getDecorations :: ccs -> MapStringBytes
287
+ -- getDecorations ccs = Right decorations
288
+ --
289
+ -- -- getSignedProposal :: ccs -> Either Error Pb.SignedProposal
290
+ -- getSignedProposal ccs = Right signedProposal
291
+ --
292
+ -- -- getTxTimestamp :: ccs -> Either Error Pb.Timestamp
293
+ -- getTxTimestamp ccs = Right txTimestamp
294
+ --
295
+ -- -- setEvent :: ccs -> String -> ByteArray -> Maybe Error
296
+ -- setEvent ccs = Right notImplemented
0 commit comments