github.com/ewagmig/fabric@v2.1.1+incompatible/core/chaincode/testdata/src/chaincodes/init_private_data/init_private_data.go (about)

     1  /*
     2  Copyright IBM Corp. All Rights Reserved.
     3  
     4  SPDX-License-Identifier: Apache-2.0
     5  */
     6  
     7  package main
     8  
     9  import (
    10  	"fmt"
    11  
    12  	"github.com/hyperledger/fabric-chaincode-go/shim"
    13  	pb "github.com/hyperledger/fabric-protos-go/peer"
    14  )
    15  
    16  // SimpleChaincode example simple Chaincode implementation
    17  type SimpleChaincode struct {
    18  }
    19  
    20  // Init initializes a private state
    21  func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
    22  	if err := stub.PutPrivateData("dummyColl", "dummyKey", []byte("dummyValue")); err != nil {
    23  		return shim.Error(fmt.Sprintf("put operation failed. Error storing state: %s", err))
    24  	}
    25  	return shim.Success(nil)
    26  }
    27  
    28  // Invoke is a no-op
    29  func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
    30  	return shim.Success(nil)
    31  }
    32  
    33  func main() {
    34  	err := shim.Start(new(SimpleChaincode))
    35  	if err != nil {
    36  		fmt.Printf("Error starting chaincode: %s", err)
    37  	}
    38  }