Skip to content

Commit

Permalink
Add echo-go sample
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Brandenburger <bur@zurich.ibm.com>
  • Loading branch information
mbrandenburger committed Dec 6, 2023
1 parent 9d7f161 commit 5edd740
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
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)
}
}

0 comments on commit 5edd740

Please sign in to comment.