Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 93ee862

Browse files
author
Nick Waywood
committed
wip: prepared stubs for next functions to be implemented
Signed-off-by: Nick Waywood <nwaywood@au1.ibm.com>
1 parent d553d7f commit 93ee862

File tree

2 files changed

+42
-38
lines changed

2 files changed

+42
-38
lines changed

src/Interfaces.hs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ class ChaincodeStubInterface ccs where
124124
-- Call Close() on the returned StateQueryIteratorInterface object when done.
125125
-- The query is re-executed during validation phase to ensure result set
126126
-- has not changed since transaction endorsement (phantom reads detected).
127-
-- getStateByPartialCompositeKey :: ccs -> String -> [String] -> Either Error StateQueryIterator
127+
getStateByPartialCompositeKey :: ccs -> Text -> [Text] -> ExceptT Error IO StateQueryIterator
128+
128129
-- GetStateByPartialCompositeKeyWithPagination queries the state in the ledger based on
129130
-- a given partial composite key. This function returns an iterator
130131
-- which can be used to iterate over the composite keys whose
@@ -143,18 +144,22 @@ class ChaincodeStubInterface ccs where
143144
-- code point). See related functions SplitCompositeKey and CreateCompositeKey.
144145
-- Call Close() on the returned StateQueryIteratorInterface object when done.
145146
-- This call is only supported in a read only transaction.
146-
-- getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
147+
getStateByPartialCompositeKeyWithPagination
148+
:: ccs -> Text -> [Text] -> Int -> Text -> ExceptT Error IO (StateQueryIterator, Pb.QueryResponseMetadata)
149+
147150
-- CreateCompositeKey combines the given `attributes` to form a composite
148151
-- key. The objectType and attributes are expected to have only valid utf8
149152
-- strings and should not contain U+0000 (nil byte) and U+10FFFF
150153
-- (biggest and unallocated code point).
151154
-- The resulting composite key can be used as the key in PutState().
152-
-- createCompositeKey :: ccs -> String -> [String] -> Either Error String
155+
createCompositeKey :: ccs -> Text -> [Text] -> Either Error Text
156+
153157
-- SplitCompositeKey splits the specified key into attributes on which the
154158
-- composite key was formed. Composite keys found during range queries
155159
-- or partial composite key queries can therefore be split into their
156160
-- composite parts.
157-
-- splitCompositeKey :: ccs -> String -> Either Error (String, [String])
161+
splitCompositeKey :: ccs -> Text -> Either Error (Text, [Text])
162+
158163
-- GetQueryResult performs a "rich" query against a state database. It is
159164
-- only supported for state databases that support rich query,
160165
-- e.g.CouchDB. The query string is in the native syntax
@@ -170,7 +175,8 @@ class ChaincodeStubInterface ccs where
170175
-- be detected at validation/commit time. Applications susceptible to this
171176
-- should therefore not use GetQueryResult as part of transactions that update
172177
-- ledger, and should limit use to read-only chaincode operations.
173-
-- getQueryResult :: ccs -> String -> Either Error StateQueryIterator
178+
getQueryResult :: ccs -> Text -> ExceptT Error IO StateQueryIterator
179+
174180
-- GetQueryResultWithPagination performs a "rich" query against a state database.
175181
-- It is only supported for state databases that support rich query,
176182
-- e.g., CouchDB. The query string is in the native syntax
@@ -184,7 +190,9 @@ class ChaincodeStubInterface ccs where
184190
-- can be used as a value to the bookmark argument. Otherwise, an empty string
185191
-- must be passed as bookmark.
186192
-- This call is only supported in a read only transaction.
187-
-- getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
193+
getQueryResultWithPagination
194+
:: ccs -> Text -> Int -> Text -> ExceptT Error IO (StateQueryIterator, Pb.QueryResponseMetadata)
195+
188196
-- GetHistoryForKey returns a history of key values across time.
189197
-- For each historic key update, the historic value and associated
190198
-- transaction id and timestamp are returned. The timestamp is the
@@ -197,7 +205,9 @@ class ChaincodeStubInterface ccs where
197205
-- detected at validation/commit time. Applications susceptible to this
198206
-- should therefore not use GetHistoryForKey as part of transactions that
199207
-- update ledger, and should limit use to read-only chaincode operations.
200-
-- getHistoryForKey :: ccs -> Either Error HistoryQueryIterator
208+
-- TODO: value should be HistoryQueryIterator
209+
getHistoryForKey :: ccs -> Text -> ExceptT Error IO StateQueryIterator
210+
201211
-- GetPrivateData returns the value of the specified `key` from the specified
202212
-- `collection`. Note that GetPrivateData doesn't read data from the
203213
-- private writeset, which has not been committed to the `collection`. In

src/Stub.hs

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Stub where
66

77
import qualified Common.Common as Pb
88

9-
import Control.Monad.Except ( ExceptT(..), runExceptT )
9+
import Control.Monad.Except ( ExceptT(..), runExceptT, throwError )
1010

1111
-- import Data.Int (fromIntegral)
1212
import Data.Bifunctor
@@ -137,13 +137,6 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
137137
Right _ -> pure ()
138138
listenForResponse (recvStream ccs)
139139

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-
--
147140
-- TODO: Implement better error handling/checks etc
148141
-- getStateByRange :: ccs -> Text -> Text -> IO (Either Error StateQueryIterator)
149142
getStateByRange ccs startKey endKey =
@@ -173,7 +166,29 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
173166
Right _ -> pure ()
174167
runExceptT $ ExceptT (listenForResponse (recvStream ccs)) >>= (bsToSqiAndMeta ccs)
175168

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 -> String -> [String] -> Either Error StateQueryIterator
171+
getStateByPartialCompositeKey ccs objectType keys = throwError $ Error "not implemented"
172+
173+
--getStateByPartialCompositeKeyWithPagination :: ccs -> String -> [String] -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
174+
getStateByPartialCompositeKeyWithPagination ccs objectType keys pageSize bookmark =
175+
throwError $ Error "not implemented"
176+
177+
--createCompositeKey :: ccs -> String -> [String] -> Either Error String
178+
createCompositeKey ccs objectType keys = throwError $ Error "not implemented"
179+
180+
--splitCompositeKey :: ccs -> String -> Either Error (String, [String])
181+
splitCompositeKey ccs key = throwError $ Error "not implemented"
182+
183+
--getQueryResult :: ccs -> String -> Either Error StateQueryIterator
184+
getQueryResult ccs query = throwError $ Error "not implemented"
185+
186+
--getQueryResultWithPagination :: ccs -> String -> Int32 -> String -> Either Error (StateQueryIterator, Pb.QueryResponseMetadata)
187+
getQueryResultWithPagination ccs key pageSize bookmark = throwError $ Error "not implemented"
188+
189+
--getHistoryForKey :: ccs -> String -> Either Error HistoryQueryIterator
190+
getHistoryForKey ccs key = throwError $ Error "not implemented"
191+
177192
instance StateQueryIteratorInterface StateQueryIterator where
178193
-- TODO: remove the IO from this function (possibly with the State monad)
179194
-- hasNext :: sqi -> IO Bool
@@ -184,6 +199,7 @@ instance StateQueryIteratorInterface StateQueryIterator where
184199
pure $ (currentLoc < Prelude.length (Pb.queryResponseResults queryResponse))
185200
|| (Pb.queryResponseHasMore queryResponse)
186201

202+
-- TODO : implement close function (need to do anything here in haskell?)
187203
-- close :: sqi -> IO (Maybe Error)
188204
close _ = pure Nothing
189205

@@ -296,28 +312,6 @@ fetchNextQueryResult sqi = do
296312
Left err -> error ("Error while streaming: " ++ show err)
297313
Right _ -> pure ()
298314
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-
--
321315
-- --getPrivateData :: ccs -> String -> String -> Either Error ByteString
322316
-- getPrivateData ccs collection key = Left notImplemented
323317
--

0 commit comments

Comments
 (0)