@@ -127,34 +127,37 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
127127 getStateByRange ccs startKey endKey =
128128 let payload = getStateByRangePayload startKey endKey
129129 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)
133130 -- ExceptT is a monad transformer that allows us to compose these by binding over IO Either
134131 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
152151 e <- (sendStream ccs) message
153152 case e of
154153 Left err -> error (" Error while streaming: " ++ show err)
155154 Right _ -> pure ()
156155 runExceptT $ ExceptT (listenForResponse (recvStream ccs)) >>= bsToSqi
157156
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+
158161 -- TODO : implement all these interface functions
159162instance StateQueryIteratorInterface StateQueryIterator where
160163-- TODO: remove the IO from this function (possibly with the State monad)
@@ -222,75 +225,73 @@ fetchNextQueryResult sqi = do
222225 Right _ -> pure ()
223226 runExceptT $ ExceptT (listenForResponse (recvStream $ sqiChaincodeStub sqi)) >>= bsToQueryResponse
224227
225- --
226- -- -- getStateByRangeWithPagination :: ccs -> String -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
227- -- getStateByRangeWithPagination ccs startKey endKey pageSize bookmark = Left notImplemented
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
228+
229+ --
230+ -- -- getStateByPartialCompositeKey :: ccs -> String -> [String] -> Either Error StateQueryIterator
231+ -- getStateByPartialCompositeKey ccs objectType keys = Left notImplemented
232+ --
233+ -- --getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
234+ -- getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark = Left notImplemented
235+ --
236+ -- --createCompositeKey :: ccs -> String -> [String] -> Either Error String
237+ -- createCompositeKey ccs objectType keys = Left notImplemented
238+ --
239+ -- --splitCompositeKey :: ccs -> String -> Either Error (String, [String])
240+ -- splitCompositeKey ccs key = Left notImplemented
241+ --
242+ -- --getQueryResult :: ccs -> String -> Either Error StateQueryIterator
243+ -- getQueryResult ccs query = Left notImplemented
244+ --
245+ -- --getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
246+ -- getQueryResultWithPagination ccs key pageSize bookmark = Left notImplemented
247+ --
248+ -- --getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
249+ -- getHistoryForKey ccs key = Left notImplemented
250+ --
251+ -- --getPrivateData :: ccs -> String -> String -> Either Error ByteString
252+ -- getPrivateData ccs collection key = Left notImplemented
253+ --
254+ -- --getPrivateDataHash :: ccs -> String -> String -> Either Error ByteString
255+ -- getPrivateDataHash ccs collection key = Left notImplemented
256+ --
257+ -- --putPrivateData :: ccs -> String -> String -> ByteString -> Maybe Error
258+ -- putPrivateData ccs collection string value = Right notImplemented
259+ --
260+ -- --delPrivateData :: ccs -> String -> String -> Maybe Error
261+ -- delPrivateData ccs collection key = Right notImplemented
262+ --
263+ -- --setPrivateDataValidationParameter :: ccs -> String -> String -> ByteArray -> Maybe Error
264+ -- setPrivateDataValidationParameter ccs collection key params = Right notImplemented
265+ --
266+ -- --getPrivateDataValidationParameter :: ccs -> String -> String -> Either Error ByteString
267+ -- getPrivateDataValidationParameter ccs collection key = Left notImplemented
268+ --
269+ -- --getPrivateDataByRange :: ccs -> String -> String -> String -> Either Error StateQueryIterator
270+ -- getPrivateDataByRange ccs collection startKey endKey = Left notImplemented
271+ --
272+ -- --getPrivateDataByPartialCompositeKey :: ccs -> String -> String -> [String] -> Either Error StateQueryIterator
273+ -- getPrivateDataByPartialCompositeKey ccs collection objectType keys = Left notImplemented
274+ --
275+ -- -- getPrivateDataQueryResult :: ccs -> String -> String -> Either Error StateQueryIterator
276+ -- getPrivateDataQueryResult ccs collection query = Left notImplemented
277+ --
278+ -- -- getCreator :: ccs -> Either Error ByteArray
279+ -- getCreator ccs = Right creator
280+ --
281+ -- -- getTransient :: ccs -> Either Error MapStringBytes
282+ -- getTransient ccs = Right transient
283+ --
284+ -- -- getBinding :: ccs -> Either Error MapStringBytes
285+ -- getBinding ccs = Right binding
286+ --
287+ -- -- getDecorations :: ccs -> MapStringBytes
288+ -- getDecorations ccs = Right decorations
289+ --
290+ -- -- getSignedProposal :: ccs -> Either Error Pb.SignedProposal
291+ -- getSignedProposal ccs = Right signedProposal
292+ --
293+ -- -- getTxTimestamp :: ccs -> Either Error Pb.Timestamp
294+ -- getTxTimestamp ccs = Right txTimestamp
295+ --
296+ -- -- setEvent :: ccs -> String -> ByteArray -> Maybe Error
297+ -- setEvent ccs = Right notImplemented
0 commit comments