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

Commit 7f1e712

Browse files
airvinnwaywood
andcommitted
Printing the key/value of marbles returned from GetStateByRange
Co-authored-by: Nick Waywood <n.waywood@gmail.com> Signed-off-by: Allison Irvin <allison.irvin2@gmail.com>
1 parent 32f0822 commit 7f1e712

File tree

5 files changed

+62
-20
lines changed

5 files changed

+62
-20
lines changed

examples/Fabcar.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE DeriveGeneric #-}
33

4-
-- peer chaincode invoke -n mycc -c '{"Args":["initLedger"]}' -C myc
5-
-- peer chaincode invoke -n mycc -c '{"Args":["createCar", "CAR10", "Ford", "Falcon", "White", "Al"]}' -C myc
6-
-- peer chaincode invoke -n mycc -c '{"Args":["queryCar", "CAR10"]}' -C myc
7-
-- peer chaincode invoke -n mycc -c '{"Args":["changeCarOwner", "CAR10", "Nick"]}' -C myc
8-
94
module Fabcar where
105

116
import GHC.Generics

examples/Marbles.hs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
{-# LANGUAGE OverloadedStrings #-}
22
{-# LANGUAGE DeriveGeneric #-}
33

4-
-- Example invocations:
5-
-- peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc -o orderer:7050
6-
-- peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc
7-
-- peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble2","blue","large","Nick"]}' -C myc
8-
-- peer chaincode invoke -n mycc -c '{"Args":["readMarble","marble1"]}' -C myc
9-
-- peer chaincode invoke -n mycc -c '{"Args":["deleteMarble","marble1"]}' -C myc
10-
-- peer chaincode invoke -n mycc -c '{"Args":["transferMarble","marble1", "Nick"]}' -C myc
11-
-- peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRange","marble1", "marble3"]}' -C myc
12-
134
module Marbles where
145

156
import GHC.Generics
@@ -44,6 +35,7 @@ import Data.Aeson ( ToJSON
4435
, encode
4536
, decode
4637
)
38+
4739
import Debug.Trace
4840

4941
main :: IO ()
@@ -190,7 +182,9 @@ generateResultBytes sqi text = do
190182
eeKV <- next sqi
191183
-- TODO: We need to check that the Either Error KV returned from next
192184
-- is correct and append the showable version of KVs instead of "abc".
193-
generateResultBytes sqi (append text "abc")
185+
case eeKV of
186+
Right kv -> generateResultBytes sqi (append text $ pack $ show kv)
187+
Left e -> pure $ Left e
194188
else pure $ Right $ TSE.encodeUtf8 text
195189

196190
parseMarble :: [Text] -> Marble

examples/readme.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Haskell Chaincode Examples
2+
3+
## Simple Application Chaincode (SACC)
4+
5+
The SACC chaincode can be instantiated with:
6+
```
7+
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["init","a","100"]}' -C myc -o orderer:7050
8+
```
9+
10+
The chaincode can then be invoked with the following examples:
11+
12+
```
13+
peer chaincode invoke -n mycc -c '{"Args":["get","a"]}' -C myc
14+
peer chaincode invoke -n mycc -c '{"Args":["put","b","60"]}' -C myc
15+
peer chaincode invoke -n mycc -c '{"Args":["set","b","60"]}' -C myc
16+
peer chaincode invoke -n mycc -c '{"Args":["del","a"]}' -C myc
17+
```
18+
19+
20+
## Marbles Chaincode
21+
22+
The Marbles chaincode can be instantiated with:
23+
```
24+
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc -o orderer:7050
25+
```
26+
27+
The chaincode can then be invoked with the following examples:
28+
```
29+
peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc
30+
peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble2","blue","large","Nick"]}' -C myc
31+
peer chaincode invoke -n mycc -c '{"Args":["readMarble","marble1"]}' -C myc
32+
peer chaincode invoke -n mycc -c '{"Args":["deleteMarble","marble1"]}' -C myc
33+
peer chaincode invoke -n mycc -c '{"Args":["transferMarble","marble1", "Nick"]}' -C myc
34+
peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRange","marble1", "marble3"]}' -C myc
35+
```
36+
37+
## Fabcar Chaincode
38+
39+
The Fabcar chaincode can be instantiated with:
40+
```
41+
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["init"]}' -C myc -o orderer:7050
42+
```
43+
44+
The chaincode can then be invoked with the following examples:
45+
```
46+
peer chaincode invoke -n mycc -c '{"Args":["initLedger"]}' -C myc
47+
peer chaincode invoke -n mycc -c '{"Args":["createCar", "CAR10", "Ford", "Falcon", "White", "Al"]}' -C myc
48+
peer chaincode invoke -n mycc -c '{"Args":["queryCar", "CAR10"]}' -C myc
49+
peer chaincode invoke -n mycc -c '{"Args":["changeCarOwner", "CAR10", "Nick"]}' -C myc
50+
```

readme.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ Note: Since running chaincode in production mode depends on a language specific
3535

3636
### Running the Haskell chaincode
3737

38-
The Haskell chaincode process can be started with:
38+
There are three example chaincodes that have been implemented. Please see the
39+
readme in the `examples` directory for information on how to run each of them.
40+
41+
The instructions for running for the `sacc` example are described below.
42+
43+
Start the Haskell chaincode process with:
3944

4045
```
4146
stack run sacc-exe
4247
```
4348

44-
To run the `sacc` example. Look at `package.yaml` to see available executables.
45-
4649
When the Fabric peer is running (see below), the Haskell process that is started does a number of things
4750

4851
1. It connects to the Fabric peer through gRPC
@@ -71,7 +74,6 @@ peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["init","a","100"
7174
```
7275

7376
The chaincode can then be invoked with the following examples:
74-
7577
```
7678
peer chaincode invoke -n mycc -c '{"Args":["get","a"]}' -C myc
7779
peer chaincode invoke -n mycc -c '{"Args":["put","b","60"]}' -C myc
@@ -83,7 +85,7 @@ peer chaincode invoke -n mycc -c '{"Args":["del","a"]}' -C myc
8385

8486
- [x] Finish implementing shim functions and clean up shim module exports
8587
- [x] Add examples directory
86-
- [ ] Write unit tests for stub functions
8788
- [ ] Add support for concurrent transactions
8889
- [ ] Finish implementing all stub functions
8990
- [ ] Publish to Hackage
91+
- [ ] Add traces throughout the chaincode examples

src/Stub.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
157157

158158
-- TODO : implement all these interface functions
159159
instance StateQueryIteratorInterface StateQueryIterator where
160+
-- TODO: remove the IO from this function (possibly with the State monad)
160161
-- hasNext :: sqi -> IO Bool
161162
hasNext sqi = do
162163
queryResponse <- readIORef $ sqiResponse sqi

0 commit comments

Comments
 (0)