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

Finished GetStateByRange stub function and example usage #15

Merged
merged 2 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/Fabcar.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}

-- peer chaincode invoke -n mycc -c '{"Args":["initLedger"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["createCar", "CAR10", "Ford", "Falcon", "White", "Al"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["queryCar", "CAR10"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["changeCarOwner", "CAR10", "Nick"]}' -C myc

module Fabcar where

import GHC.Generics
Expand Down
11 changes: 1 addition & 10 deletions examples/Marbles.hs
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}

-- Example invocations:
-- peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc -o orderer:7050
-- peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble2","blue","large","Nick"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["readMarble","marble1"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["deleteMarble","marble1"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["transferMarble","marble1", "Nick"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRange","marble1", "marble3"]}' -C myc
-- peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRangeWithPagination","marble1", "marble3", "2", ""]}' -C myc

module Marbles where

import GHC.Generics
Expand Down Expand Up @@ -47,6 +37,7 @@ import Data.Aeson ( ToJSON
, encode
, decode
)

import Debug.Trace

main :: IO ()
Expand Down
50 changes: 50 additions & 0 deletions examples/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Haskell Chaincode Examples

## Simple Application Chaincode (SACC)

The SACC chaincode can be instantiated with:
```
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["init","a","100"]}' -C myc -o orderer:7050
```

The chaincode can then be invoked with the following examples:

```
peer chaincode invoke -n mycc -c '{"Args":["get","a"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["put","b","60"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["set","b","60"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["del","a"]}' -C myc
```


## Marbles Chaincode

The Marbles chaincode can be instantiated with:
```
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc -o orderer:7050
```

The chaincode can then be invoked with the following examples:
```
peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble1","red","large","Al"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["initMarble","marble2","blue","large","Nick"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["readMarble","marble1"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["deleteMarble","marble1"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["transferMarble","marble1", "Nick"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["getMarblesByRange","marble1", "marble3"]}' -C myc
```

## Fabcar Chaincode

The Fabcar chaincode can be instantiated with:
```
peer chaincode instantiate -n mycc -v v0 -l golang -c '{"Args":["init"]}' -C myc -o orderer:7050
```

The chaincode can then be invoked with the following examples:
```
peer chaincode invoke -n mycc -c '{"Args":["initLedger"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["createCar", "CAR10", "Ford", "Falcon", "White", "Al"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["queryCar", "CAR10"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["changeCarOwner", "CAR10", "Nick"]}' -C myc
```
12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ Note: Since running chaincode in production mode depends on a language specific

### Running the Haskell chaincode

The Haskell chaincode process can be started with:
There are three example chaincodes that have been implemented. Please see the
readme in the `examples` directory for information on how to run each of them.

The instructions for running for the `sacc` example are described below.

Start the Haskell chaincode process with:

```
stack run sacc-exe
```

To run the `sacc` example. Look at `package.yaml` to see available executables.

When the Fabric peer is running (see below), the Haskell process that is started does a number of things

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

The chaincode can then be invoked with the following examples:

```
peer chaincode invoke -n mycc -c '{"Args":["get","a"]}' -C myc
peer chaincode invoke -n mycc -c '{"Args":["put","b","60"]}' -C myc
Expand All @@ -83,7 +85,7 @@ peer chaincode invoke -n mycc -c '{"Args":["del","a"]}' -C myc

- [x] Finish implementing shim functions and clean up shim module exports
- [x] Add examples directory
- [ ] Write unit tests for stub functions
- [ ] Add support for concurrent transactions
- [ ] Finish implementing all stub functions
- [ ] Publish to Hackage
- [ ] Add traces throughout the chaincode examples
1 change: 1 addition & 0 deletions src/Stub.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ instance ChaincodeStubInterface DefaultChaincodeStub where

-- TODO : implement all these interface functions
instance StateQueryIteratorInterface StateQueryIterator where
-- TODO: remove the IO from this function (possibly with the State monad)
-- hasNext :: sqi -> IO Bool
hasNext sqi = do
queryResponse <- readIORef $ sqiResponse sqi
Expand Down