Skip to content

Commit 87db6e1

Browse files
committed
comments resolved
1 parent a16a291 commit 87db6e1

File tree

7 files changed

+107
-53
lines changed

7 files changed

+107
-53
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
!ecc/ecc
1010
!ecc_go/ecc_go
1111
!ecc_go/enclave.json
12+
!ecc_go/ccToolsDemoEnclave.json
1213
!ecc_enclave/_build/lib/libsgxcc.so
1314
# note: docker seems to have troubles with '+' in filenames in this file, at least in exceptions ..

ecc_go/ccToolsDemoEnclave.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"exe": "ecc",
3+
"key": "private.pem",
4+
"debug": true,
5+
"heapSize": 512,
6+
"productID": 1,
7+
"securityVersion": 1,
8+
"mounts": null,
9+
"files": null,
10+
"env": [
11+
{
12+
"name": "CHAINCODE_SERVER_ADDRESS",
13+
"fromHost": true
14+
},
15+
{
16+
"name": "CHAINCODE_PKG_ID",
17+
"fromHost": true
18+
},
19+
{
20+
"name": "FPC_ENABLED",
21+
"fromHost": true
22+
},
23+
{
24+
"name": "RUN_CCAAS",
25+
"fromHost": true
26+
},
27+
28+
{
29+
"name": "FABRIC_LOGGING_SPEC",
30+
"fromHost": true
31+
}
32+
]
33+
}

ecc_go/chaincode/enclave_go/shim.go

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ package enclave_go
1010
import (
1111
"fmt"
1212

13+
protoV1 "github.com/golang/protobuf/proto"
1314
"github.com/hyperledger/fabric-chaincode-go/shim"
1415
"github.com/hyperledger/fabric-private-chaincode/internal/utils"
16+
common "github.com/hyperledger/fabric-protos-go/common"
1517
pb "github.com/hyperledger/fabric-protos-go/peer"
18+
19+
"google.golang.org/protobuf/proto"
1620
timestamp "google.golang.org/protobuf/types/known/timestamppb"
1721
)
1822

@@ -250,21 +254,21 @@ func (f *FpcStubInterface) GetSignedProposal() (*pb.SignedProposal, error) {
250254
return f.stub.GetSignedProposal()
251255
}
252256

253-
// GetTxTimestamp documentation can be found in interfaces.go
254-
func (s *FpcStubInterface) GetTxTimestamp() (*timestamp.Timestamp, error) {
255-
// hdr := &common.Header{}
256-
// if err := proto.Unmarshal(s.proposal.Header, hdr); err != nil {
257-
// return nil, fmt.Errorf("error unmarshaling Header: %s", err)
258-
// }
259-
260-
// chdr := &common.ChannelHeader{}
261-
// if err := proto.Unmarshal(hdr.ChannelHeader, chdr); err != nil {
262-
// return nil, fmt.Errorf("error unmarshaling ChannelHeader: %s", err)
263-
// }
264-
// return chdr.GetTimestamp(), nil
265-
println(timestamp.Now())
266-
return timestamp.Now(), nil
257+
func (f *FpcStubInterface) GetTxTimestamp() (*timestamp.Timestamp, error) {
258+
hdr := &common.Header{}
259+
proposal, Proposalerr := f.GetSignedProposal()
260+
if Proposalerr != nil {
261+
return nil, fmt.Errorf("Error retrieving the proposal from the FPC Stub")
262+
}
263+
if err := proto.Unmarshal(proposal.ProposalBytes, protoV1.MessageV2(hdr)); err != nil {
264+
return nil, fmt.Errorf("error unmarshaling Header: %s", err)
265+
}
267266

267+
chdr := &common.ChannelHeader{}
268+
if err := proto.Unmarshal(hdr.ChannelHeader, protoV1.MessageV2(chdr)); err != nil {
269+
return nil, fmt.Errorf("error unmarshaling ChannelHeader: %s", err)
270+
}
271+
return chdr.GetTimestamp(), nil
268272
}
269273

270274
func (f *FpcStubInterface) SetEvent(name string, payload []byte) error {

ecc_go/enclave.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@
1616
"name": "CHAINCODE_PKG_ID",
1717
"fromHost": true
1818
},
19-
{
20-
"name": "FPC_ENABLED",
21-
"fromHost": true
22-
},
23-
{
24-
"name": "RUN_CCAAS",
25-
"fromHost": true
26-
},
2719
{
2820
"name": "FABRIC_LOGGING_SPEC",
2921
"fromHost": true

samples/application/ccapi/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ The transaction client invocation process, as illustrated in the diagram, consis
1717

1818
![CCAPIFlow](./CCAPIFlow.png)
1919

20-
2120
## User Experience
2221

23-
CCAPI is using docker and docker-compose for spinning up all the required components needed to work.
22+
CCAPI is using docker and docker-compose for spinning up all the required components needed to work.
2423

2524
Have a look at the [fpc-docker-compose.yaml](./fpc-docker-compose.yaml) to see how we use different env vars. Most of these environment variables are required by any client application to work and communicate with FPC. If you followed the [cc-tools-demo](../../chaincode/cc-tools-demo/README.md) tutorial, the values should be the same.
2625

27-
Start by running `docker-compose -f fpc-docker-compose.yaml up`
26+
Start by running `docker-compose -f fpc-docker-compose.yaml up` then go to the browser and type `localhost:80` to open the swagger api and start executing functions.
27+
28+
## Future work
29+
30+
CCAPI have another component for the dashboard frontend application but it's not yet utilized with

samples/chaincode/cc-tools-demo/README.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# CC-Tools-Demo Tutorial
22

3-
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.
3+
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.
44

5-
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.
5+
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.
66

7-
This tutorial is based on the [FPC with CC-Tools integration project]() and all our design choices are explained here in the [design document]().
7+
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).
88
Here are the steps to accomplish this:
99

10-
* Clone and copy the cc-tools-demo chaincode
10+
* Clone the cc-tools-demo chaincode
1111
* Modify the chaincode to use FPC
1212
* Build your FPC CC-tools-demo chaincode
1313
* Launch a Fabric network
@@ -16,26 +16,32 @@ Here are the steps to accomplish this:
1616

1717
## Prerequisites
1818

19-
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.
19+
* 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.
2020

21-
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).
21+
* 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).
2222
We recommend using the docker-based development environment and continue this tutorial within the dev container terminal.
2323

24-
Moreover, within your FPC development you have already installed the FPC Go Chaincode Support components.
24+
* Moreover, within your FPC development you have already installed the FPC Go Chaincode Support components.
2525
See the installation steps in [ecc_go/README.md](../../../ecc_go/README.md#installation).
2626

27-
We also assume that you are familiar with Fabric chaincode development in go.
27+
* We assume that you are familiar with Fabric chaincode development in go.
2828
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.
2929

30-
## Clone and copy the cc-tools-demo chaincode
30+
* 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
3131

32-
Clone the [cc-tools-demo]() repository and copy the [chaincode]() folder. Then paste it in the root directory for cc-tools-demo here.
32+
## Clone the cc-tools-demo chaincode
33+
34+
We need to clone the chaincode folder from the [cc-tools-demo](https://github.com/hyperledger-labs/cc-tools-demo) repository here.
3335

3436
```bash
35-
cd ~
36-
git clone https://github.com/hyperledger-labs/cc-tools-demo.git
37-
cp -a ~/cc-tools-demo/chaincode/. $FPC_PATH/samples/chaincode/cc-tools-demo/
38-
cd $FPC_PATH/samples/chaincode/cc-tools-demo
37+
export ccToolsDemoPath=$FPC_PATH/samples/chaincode/cc-tools-demo
38+
git clone -n --no-checkout --depth=1 --filter=tree:0 https://github.com/hyperledger-labs/cc-tools-demo.git "$ccToolsDemoPath/chaincode"
39+
cd "$ccToolsDemoPath/chaincode" || { echo "$ccToolsDemoPath/chaincode does not exist" ; exit 1; }
40+
git sparse-checkout set --no-cone chaincode/*
41+
git checkout
42+
mv chaincode/* $ccToolsDemoPath
43+
cd $ccToolsDemoPath
44+
sudo rm -r $ccToolsDemoPath/chaincode
3945
```
4046

4147
The chaincode code structure is different than normal chaincode as it's using the cc-tools framework.
@@ -115,15 +121,6 @@ func runCCaaS() error {
115121

116122
```
117123

118-
## Set the needed env vars in the docker-compose file
119-
120-
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
121-
```yaml
122-
- RUN_CCAAS=true
123-
- FPC_ENABLED=true
124-
```
125-
126-
127124
## Building FPC Go Chaincode
128125

129126
Create a `Makefile` (i.e., `touch $FPC_PATH/samples/chaincode/cc-tools-demo/Makefile`) with the following content:
@@ -133,30 +130,38 @@ TOP = ../../..
133130
include $(TOP)/ecc_go/build.mk
134131

135132
CC_NAME ?= fpc-cc-tools-demo
133+
134+
EGO_CONFIG_FILE ?= $(FPC_PATH)/ecc_go/ccToolsDemoEnclave.json
135+
136136
```
137137

138138
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.
139139

140140
**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`
141141

142-
143142
In `$FPC_PATH/samples/chaincode/cc-tools-demo` directory, to build the chaincode and package it as docker image, execute:
144143

145144
```bash
146145
make
147146
```
147+
148148
Note: this command runs inside the FPC dev environment and not your local host.
149149

150150
**Note**: If you faced this error:
151+
151152
```bash
152153
/project/pkg/mod/github.com/hyperledger-labs/cc-tools@v1.0.1/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)
153154
```
155+
154156
This is because there is a minor difference between the `ChaincodeStubInterface` used in the cc-tools `Mockstub` as it's missing the `PurgePrivateData` method.
155157
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.
158+
156159
```bash
157160
nano $FPC_PATH/vendor/github.com/hyperledger-labs/cc-tools/mock/mockstub.go
158161
```
162+
159163
add the following function
164+
160165
```go
161166
// PurgePrivateData ...
162167
func (stub *MockStub) PurgePrivateData(collection, key string) error {
@@ -203,7 +208,19 @@ cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network
203208
./network.sh createChannel -c mychannel
204209
```
205210

206-
Once the network is up and running, we install the simple asset chaincode and the FPC Enclave Registry.
211+
212+
### Set the needed env vars in the docker-compose file
213+
214+
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
215+
216+
```yaml
217+
- RUN_CCAAS=true
218+
- FPC_ENABLED=true
219+
```
220+
221+
### Install the chaincode
222+
223+
Once the network is up and running, we install the cc-tools-demo chaincode and the FPC Enclave Registry.
207224
We provide a small shell script to make this task a bit easier.
208225
209226
```bash
@@ -214,8 +231,6 @@ cd $FPC_PATH/samples/deployment/test-network
214231
./installFPC.sh
215232
```
216233

217-
Note that the `installFPC.sh` script returns an export statement you need to copy and paste in the terminal.
218-
This sets environment variables for the package IDs for each chaincode container.
219234
Continue by running:
220235

221236
```bash
@@ -224,7 +239,7 @@ make ercc-ecc-start
224239

225240
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`).
226241

227-
### Invoke simple asset
242+
### Invoke simple getSchema transaction
228243

229244
Open a new terminal and connect to the `fpc-development-go-support` container by running
230245

@@ -270,3 +285,9 @@ export RUN_CCAAS=true
270285
```
271286

272287
Congratulations! You have successfully created an FPC chaincode with go using cc-tools and invoked it using our simple cli.
288+
289+
Now you can test all your work again by running the [test](./testTutorial.sh) script
290+
291+
## Next Step
292+
293+
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/)

commands.sh renamed to samples/chaincode/cc-tools-demo/testTutorial.sh

File renamed without changes.

0 commit comments

Comments
 (0)