@@ -6,14 +6,14 @@ module Stub where
6
6
7
7
import qualified Common.Common as Pb
8
8
9
- import Control.Monad.Except ( ExceptT (.. ), runExceptT )
9
+ import Control.Monad.Except ( ExceptT (.. ), runExceptT , throwError )
10
10
11
- -- import Data.Int (fromIntegral)
12
11
import Data.Bifunctor
13
12
import Data.ByteString as BS
14
13
import qualified Data.ByteString.Lazy as LBS
14
+ import Data.Char ( chr )
15
15
import Data.IORef ( modifyIORef , newIORef , readIORef , writeIORef )
16
- import Data.Text
16
+ import Data.Text as TS
17
17
import Data.Text.Encoding
18
18
import Data.Text.Lazy as TL
19
19
import Data.Vector as Vector ( (!) , Vector , empty , foldr , length , toList )
@@ -137,13 +137,6 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
137
137
Right _ -> pure ()
138
138
listenForResponse (recvStream ccs)
139
139
140
- --
141
- -- -- setStateValidationParameter :: ccs -> String -> [ByteString] -> Maybe Error
142
- -- setStateValidationParameter ccs key parameters = Right notImplemented
143
- --
144
- -- -- getStateValiationParameter :: ccs -> String -> Either Error [ByteString]
145
- -- getStateValiationParameter ccs key = Left notImplemented
146
- --
147
140
-- TODO: Implement better error handling/checks etc
148
141
-- getStateByRange :: ccs -> Text -> Text -> IO (Either Error StateQueryIterator)
149
142
getStateByRange ccs startKey endKey =
@@ -173,7 +166,37 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
173
166
Right _ -> pure ()
174
167
runExceptT $ ExceptT (listenForResponse (recvStream ccs)) >>= (bsToSqiAndMeta ccs)
175
168
176
- -- TODO : implement all these interface functions
169
+ -- TODO: This is the next TODO! Implement these 7 function because they are needed in marbles.hs
170
+ -- getStateByPartialCompositeKey :: ccs -> Text -> [Text] -> Either Error StateQueryIterator
171
+ getStateByPartialCompositeKey ccs objectType keys = throwError $ Error " not implemented"
172
+
173
+ -- getStateByPartialCompositeKeyWithPagination :: ccs -> Text -> [Text] -> Int32 -> Text -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
174
+ getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark =
175
+ throwError $ Error " not implemented"
176
+
177
+ -- createCompositeKey :: ccs -> Text -> [Text] -> Either Error Text
178
+ createCompositeKey ccs objectType keys =
179
+ let keysString = Prelude. foldr (\ key acc -> acc ++ TS. unpack key ++ nullCodepoint) " " keys
180
+ nullCodepoint = [ chr 0 ]
181
+ in
182
+ -- TODO: Check that objectTypes and keys are all valid utf8 strings
183
+ Right $ TS. pack $ " \x00 " ++ TS. unpack objectType ++ nullCodepoint ++ keysString
184
+
185
+ -- splitCompositeKey :: ccs -> Text -> Either Error (Text, [Text])
186
+ splitCompositeKey ccs key =
187
+ -- key has the form \x00objectTypeU+0000keyU+0000key etc so we use `tail key` to ignore the \x00 char
188
+ -- and then split on the unicode codepoint U+0000 to extract the objectType and keys
189
+ let keys = TS. splitOn (TS. singleton $ chr 0 ) (TS. tail key) in Right (Prelude. head keys, Prelude. tail keys)
190
+
191
+ -- getQueryResult :: ccs -> Text -> Either Error StateQueryIterator
192
+ getQueryResult ccs query = throwError $ Error " not implemented"
193
+
194
+ -- getQueryResultWithPagination :: ccs -> Text -> Int32 -> Text -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
195
+ getQueryResultWithPagination ccs key pageSize bookmark = throwError $ Error " not implemented"
196
+
197
+ -- getHistoryForKey :: ccs -> Text -> Either Error HistoryQueryIterator
198
+ getHistoryForKey ccs key = throwError $ Error " not implemented"
199
+
177
200
instance StateQueryIteratorInterface StateQueryIterator where
178
201
-- TODO: remove the IO from this function (possibly with the State monad)
179
202
-- hasNext :: sqi -> IO Bool
@@ -184,6 +207,7 @@ instance StateQueryIteratorInterface StateQueryIterator where
184
207
pure $ (currentLoc < Prelude. length (Pb. queryResponseResults queryResponse))
185
208
|| (Pb. queryResponseHasMore queryResponse)
186
209
210
+ -- TODO : implement close function (need to do anything here in haskell?)
187
211
-- close :: sqi -> IO (Maybe Error)
188
212
close _ = pure Nothing
189
213
@@ -296,28 +320,6 @@ fetchNextQueryResult sqi = do
296
320
Left err -> error (" Error while streaming: " ++ show err)
297
321
Right _ -> pure ()
298
322
runExceptT $ ExceptT (listenForResponse (recvStream $ sqiChaincodeStub sqi)) >>= bsToQueryResponse
299
- --
300
- -- -- getStateByPartialCompositeKey :: ccs -> String -> [String] -> Either Error StateQueryIterator
301
- -- getStateByPartialCompositeKey ccs objectType keys = Left notImplemented
302
- --
303
- -- --getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
304
- -- getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark = Left notImplemented
305
- --
306
- -- --createCompositeKey :: ccs -> String -> [String] -> Either Error String
307
- -- createCompositeKey ccs objectType keys = Left notImplemented
308
- --
309
- -- --splitCompositeKey :: ccs -> String -> Either Error (String, [String])
310
- -- splitCompositeKey ccs key = Left notImplemented
311
- --
312
- -- --getQueryResult :: ccs -> String -> Either Error StateQueryIterator
313
- -- getQueryResult ccs query = Left notImplemented
314
- --
315
- -- --getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
316
- -- getQueryResultWithPagination ccs key pageSize bookmark = Left notImplemented
317
- --
318
- -- --getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
319
- -- getHistoryForKey ccs key = Left notImplemented
320
- --
321
323
-- --getPrivateData :: ccs -> String -> String -> Either Error ByteString
322
324
-- getPrivateData ccs collection key = Left notImplemented
323
325
--
0 commit comments