diff --git a/samples/chaincode/echo-go/.gitignore b/samples/chaincode/echo-go/.gitignore new file mode 100644 index 000000000..e8df032d2 --- /dev/null +++ b/samples/chaincode/echo-go/.gitignore @@ -0,0 +1,7 @@ +ecc +ecc-bundle +enclave.json +private.pem +public.pem +mrenclave +details.env diff --git a/samples/chaincode/echo-go/Makefile b/samples/chaincode/echo-go/Makefile new file mode 100644 index 000000000..d197721ab --- /dev/null +++ b/samples/chaincode/echo-go/Makefile @@ -0,0 +1,9 @@ +# Copyright 2019 Intel Corporation +# Copyright IBM Corp. All Rights Reserved. +# +# SPDX-License-Identifier: Apache-2.0 + +TOP = ../../.. +include $(TOP)/ecc_go/build.mk + +CC_NAME ?= fpc-echo-go diff --git a/samples/chaincode/echo-go/chaincode/echo.go b/samples/chaincode/echo-go/chaincode/echo.go new file mode 100644 index 000000000..f6f826dac --- /dev/null +++ b/samples/chaincode/echo-go/chaincode/echo.go @@ -0,0 +1,27 @@ +/* +Copyright IBM Corp. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package chaincode + +import ( + "fmt" + + "github.com/hyperledger/fabric-chaincode-go/shim" + pb "github.com/hyperledger/fabric-protos-go/peer" +) + +type Echo struct { +} + +func (t *Echo) Init(stub shim.ChaincodeStubInterface) pb.Response { + return shim.Success(nil) +} + +func (t *Echo) Invoke(stub shim.ChaincodeStubInterface) pb.Response { + functionName, params := stub.GetFunctionAndParameters() + fmt.Println("EchoCC: Function:", functionName, "Params:", params) + return shim.Success([]byte(functionName)) +} diff --git a/samples/chaincode/echo-go/main.go b/samples/chaincode/echo-go/main.go new file mode 100644 index 000000000..1146f64e9 --- /dev/null +++ b/samples/chaincode/echo-go/main.go @@ -0,0 +1,43 @@ +/* +Copyright IBM Corp. All Rights Reserved. +Copyright 2020 Intel Corporation + +SPDX-License-Identifier: Apache-2.0 +*/ + +package main + +import ( + "os" + + "github.com/hyperledger/fabric-chaincode-go/shim" + fpc "github.com/hyperledger/fabric-private-chaincode/ecc_go/chaincode" + "github.com/hyperledger/fabric-private-chaincode/samples/chaincode/echo-go/chaincode" +) + +func main() { + + // we can control logging via FABRIC_LOGGING_SPEC, the default is FABRIC_LOGGING_SPEC=INFO + // For more fine-grained logging we could also use different log level for loggers. + // For example: FABRIC_LOGGING_SPEC=ecc=DEBUG:ecc_enclave=ERROR + + ccid := os.Getenv("CHAINCODE_PKG_ID") + addr := os.Getenv("CHAINCODE_SERVER_ADDRESS") + + // create private chaincode + privateChaincode := fpc.NewPrivateChaincode(&chaincode.Echo{}) + + // start chaincode as a service + server := &shim.ChaincodeServer{ + CCID: ccid, + Address: addr, + CC: privateChaincode, + TLSProps: shim.TLSProperties{ + Disabled: true, // just for testing good enough + }, + } + + if err := server.Start(); err != nil { + panic(err) + } +}