github.com/hechain20/hechain@v0.0.0-20220316014945-b544036ba106/integration/lifecycle/chaincode/callee/chaincode.go (about)

     1  /*
     2  Copyright hechain. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package callee
     8  
     9  import (
    10  	"github.com/hyperledger/fabric-chaincode-go/shim"
    11  	pb "github.com/hyperledger/fabric-protos-go/peer"
    12  )
    13  
    14  // CC example simple Chaincode implementation
    15  type CC struct{}
    16  
    17  func (t *CC) Init(stub shim.ChaincodeStubInterface) pb.Response {
    18  	err := stub.PutState("foo", []byte("callee:foo"))
    19  	if err != nil {
    20  		return shim.Error(err.Error())
    21  	}
    22  
    23  	return shim.Success(nil)
    24  }
    25  
    26  func (t *CC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
    27  	fn, _ := stub.GetFunctionAndParameters()
    28  	switch fn {
    29  	case "INVOKE":
    30  		err := stub.PutState("foo", []byte("callee:bar"))
    31  		if err != nil {
    32  			return shim.Error(err.Error())
    33  		}
    34  
    35  		return shim.Success(nil)
    36  	case "QUERY":
    37  		val, err := stub.GetState("foo")
    38  		if err != nil {
    39  			return shim.Error(err.Error())
    40  		}
    41  
    42  		return shim.Success(val)
    43  	default:
    44  		return shim.Error("unknown function")
    45  	}
    46  }