Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/integrate with cc tools #779

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
9994daa
feat: integrate with cc-tools-demo
osamamagdy Aug 14, 2024
c6b9259
fix: resolve conflict
osamamagdy Aug 14, 2024
5bf43ed
fix: export FPC and CCAAS envs
osamamagdy Aug 14, 2024
f369725
feat: ccapi is working
osamamagdy Sep 8, 2024
1f860dc
add uodate external connection script
osamamagdy Sep 15, 2024
a13460d
handle corner cases
osamamagdy Sep 15, 2024
8892936
edit script
osamamagdy Sep 15, 2024
c395ce2
add cc-tools-demo tutorial
osamamagdy Sep 27, 2024
2838217
add readme for the cc-tools-demo tutorial
osamamagdy Sep 27, 2024
237a3b1
rename ccapi and FPC_MODE
osamamagdy Sep 27, 2024
9bf539a
fixing documentation
osamamagdy Oct 2, 2024
db0cb7f
edit
osamamagdy Oct 2, 2024
a064eb0
fix: fix go.mod
osamamagdy Oct 11, 2024
5ed35d4
fix: upgrade fabric-sdk-go
osamamagdy Oct 11, 2024
8250fbf
fix: resolve comments
osamamagdy Oct 15, 2024
1ec09a9
revert go.mod and go.sum changes
osamamagdy Oct 15, 2024
ed720cd
fix: revert changes of the protos
osamamagdy Oct 15, 2024
171ea9c
fix: add the right ccapi
osamamagdy Oct 18, 2024
57a9ff3
fix: return Error for not implemented functions
osamamagdy Oct 18, 2024
c710be0
docs: add tutorial for ccapi
osamamagdy Oct 18, 2024
ae668f1
comments resolved
osamamagdy Oct 21, 2024
1ae8062
Merge branch 'main' into feature/integrate-with-cc-tools
osamamagdy Oct 22, 2024
934b941
move ccapi to another PR
osamamagdy Oct 22, 2024
e027bcf
fix: edit error message
osamamagdy Oct 22, 2024
3c62109
fix: ignore the linter for protobuf
osamamagdy Oct 25, 2024
cdbf3d8
feat: edit readme
osamamagdy Nov 1, 2024
6d8ac47
Merge branch 'feature/integrate-with-cc-tools' of https://github.com/…
osamamagdy Nov 1, 2024
5f5eaa9
fix: update makefile variable setting
osamamagdy Nov 5, 2024
60efa3a
docs: add note about org names
osamamagdy Nov 6, 2024
63fe3dd
Merge branch 'main' into feature/integrate-with-cc-tools
osamamagdy Nov 6, 2024
8bd3cfd
docs: edit readme
osamamagdy Nov 6, 2024
31d982d
fix: rename enclave.json
osamamagdy Nov 8, 2024
ae77fce
fix: edit readme
osamamagdy Nov 8, 2024
9c485b8
fix: remove unwanted step
osamamagdy Nov 14, 2024
99ab55e
docs: edit note
osamamagdy Nov 22, 2024
1085cd2
chore: change ccToolsDemoEnclave.json path
osamamagdy Nov 22, 2024
42f1fef
feat: pass file paths to Makefile from terminal
osamamagdy Nov 22, 2024
c3150b6
fix: edit readme notes
osamamagdy Nov 25, 2024
e11d630
feat: relocate extra compose file
osamamagdy Nov 26, 2024
06e1453
fix: sudo commands
osamamagdy Nov 29, 2024
62409a0
Update samples/chaincode/cc-tools-demo/README.md
osamamagdy Nov 29, 2024
d16dc4b
Update samples/chaincode/cc-tools-demo/README.md
osamamagdy Nov 29, 2024
2e80ab2
fix: fix typo
osamamagdy Nov 29, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cscope.*
common/protos
internal/protos
coverage.out
vendor
97 changes: 97 additions & 0 deletions commands.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# ############################## Commands in order #######################################
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved


# ################################### For CC-tools inside the fpc

# - Copy all chaincode files using the same way as simple-asset-go
# - replace the "CHAINCODE_ID" env with "CHAINCODE_PKG_ID" in main.go
# - Run `go get` inside the cc-tools-demo folder after putting it inside the fpc repo
# ------ There are huge problem with using FPC outside the FPC repository. Even go get doesn't work and you need to specify a certain version and there are conflicting packages-----------------'
# # - You have to add dummy implementation for the PurgePrivate data method in the MockStup of cc-tools but be careful you need to do it in the package installed inside the FPC dev env not your local
# # For example do: vim /project/pkg/mod/github.com/hyperledger-labs/[email protected]/mock/mockstub.go and add this:
# # // PurgePrivateData ...
# # func (stub *MockStub) PurgePrivateData(collection, key string) error {
# # return errors.New("Not Implemented")
# # }.
# # A good idea is to use go mod vendor and download all go packages in the vendor directory and edit it one time there.
# # nano $FPC_PATH/vendor/github.com/hyperledger-labs/cc-tools/mock/mockstub.go
# # // PurgePrivateData ...
# # func (stub *MockStub) PurgePrivateData(collection, key string) error {
# # return errors.New("Not Implemented")
# # }

cd $FPC_PATH/samples/deployment/test-network
docker compose down

cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network
./network.sh down
docker system prune
sleep 5

cd $FPC_PATH/samples/chaincode/cc-tools-demo/
export CC_NAME=fpc-cc-tools-demo
make

# - run docker images | grep fpc-cc-tools-demo to make sure of the image
# - complete the tutorial normally:
cd $FPC_PATH/samples/deployment/test-network
./setup.sh

cd $FPC_PATH/samples/deployment/test-network/fabric-samples/test-network
./network.sh up createChannel -ca -c mychannel
sleep 5

export CC_ID=cc-tools-demo
export CC_PATH="$FPC_PATH/samples/chaincode/cc-tools-demo/"
export CC_VER=$(cat "$FPC_PATH/samples/chaincode/cc-tools-demo/mrenclave")

cd $FPC_PATH/samples/deployment/test-network
./installFPC.sh
sleep 5
make ercc-ecc-start
sleep 5

# # prepare connections profile
cd $FPC_PATH/samples/deployment/test-network
./update-connection.sh

# # update the connection profile for external clients outside the fpc dev environment
cd $FPC_PATH/samples/deployment/test-network
./update-external-connection.sh

# make fpcclient
cd $FPC_PATH/samples/application/simple-cli-go
make

# export fpcclient settings
export CC_NAME=cc-tools-demo
export CHANNEL_NAME=mychannel
export CORE_PEER_ADDRESS=localhost:7051
export CORE_PEER_ID=peer0.org1.example.com
export CORE_PEER_LOCALMSPID=Org1MSP
export CORE_PEER_MSPCONFIGPATH=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_TLS_CERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.crt
export CORE_PEER_TLS_ENABLED="true"
export CORE_PEER_TLS_KEY_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/server.key
export CORE_PEER_TLS_ROOTCERT_FILE=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export ORDERER_CA=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export GATEWAY_CONFIG=$FPC_PATH/samples/deployment/test-network/fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.yaml

sleep 5
# init our enclave
./fpcclient init $CORE_PEER_ID
sleep 5
# invoke the getSchema transaction which is implemented internally by cc-tools
./fpcclient invoke getSchema

########################## Some transactions to test ####################################
# sleep 5
# ./fpcclient invoke createNewLibrary "{\"name\":\"samuel\"}"
# sleep 5
# ./fpcclient invoke createAsset "{\"asset\":[{\"@assetType\":\"person\",\"id\":\"51027337023\",\"name\":\"samuel\"}]}"
# sleep 5
# ./fpcclient invoke createAsset "{\"asset\":[{\"@assetType\":\"book\", \"title\": \"Fairy tail\" ,\"author\":\"Martin\",\"currentTenant\":{\"@assetType\": \"person\", \"@key\": \"person:f6c10e69-32ae-5dfb-b17e-9eda4a039cee\"}}]}"
# sleep 5
# ./fpcclient invoke getBooksByAuthor "{\"authorName\":\"samuel\"}" # --> Fails as GetQueryResult is not implemented. I tried to implement it but the fabric implementation needs what's called handler and it's not ther


35 changes: 30 additions & 5 deletions ecc_go/chaincode/enclave_go/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ SPDX-License-Identifier: Apache-2.0
package enclave_go

import (
"fmt"

"github.com/hyperledger/fabric-chaincode-go/shim"
"github.com/hyperledger/fabric-private-chaincode/internal/utils"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/pkg/errors"
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
timestamp "google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -177,7 +180,11 @@ func (f *FpcStubInterface) SplitCompositeKey(compositeKey string) (string, []str
}

func (f *FpcStubInterface) GetQueryResult(query string) (shim.StateQueryIteratorInterface, error) {
panic("not implemented") // TODO: Implement
it, err := f.stub.GetQueryResult(query)
if err != nil {
return it, errors.Wrap(err, "stub.GetQueryResult call error")
}
return it, nil
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
}

func (f *FpcStubInterface) GetQueryResultWithPagination(query string, pageSize int32, bookmark string) (shim.StateQueryIteratorInterface, *pb.QueryResponseMetadata, error) {
Expand Down Expand Up @@ -233,7 +240,7 @@ func (f *FpcStubInterface) GetCreator() ([]byte, error) {
}

func (f *FpcStubInterface) GetTransient() (map[string][]byte, error) {
panic("not implemented") // TODO: Implement
return nil, nil
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
}

func (f *FpcStubInterface) GetBinding() ([]byte, error) {
Expand All @@ -248,10 +255,28 @@ func (f *FpcStubInterface) GetSignedProposal() (*pb.SignedProposal, error) {
return f.stub.GetSignedProposal()
}

func (f *FpcStubInterface) GetTxTimestamp() (*timestamp.Timestamp, error) {
panic("not implemented") // TODO: Implement
// GetTxTimestamp documentation can be found in interfaces.go
func (s *FpcStubInterface) GetTxTimestamp() (*timestamp.Timestamp, error) {
// hdr := &common.Header{}
// if err := proto.Unmarshal(s.proposal.Header, hdr); err != nil {
// return nil, fmt.Errorf("error unmarshaling Header: %s", err)
// }

// chdr := &common.ChannelHeader{}
// if err := proto.Unmarshal(hdr.ChannelHeader, chdr); err != nil {
// return nil, fmt.Errorf("error unmarshaling ChannelHeader: %s", err)
// }
// return chdr.GetTimestamp(), nil
println(timestamp.Now())
return timestamp.Now(), nil
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved

}

func (f *FpcStubInterface) SetEvent(name string, payload []byte) error {
panic("not implemented") // TODO: Implement
if name == "" {
return errors.New("event name can not be empty string")
}
fmt.Println("Trying to set event name: ", name, "\n with payload: ", payload)
fmt.Println("NO event is bieng set as function is not implemented yet")
return nil
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
}
8 changes: 8 additions & 0 deletions ecc_go/enclave.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
"name": "CHAINCODE_PKG_ID",
"fromHost": true
},
{
"name": "FPC_ENABLED",
"fromHost": true
},
{
"name": "RUN_CCAAS",
"fromHost": true
},
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
{
"name": "FABRIC_LOGGING_SPEC",
"fromHost": true
Expand Down
31 changes: 9 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,34 @@ replace google.golang.org/grpc => google.golang.org/grpc v1.29.1
require (
github.com/client9/misspell v0.3.4
github.com/golang/protobuf v1.5.3
github.com/hyperledger/fabric v1.4.0-rc1.0.20230405174026-695dd57e01c2
github.com/hyperledger/fabric v2.1.1+incompatible
github.com/hyperledger/fabric-chaincode-go v0.0.0-20230228194215-b84622ba6a7a
github.com/hyperledger/fabric-contract-api-go v1.2.1
github.com/hyperledger/fabric-protos-go v0.3.0
github.com/hyperledger/fabric-samples/asset-transfer-basic/chaincode-go v0.0.0-20230505123407-84f9ba1dc4ec
github.com/hyperledger/fabric-sdk-go v1.0.1-0.20240123083657-5d6ca326e01b
github.com/maxbrunsfeld/counterfeiter/v6 v6.6.1
github.com/onsi/ginkgo v1.16.5
github.com/onsi/ginkgo/v2 v2.11.0
github.com/onsi/gomega v1.27.8
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.5.0
golang.org/x/tools v0.14.0
google.golang.org/protobuf v1.33.0
google.golang.org/protobuf v1.34.1
osamamagdy marked this conversation as resolved.
Show resolved Hide resolved
gopkg.in/yaml.v2 v2.4.0
honnef.co/go/tools v0.4.3
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/IBM/idemix v0.0.2-0.20231107110441-534ea4193b8f // indirect
github.com/IBM/idemix/bccsp/schemes/aries v0.0.0-20231107110234-4cf31dd43660 // indirect
github.com/IBM/idemix/bccsp/schemes/weak-bb v0.0.0-20231107110234-4cf31dd43660 // indirect
github.com/IBM/idemix/bccsp/types v0.0.0-20231107110234-4cf31dd43660 // indirect
github.com/IBM/mathlib v0.0.3-0.20231011094432-44ee0eb539da // indirect
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ale-linux/aries-framework-go/component/kmscrypto v0.0.0-20231023164747-f3f972769504 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/cfssl v1.4.1 // indirect
github.com/consensys/bavard v0.1.13 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/containerd/containerd v1.7.13 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand Down Expand Up @@ -93,14 +83,12 @@ require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kilic/bls12-381 v0.1.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/miekg/pkcs11 v1.1.1 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
Expand Down Expand Up @@ -133,17 +121,16 @@ require (
github.com/zmap/zlint v0.0.0-20190806154020-fd021b4cfbeb // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20221208152030-732eee02a75a // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.59.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/grpc v1.63.2 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)
Loading
Loading