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

Add echo-go sample #747

Merged
merged 1 commit into from
Dec 13, 2023
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
2 changes: 1 addition & 1 deletion samples/chaincode/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
TOP = ../..
include $(TOP)/build.mk

SUB_DIRS = auction auction-go echo kv-test kv-test-go
SUB_DIRS = auction auction-go echo echo-go kv-test kv-test-go

all build test clean clobber:
$(foreach DIR, $(SUB_DIRS), $(MAKE) -C $(DIR) $@ || exit ;)
7 changes: 7 additions & 0 deletions samples/chaincode/echo-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ecc
ecc-bundle
enclave.json
private.pem
public.pem
mrenclave
details.env
9 changes: 9 additions & 0 deletions samples/chaincode/echo-go/Makefile
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions samples/chaincode/echo-go/chaincode/echo.go
Original file line number Diff line number Diff line change
@@ -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))
}
43 changes: 43 additions & 0 deletions samples/chaincode/echo-go/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}