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

Commit f5745bd

Browse files
authored
Merge pull request #15 from airvin/iterator-methods
Finished GetStateByRange stub function and example usage
2 parents 26f9598 + a59b4c2 commit f5745bd

File tree

5 files changed

+59
-20
lines changed

5 files changed

+59
-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: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +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-
-- peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRangeWithPagination","marble1", "marble3", "2", ""]}' -C myc
13-
144
module Marbles where
155

166
import GHC.Generics
@@ -47,6 +37,7 @@ import Data.Aeson ( ToJSON
4737
, encode
4838
, decode
4939
)
40+
5041
import Debug.Trace
5142

5243
main :: IO ()

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
@@ -160,6 +160,7 @@ instance ChaincodeStubInterface DefaultChaincodeStub where
160160

161161
-- TODO : implement all these interface functions
162162
instance StateQueryIteratorInterface StateQueryIterator where
163+
-- TODO: remove the IO from this function (possibly with the State monad)
163164
-- hasNext :: sqi -> IO Bool
164165
hasNext sqi = do
165166
queryResponse <- readIORef $ sqiResponse sqi

0 commit comments

Comments
 (0)