package main

import (
	"fmt"
	"github.com/hyperledger/fabric/core/chaincode/shim"
	pb "github.com/hyperledger/fabric/protos/peer"
)



type TestCC struct {
}


func (ret *TestCC) Init(stub shim.ChaincodeStubInterface) pb.Response {
	return shim.Success([]byte("retrospect chain init success"))
}

// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
func (ret *TestCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
	functionName, args := stub.GetFunctionAndParameters()
	switch functionName {
	case "testCheck": //测试接口
		return TestCheck(args, stub)
	default:
		return shim.Error(fmt.Sprintf("%s Unsupported function name ", functionName))
	}
	return pb.Response{}
}

func TestCheck(args []string, stub shim.ChaincodeStubInterface) pb.Response {
	if len(args) == 0 {
		return shim.Success([]byte("参数内容为空"))
	}
	return shim.Success([]byte(args[0]))
}



func main() {
	err := shim.Start(&TestCC{})
	if err != nil {
		fmt.Printf("Error starting medical chaincode: %s", err)
	}
}
