const ( //InstalledChaincodeFuncName is the chaincode function name used to install a chaincode InstallChaincodeFuncName = "InstallChaincode" // QueryInstalledChaincodeFuncName is the chaincode function name used to query an installed chaincode QueryInstalledChaincodeFuncName = "QueryInstalledChaincode" )
ChaincodeStore provides a way to persist chaincodes
type ChaincodeStore interface { Save(name, version string, ccInstallPkg []byte) (hash []byte, err error) RetrieveHash(name, version string) (hash []byte, err error) }
Lifecycle implements the lifecycle operations which are invoked by the SCC as well as internally
type Lifecycle struct { ChaincodeStore ChaincodeStore PackageParser PackageParser }
func (l *Lifecycle) InstallChaincode(name, version string, chaincodeInstallPackage []byte) ([]byte, error)
InstallChaincode installs a given chaincode to the peer's chaincode store. It returns the hash to reference the chaincode by or an error on failure.
func (l *Lifecycle) QueryInstalledChaincode(name, version string) ([]byte, error)
QueryInstalledChaincode returns the hash of an installed chaincode of a given name and version.
type PackageParser interface { Parse(data []byte) (*persistence.ChaincodePackage, error) }
Protobuf defines the subset of protobuf lifecycle needs and allows for injection of mocked marshaling errors.
type Protobuf interface { Marshal(msg proto.Message) (marshaled []byte, err error) Unmarshal(marshaled []byte, msg proto.Message) error }
ProtobufImpl is the standard implementation to use for Protobuf
type ProtobufImpl struct{}
func (p ProtobufImpl) Marshal(msg proto.Message) ([]byte, error)
Marshal passes through to proto.Marshal
func (p ProtobufImpl) Unmarshal(marshaled []byte, msg proto.Message) error
Unmarshal passes through to proto.Unmarshal
SCC implements the required methods to satisfy the chaincode interface. It routes the invocation calls to the backing implementations.
type SCC struct { Protobuf Protobuf Functions SCCFunctions }
func (scc *SCC) Chaincode() shim.Chaincode
Chaincode returns a reference to itself
func (scc *SCC) Enabled() bool
Enabled returns true
func (scc *SCC) Init(stub shim.ChaincodeStubInterface) pb.Response
Init is mostly useless for system chaincodes and always returns success
func (scc *SCC) InitArgs() [][]byte
InitArgs returns nil
func (scc *SCC) InvokableCC2CC() bool
InvokableCC2CC returns true
func (scc *SCC) InvokableExternal() bool
InvokableExternal returns true
func (scc *SCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
Invoke takes chaincode invocation arguments and routes them to the correct underlying lifecycle operation. All functions take a single argument of type marshaled lb.<FunctionName>Args and return a marshaled lb.<FunctionName>Result
func (scc *SCC) Name() string
Name returns "+lifecycle"
func (scc *SCC) Path() string
Path returns "github.com/hyperledger/fabric/core/chaincode/lifecycle"
SCCFunctions provides a backing implementation with concrete arguments for each of the SCC functions
type SCCFunctions interface { // InstallChaincode persists a chaincode definition to disk InstallChaincode(name, version string, chaincodePackage []byte) (hash []byte, err error) // QueryInstalledChaincode returns the hash for a given name and version of an installed chaincode QueryInstalledChaincode(name, version string) (hash []byte, err error) }