ccprovider

package
v1.0.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChaincodePackageExists

func ChaincodePackageExists(ccname string, ccversion string) (bool, error)

ChaincodePackageExists returns whether the chaincode package exists in the file system

func CheckInstantiationPolicy

func CheckInstantiationPolicy(name, version string, cdLedger *ChaincodeData) error

func EnableCCInfoCache

func EnableCCInfoCache()

EnableCCInfoCache can be called to enable the cache

func GetInstalledChaincodes

func GetInstalledChaincodes() (*pb.PtnChaincodeQueryResponse, error)

GetInstalledChaincodes returns a map whose key is the chaincode id and value is the ChaincodeDeploymentSpec struct for that chaincodes that have been installed (but not necessarily instantiated) on the peer by searching the chaincode install path

func NewCCInfoCache

func NewCCInfoCache(cs CCCacheSupport) *ccInfoCacheImpl

NewCCInfoCache returns a new cache on top of the supplied CCInfoProvider instance

func RegisterChaincodeProviderFactory

func RegisterChaincodeProviderFactory(ccfact ChaincodeProviderFactory)

RegisterChaincodeProviderFactory is to be called once to set the factory that will be used to obtain instances of ChaincodeProvider

Types

type CCCacheSupport

type CCCacheSupport interface {
	//GetChaincode is needed by the cache to get chaincode data
	GetChaincode(ccname string, ccversion string) (CCPackage, error)
}

type CCContext

type CCContext struct {
	//contract id
	ContractId []byte
	//ChainID chain id
	ChainID string

	//Name chaincode name
	Name string

	//Version used to construct the chaincode image and register
	Version string

	//TxID is the transaction id for the proposal (if any)
	TxID string

	//Syscc is this a system chaincode
	Syscc bool

	//SignedProposal for this invoke (if any)
	//this is kept here for access control and in case we need to pass something
	//from this to the chaincode
	SignedProposal *pb.PtnSignedProposal

	//Proposal for this invoke (if any)
	//this is kept here just in case we need to pass something
	//from this to the chaincode
	Proposal *pb.PtnProposal

	// this is additional data passed to the chaincode
	ProposalDecorations map[string][]byte
	// contains filtered or unexported fields
}

CCContext pass this around instead of string of args

func NewCCContext

func NewCCContext(contractid []byte, cid, name, version, txid string, syscc bool, signedProp *pb.PtnSignedProposal, prop *pb.PtnProposal) *CCContext

NewCCContext just construct a new struct with whatever args

func (*CCContext) GetCanonicalName

func (cccid *CCContext) GetCanonicalName() string

GetCanonicalName returns the canonical name associated with the proposal context

func (*CCContext) GetContainerName

func (cccid *CCContext) GetContainerName() string

type CCInfoFSImpl

type CCInfoFSImpl struct{}

CCInfoFSImpl provides the implementation for CC on the FS and the access to it It implements CCCacheSupport

func (*CCInfoFSImpl) GetChaincode

func (*CCInfoFSImpl) GetChaincode(ccname string, ccversion string) (CCPackage, error)

GetChaincodeFromFS this is a wrapper for hiding package implementation.

type CCPackage

type CCPackage interface {
	//InitFromBuffer initialize the package from bytes
	InitFromBuffer(buf []byte) (*ChaincodeData, error)

	// InitFromFS gets the chaincode from the filesystem (includes the raw bytes too)
	InitFromFS(ccname string, ccversion string) ([]byte, *pb.PtnChaincodeDeploymentSpec, error)

	// PutChaincodeToFS writes the chaincode to the filesystem
	PutChaincodeToFS() error

	// GetDepSpec gets the ChaincodeDeploymentSpec from the package
	GetDepSpec() *pb.PtnChaincodeDeploymentSpec

	// GetDepSpecBytes gets the serialized ChaincodeDeploymentSpec from the package
	GetDepSpecBytes() []byte

	// ValidateCC validates and returns the chaincode deployment spec corresponding to
	// ChaincodeData. The validation is based on the metadata from ChaincodeData
	// One use of this method is to validate the chaincode before launching
	ValidateCC(ccdata *ChaincodeData) error

	// GetPackageObject gets the object as a proto.Message
	GetPackageObject() proto.Message

	// GetChaincodeData gets the ChaincodeData
	GetChaincodeData() *ChaincodeData

	// GetId gets the fingerprint of the chaincode based on package computation
	GetId() []byte
}

CCPackage encapsulates a chaincode package which can be

raw ChaincodeDeploymentSpec
SignedChaincodeDeploymentSpec

Attempt to keep the interface at a level with minimal interface for possible generalization.

func GetCCPackage

func GetCCPackage(buf []byte) (CCPackage, error)

GetCCPackage tries each known package implementation one by one till the right package is found

func GetChaincodeFromFS

func GetChaincodeFromFS(ccname string, ccversion string) (CCPackage, error)

GetChaincodeFromFS retrieves chaincode information from the file system

type ChaincodeData

type ChaincodeData struct {
	//Name of the chaincode
	Name string `protobuf:"bytes,1,opt,name=name"`

	//Version of the chaincode
	Version string `protobuf:"bytes,2,opt,name=version"`

	//Escc for the chaincode instance
	Escc string `protobuf:"bytes,3,opt,name=escc"`

	//Vscc for the chaincode instance
	Vscc string `protobuf:"bytes,4,opt,name=vscc"`

	//Policy endorsement policy for the chaincode instance
	Policy []byte `protobuf:"bytes,5,opt,name=policy,proto3"`

	//Data data specific to the package
	Data []byte `protobuf:"bytes,6,opt,name=data,proto3"`

	//Id of the chaincode that's the unique fingerprint for the CC
	//This is not currently used anywhere but serves as a good
	//eyecatcher
	Id []byte `protobuf:"bytes,7,opt,name=id,proto3"`

	//InstantiationPolicy for the chaincode
	InstantiationPolicy []byte `protobuf:"bytes,8,opt,name=instantiation_policy,proto3"`
}

ChaincodeData defines the datastructure for chaincodes to be serialized by proto Type provides an additional check by directing to use a specific package after instantiation Data is Type specifc (see CDSPackage and SignedCDSPackage)

func GetChaincodeData

func GetChaincodeData(ccname string, ccversion string) (*ChaincodeData, error)

GetChaincodeData gets chaincode data from cache if there's one

func (*ChaincodeData) CCName

func (cd *ChaincodeData) CCName() string

CCName returns the name of this chaincode (the name it was put in the ChaincodeRegistry with).

func (*ChaincodeData) CCVersion

func (cd *ChaincodeData) CCVersion() string

CCVersion returns the version of the chaincode.

func (*ChaincodeData) Endorsement

func (cd *ChaincodeData) Endorsement() string

Endorsement returns how to endorse proposals for this chaincode. The string returns is the name of the endorsement method (usually 'escc').

func (*ChaincodeData) Hash

func (cd *ChaincodeData) Hash() []byte

Hash returns the hash of the chaincode.

func (*ChaincodeData) ProtoMessage

func (*ChaincodeData) ProtoMessage()

ProtoMessage just exists to make proto happy

func (*ChaincodeData) Reset

func (cd *ChaincodeData) Reset()

Reset resets

func (*ChaincodeData) String

func (cd *ChaincodeData) String() string

String converts to string

func (*ChaincodeData) Validation

func (cd *ChaincodeData) Validation() (string, []byte)

Validation returns how to validate transactions for this chaincode. The string returned is the name of the validation method (usually 'vscc') and the bytes returned are the argument to the validation (in the case of 'vscc', this is a marshaled pb.VSCCArgs message).

type ChaincodeProvider

type ChaincodeProvider interface {
	// GetContext returns a ledger context and a tx simulator; it's the
	// caller's responsibility to release the simulator by calling its
	// done method once it is no longer useful
	//glh
	//GetContext(ledger ledger.PeerLedger, txid string) (context.Context, ledger.TxSimulator, error)
	GetContext() (context.Context, error)
	// GetCCContext returns an opaque chaincode context
	GetCCContext(contractid []byte, cid, name, version, txid string, syscc bool, signedProp *pb.PtnSignedProposal, prop *pb.PtnProposal) interface{}
	// ExecuteChaincode executes the chaincode given context and args
	ExecuteChaincode(ctxt context.Context, cccid interface{}, args [][]byte, timeout time.Duration) (*pb.PtnResponse, *pb.PtnChaincodeEvent, error)
	// Execute executes the chaincode given context and spec (invocation or deploy)
	Execute(ctxt context.Context, cccid interface{}, spec interface{}, timeout time.Duration) (*pb.PtnResponse, *pb.PtnChaincodeEvent, error)
	// ExecuteWithErrorFilter executes the chaincode given context and spec and returns payload
	ExecuteWithErrorFilter(ctxt context.Context, cccid interface{}, spec interface{}, timeout time.Duration) ([]byte, *pb.PtnChaincodeEvent, error)
	// Stop stops the chaincode given context and deployment spec
	Stop(ctxt context.Context, cccid interface{}, spec *pb.PtnChaincodeDeploymentSpec, dontRmCon bool) error

	Destroy(ctxt context.Context, cccid interface{}, spec *pb.PtnChaincodeDeploymentSpec) error
}

ChaincodeProvider provides an abstraction layer that is used for different packages to interact with code in the chaincode package without importing it; more methods should be added below if necessary

func GetChaincodeProvider

func GetChaincodeProvider() ChaincodeProvider

GetChaincodeProvider returns instances of ChaincodeProvider; the actual implementation is controlled by the factory that is registered via RegisterChaincodeProviderFactory

type ChaincodeProviderFactory

type ChaincodeProviderFactory interface {
	NewChaincodeProvider() ChaincodeProvider
}

ChaincodeProviderFactory defines a factory interface so that the actual implementation can be injected

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL