github.com/sykesm/fabric@v1.1.0-preview.0.20200129034918-2aa12b1a0181/integration/lifecycle/chaincode/callee/chaincode.go (about)

     1  /*
     2  Copyright IBM Corp. 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  
    18  func (t *CC) Init(stub shim.ChaincodeStubInterface) pb.Response {
    19  	err := stub.PutState("foo", []byte("callee:foo"))
    20  	if err != nil {
    21  		return shim.Error(err.Error())
    22  	}
    23  
    24  	return shim.Success(nil)
    25  }
    26  
    27  func (t *CC) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
    28  	fn, _ := stub.GetFunctionAndParameters()
    29  	switch fn {
    30  	case "INVOKE":
    31  		err := stub.PutState("foo", []byte("callee:bar"))
    32  		if err != nil {
    33  			return shim.Error(err.Error())
    34  		}
    35  
    36  		return shim.Success(nil)
    37  	case "QUERY":
    38  		val, err := stub.GetState("foo")
    39  		if err != nil {
    40  			return shim.Error(err.Error())
    41  		}
    42  
    43  		return shim.Success(val)
    44  	default:
    45  		return shim.Error("unknown function")
    46  	}
    47  }