@@ -8,12 +8,12 @@ import qualified Common.Common as Pb
8
8
9
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 )
@@ -167,26 +167,34 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
167
167
runExceptT $ ExceptT (listenForResponse (recvStream ccs)) >>= (bsToSqiAndMeta ccs)
168
168
169
169
-- TODO: This is the next TODO! Implement these 7 function because they are needed in marbles.hs
170
- -- getStateByPartialCompositeKey :: ccs -> String -> [String ] -> Either Error StateQueryIterator
170
+ -- getStateByPartialCompositeKey :: ccs -> Text -> [Text ] -> Either Error StateQueryIterator
171
171
getStateByPartialCompositeKey ccs objectType keys = throwError $ Error " not implemented"
172
172
173
- -- getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String ] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
173
+ -- getStateByPartialCompositeKeyWithPagination :: ccs -> Text -> [Text ] -> Int32 -> Text -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
174
174
getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark =
175
175
throwError $ Error " not implemented"
176
176
177
- -- createCompositeKey :: ccs -> String -> [String] -> Either Error String
178
- createCompositeKey ccs objectType keys = throwError $ Error " not implemented"
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
179
184
180
- -- splitCompositeKey :: ccs -> String -> Either Error (String, [String])
181
- splitCompositeKey ccs key = throwError $ Error " not implemented"
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)
182
190
183
- -- getQueryResult :: ccs -> String -> Either Error StateQueryIterator
191
+ -- getQueryResult :: ccs -> Text -> Either Error StateQueryIterator
184
192
getQueryResult ccs query = throwError $ Error " not implemented"
185
193
186
- -- getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
194
+ -- getQueryResultWithPagination :: ccs -> Text -> Int32 -> Text -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
187
195
getQueryResultWithPagination ccs key pageSize bookmark = throwError $ Error " not implemented"
188
196
189
- -- getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
197
+ -- getHistoryForKey :: ccs -> Text -> Either Error HistoryQueryIterator
190
198
getHistoryForKey ccs key = throwError $ Error " not implemented"
191
199
192
200
instance StateQueryIteratorInterface StateQueryIterator where
0 commit comments