-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a16a291
commit 87db6e1
Showing
7 changed files
with
107 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"exe": "ecc", | ||
"key": "private.pem", | ||
"debug": true, | ||
"heapSize": 512, | ||
"productID": 1, | ||
"securityVersion": 1, | ||
"mounts": null, | ||
"files": null, | ||
"env": [ | ||
{ | ||
"name": "CHAINCODE_SERVER_ADDRESS", | ||
"fromHost": true | ||
}, | ||
{ | ||
"name": "CHAINCODE_PKG_ID", | ||
"fromHost": true | ||
}, | ||
{ | ||
"name": "FPC_ENABLED", | ||
"fromHost": true | ||
}, | ||
{ | ||
"name": "RUN_CCAAS", | ||
"fromHost": true | ||
}, | ||
|
||
{ | ||
"name": "FABRIC_LOGGING_SPEC", | ||
"fromHost": true | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
# CC-Tools-Demo Tutorial | ||
|
||
This tutorial shows how to build, install and test a Go Chaincode developed using the [CC-Tools]() framework and integrating it with the Fabric Private Chaincode (FPC) framework. | ||
This tutorial shows how to build, install and test a Go Chaincode developed using the [CC-Tools](https://github.com/hyperledger-labs/cc-tools) framework and integrating it with the Fabric Private Chaincode (FPC) framework. | ||
|
||
This tutorial illustrates a simple use case where we follow the [cc-tools-demo]() chaincode which is based on standard Fabric and then convert it to an FPC chaincode achieving FPC security capabilities. | ||
This tutorial illustrates a simple use case where we follow the [cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo) chaincode which is based on standard Fabric and then convert it to an FPC chaincode achieving FPC security capabilities. | ||
|
||
This tutorial is based on the [FPC with CC-Tools integration project]() and all our design choices are explained here in the [design document](). | ||
This tutorial is based on the [FPC with CC-Tools integration project](https://lf-hyperledger.atlassian.net/wiki/spaces/INTERN/pages/21954957/Hyperledger+Fabric+CC-Tools+Support+for+Fabric+Private+Chaincode) and all our design choices are explained here in the [design document](https://github.com/hyperledger/fabric-private-chaincode/tree/main/docs/design/integrate-with-cc-tools). | ||
Here are the steps to accomplish this: | ||
|
||
* Clone and copy the cc-tools-demo chaincode | ||
* Clone the cc-tools-demo chaincode | ||
* Modify the chaincode to use FPC | ||
* Build your FPC CC-tools-demo chaincode | ||
* Launch a Fabric network | ||
|
@@ -16,26 +16,32 @@ Here are the steps to accomplish this: | |
|
||
## Prerequisites | ||
|
||
This tutorial presumes that you have installed FPC on your `$GOPATH` as described in the FPC [README.md](../../../README.md#clone-fabric-private-chaincode) and `$FPC_PATH` is set accordingly. | ||
* This tutorial presumes that you have installed FPC on your `$GOPATH` as described in the FPC [README.md](../../../README.md#clone-fabric-private-chaincode) and `$FPC_PATH` is set accordingly. | ||
|
||
We also need a working FPC development environment. As described in the "Setup your Development Environment" Section of the FPC [README.md](../../../README.md#setup-your-development-environment), you can use our docker-based dev environment (Option 1) or setup your local development environment (Option 2). | ||
* We need a working FPC development environment. As described in the "Setup your Development Environment" Section of the FPC [README.md](../../../README.md#setup-your-development-environment), you can use our docker-based dev environment (Option 1) or setup your local development environment (Option 2). | ||
We recommend using the docker-based development environment and continue this tutorial within the dev container terminal. | ||
|
||
Moreover, within your FPC development you have already installed the FPC Go Chaincode Support components. | ||
* Moreover, within your FPC development you have already installed the FPC Go Chaincode Support components. | ||
See the installation steps in [ecc_go/README.md](../../../ecc_go/README.md#installation). | ||
|
||
We also assume that you are familiar with Fabric chaincode development in go. | ||
* We assume that you are familiar with Fabric chaincode development in go. | ||
Most of the steps in this tutorial follow the normal Fabric chaincode development process, however, there are a few differences that we will highlight here. | ||
|
||
## Clone and copy the cc-tools-demo chaincode | ||
* Also, since the tutorial is on the integration between cc-tools and FPC, we expect you to have a grasp knowledge of [cc-tools](https://github.com/hyperledger-labs/cc-tools) framework and that you've at least tried to run the [cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo) once by yourself on a Fabric network | ||
|
||
Clone the [cc-tools-demo]() repository and copy the [chaincode]() folder. Then paste it in the root directory for cc-tools-demo here. | ||
## Clone the cc-tools-demo chaincode | ||
|
||
We need to clone the chaincode folder from the [cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo) repository here. | ||
|
||
```bash | ||
cd ~ | ||
git clone https://github.com/hyperledger-labs/cc-tools-demo.git | ||
cp -a ~/cc-tools-demo/chaincode/. $FPC_PATH/samples/chaincode/cc-tools-demo/ | ||
cd $FPC_PATH/samples/chaincode/cc-tools-demo | ||
export ccToolsDemoPath=$FPC_PATH/samples/chaincode/cc-tools-demo | ||
git clone -n --no-checkout --depth=1 --filter=tree:0 https://github.com/hyperledger-labs/cc-tools-demo.git "$ccToolsDemoPath/chaincode" | ||
cd "$ccToolsDemoPath/chaincode" || { echo "$ccToolsDemoPath/chaincode does not exist" ; exit 1; } | ||
git sparse-checkout set --no-cone chaincode/* | ||
git checkout | ||
mv chaincode/* $ccToolsDemoPath | ||
cd $ccToolsDemoPath | ||
sudo rm -r $ccToolsDemoPath/chaincode | ||
``` | ||
|
||
The chaincode code structure is different than normal chaincode as it's using the cc-tools framework. | ||
|
@@ -115,15 +121,6 @@ func runCCaaS() error { | |
|
||
``` | ||
|
||
## Set the needed env vars in the docker-compose file | ||
|
||
From the code above, we need to set two env variables for the chaincode application to work and use FPC and chaincode-as-a-service (CCAAS). One way to do this is to go to `$FPC_PATH/samples/deployment/test-network/docker-compose.yml` and edit both `ecc.peer0.org1.example.com` and `ecc.peer0.org2.example.com` environment block to have | ||
```yaml | ||
- RUN_CCAAS=true | ||
- FPC_ENABLED=true | ||
``` | ||
## Building FPC Go Chaincode | ||
|
||
Create a `Makefile` (i.e., `touch $FPC_PATH/samples/chaincode/cc-tools-demo/Makefile`) with the following content: | ||
|
@@ -133,30 +130,38 @@ TOP = ../../.. | |
include $(TOP)/ecc_go/build.mk | ||
|
||
CC_NAME ?= fpc-cc-tools-demo | ||
|
||
EGO_CONFIG_FILE ?= $(FPC_PATH)/ecc_go/ccToolsDemoEnclave.json | ||
|
||
``` | ||
|
||
Please make sure that in the file above the variable `TOP` points to the FPC root directory (i.e., `$FPC_PATH`) as it uses the `$FPC_PATH/ecc_go/build.mk` file. | ||
|
||
**Note**: In our case, we need to change the build command in the `$FPC_PATH/ecc_go/build.mk` file at the `ecc` target to be `ego-go build $(GOTAGS) -o $(ECC_BINARY)` instead of `ego-go build $(GOTAGS) -o $(ECC_BINARY) main.go` | ||
|
||
|
||
In `$FPC_PATH/samples/chaincode/cc-tools-demo` directory, to build the chaincode and package it as docker image, execute: | ||
|
||
```bash | ||
make | ||
``` | ||
|
||
Note: this command runs inside the FPC dev environment and not your local host. | ||
|
||
**Note**: If you faced this error: | ||
|
||
```bash | ||
/project/pkg/mod/github.com/hyperledger-labs/[email protected]/mock/mockstub.go:146:22: cannot use stub (variable of type *MockStub) as shim.ChaincodeStubInterface value in argument to stub.cc.Init: *MockStub does not implement shim.ChaincodeStubInterface (missing method PurgePrivateData) | ||
``` | ||
|
||
This is because there is a minor difference between the `ChaincodeStubInterface` used in the cc-tools `Mockstub` as it's missing the `PurgePrivateData` method. | ||
To solve this, run `go mod vendor` in the `$FPC_PATH/samples/chaincode/cc-tools-demo` root directory to download all used packages and go to the file of the error to add the missing method there. | ||
|
||
```bash | ||
nano $FPC_PATH/vendor/github.com/hyperledger-labs/cc-tools/mock/mockstub.go | ||
``` | ||
|
||
add the following function | ||
|
||
```go | ||
// PurgePrivateData ... | ||
func (stub *MockStub) PurgePrivateData(collection, key string) error { | ||
|
@@ -203,7 +208,19 @@ cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network | |
./network.sh createChannel -c mychannel | ||
``` | ||
|
||
Once the network is up and running, we install the simple asset chaincode and the FPC Enclave Registry. | ||
|
||
### Set the needed env vars in the docker-compose file | ||
|
||
From the code above, we need to set two env variables for the chaincode application to work and use FPC and chaincode-as-a-service (CCAAS). One way to do this is to go to `$FPC_PATH/samples/deployment/test-network/docker-compose.yml` and edit both `ecc.peer0.org1.example.com` and `ecc.peer0.org2.example.com` environment block to have | ||
|
||
```yaml | ||
- RUN_CCAAS=true | ||
- FPC_ENABLED=true | ||
``` | ||
### Install the chaincode | ||
Once the network is up and running, we install the cc-tools-demo chaincode and the FPC Enclave Registry. | ||
We provide a small shell script to make this task a bit easier. | ||
```bash | ||
|
@@ -214,8 +231,6 @@ cd $FPC_PATH/samples/deployment/test-network | |
./installFPC.sh | ||
``` | ||
|
||
Note that the `installFPC.sh` script returns an export statement you need to copy and paste in the terminal. | ||
This sets environment variables for the package IDs for each chaincode container. | ||
Continue by running: | ||
|
||
```bash | ||
|
@@ -224,7 +239,7 @@ make ercc-ecc-start | |
|
||
You should see now four containers running (i.e., `cc-tools-demo.peer0.org1`, `cc-tools-demo.peer0.org2`, `ercc.peer0.org1`, and `ercc.peer0.org2`). | ||
|
||
### Invoke simple asset | ||
### Invoke simple getSchema transaction | ||
|
||
Open a new terminal and connect to the `fpc-development-go-support` container by running | ||
|
||
|
@@ -270,3 +285,9 @@ export RUN_CCAAS=true | |
``` | ||
|
||
Congratulations! You have successfully created an FPC chaincode with go using cc-tools and invoked it using our simple cli. | ||
|
||
Now you can test all your work again by running the [test](./testTutorial.sh) script | ||
|
||
## Next Step | ||
|
||
CC-tools-demo also provides a unique API server called CCAPI that is able to communicate with the peers and execute transactions through a REST API. We integrated this either in the [CCAPI tutorial](../../application/ccapi/) |
0
commands.sh → ...s/chaincode/cc-tools-demo/testTutorial.sh
100755 → 100644
File renamed without changes.