lifecycle

package
v2.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2019 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NamespacesName is the prefix (or namespace) of the DB which will be used to store
	// the information about other namespaces (for things like chaincodes) in the DB.
	// We want a sub-namespaces within lifecycle in case other information needs to be stored here
	// in the future.
	NamespacesName = "namespaces"

	// ChaincodeSourcesName is the namespace reserved for storing the information about where
	// to find the chaincode (such as as a package on the local filesystem, or in the future,
	// at some network resource).  This namespace is only populated in the org implicit collection.
	ChaincodeSourcesName = "chaincode-sources"

	// ChaincodeDefinitionType is the name of the type used to store defined chaincodes
	ChaincodeDefinitionType = "ChaincodeDefinition"

	// FriendlyChaincodeDefinitionType is the name exposed to the outside world for the chaincode namespace
	FriendlyChaincodeDefinitionType = "Chaincode"

	// DefaultEndorsementPolicyRef is the name of the default endorsement policy for this channel
	DefaultEndorsementPolicyRef = "/Channel/Application/Endorsement"
)
View Source
const (
	// LifecycleNamespace is the namespace in the statedb where lifecycle
	// information is stored
	LifecycleNamespace = "_lifecycle"

	// InstallChaincodeFuncName 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"

	// QueryInstalledChaincodesFuncName is the chaincode function name used to
	// query all installed chaincodes
	QueryInstalledChaincodesFuncName = "QueryInstalledChaincodes"

	// ApproveChaincodeDefinitionForMyOrgFuncName is the chaincode function name
	// used to approve a chaincode definition for execution by the user's own org
	ApproveChaincodeDefinitionForMyOrgFuncName = "ApproveChaincodeDefinitionForMyOrg"

	// QueryApprovalStatusFuncName is the chaincode function name used to query
	// the approval status for a given definition over a given set of orgs
	QueryApprovalStatusFuncName = "QueryApprovalStatus"

	// CommitChaincodeDefinitionFuncName is the chaincode function name used to
	// 'commit' (previously 'instantiate') a chaincode in a channel.
	CommitChaincodeDefinitionFuncName = "CommitChaincodeDefinition"

	// QueryChaincodeDefinitionFuncName is the chaincode function name used to
	// query the committed chaincode definitions in a channel.
	QueryChaincodeDefinitionFuncName = "QueryChaincodeDefinition"

	// QueryNamespaceDefinitionsFuncName is the chaincode function name used
	// to query which namespaces are currently defined and what type those
	// namespaces are.
	QueryNamespaceDefinitionsFuncName = "QueryNamespaceDefinitions"
)
View Source
const (
	MetadataInfix = "metadata"
	FieldsInfix   = "fields"
)
View Source
const (
	LifecycleEndorsementPolicyRef = "/Channel/Application/LifecycleEndorsement"
)

Variables

View Source
var (
	DefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&pb.ApplicationPolicy{
		Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
			ChannelConfigPolicyReference: DefaultEndorsementPolicyRef,
		},
	})
)
View Source
var ImplicitCollectionMatcher = regexp.MustCompile("^" + ImplicitCollectionNameForOrg("(.+)") + "$")
View Source
var (
	// This is a channel which was created with a lifecycle endorsement policy
	LifecycleDefaultEndorsementPolicyBytes = protoutil.MarshalOrPanic(&pb.ApplicationPolicy{
		Type: &pb.ApplicationPolicy_ChannelConfigPolicyReference{
			ChannelConfigPolicyReference: LifecycleEndorsementPolicyRef,
		},
	})
)
View Source
var ProtoMessageType = reflect.TypeOf((*proto.Message)(nil)).Elem()
View Source
var SequenceMatcher = regexp.MustCompile("^" + NamespacesName + "/fields/([^/]+)/Sequence$")

Functions

func FieldKey

func FieldKey(namespace, name, field string) string

func GenerateImplicitCollectionForOrg

func GenerateImplicitCollectionForOrg(mspid string) *cb.StaticCollectionConfig

func ImplicitCollectionNameForOrg

func ImplicitCollectionNameForOrg(mspid string) string

func MetadataKey

func MetadataKey(namespace, name string) string

func StateIteratorToMap

func StateIteratorToMap(itr StateIterator) (map[string][]byte, error)

StateIteratorToMap takes an iterator, and iterates over the entire thing, encoding the KVs into a map, and then closes it.

Types

type Cache

type Cache struct {
	Resources  *Resources
	MyOrgMSPID string
	// contains filtered or unexported fields
}

func NewCache

func NewCache(resources *Resources, myOrgMSPID string) *Cache

func (*Cache) ChaincodeInfo

func (c *Cache) ChaincodeInfo(channelID, name string) (*LocalChaincodeInfo, error)

ChaincodeInfo returns the chaincode definition and its install info.

func (*Cache) HandleChaincodeInstalled

func (c *Cache) HandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID p.PackageID)

HandleChaincodeInstalled should be invoked whenever a new chaincode is installed

func (*Cache) HandleStateUpdates

func (c *Cache) HandleStateUpdates(trigger *ledger.StateUpdateTrigger) error

HandleStateUpdates is required to implement the ledger state listener interface. It applies any state updates to the cache.

func (*Cache) Initialize

func (c *Cache) Initialize(channelID string, qe ledger.SimpleQueryExecutor) error

Initialize will populate the set of currently committed chaincode definitions for a channel into the cache. Note, it this looks like a bit of a DRY violation with respect to 'Update', but, the error handling is quite different and attempting to factor out the common pieces results in a net total of more code.

func (*Cache) InitializeLocalChaincodes

func (c *Cache) InitializeLocalChaincodes() error

InitializeLocalChaincodes should be called once after cache creation (timing doesn't matter, though already installed chaincodes will not be invokable until it it completes). Ideally, this would be part of the constructor, but, we cannot rely on the chaincode store being created before the cache is created.

func (*Cache) InterestedInNamespaces

func (c *Cache) InterestedInNamespaces() []string

InterestedInNamespaces is required to implement the ledger state listener interface

func (*Cache) StateCommitDone

func (c *Cache) StateCommitDone(channelName string)

StateCommitDone is required to implement the ledger state listener interface

type CachedChaincodeDefinition

type CachedChaincodeDefinition struct {
	Definition  *ChaincodeDefinition
	Approved    bool
	InstallInfo *ChaincodeInstallInfo

	// Hashes is the list of hashed keys in the implicit collection referring to this definition.
	// These hashes are determined by the current sequence number of chaincode definition.  When dirty,
	// these hashes will be empty, and when not, they will be populated.
	Hashes []string
}

type ChaincodeDefinition

type ChaincodeDefinition struct {
	Sequence        int64
	EndorsementInfo *lb.ChaincodeEndorsementInfo
	ValidationInfo  *lb.ChaincodeValidationInfo
	Collections     *cb.CollectionConfigPackage
}

ChaincodeDefinition contains the chaincode parameters, as well as the sequence number of the definition. Note, it does not embed ChaincodeParameters so as not to complicate the serialization. It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

func (*ChaincodeDefinition) Parameters

func (cd *ChaincodeDefinition) Parameters() *ChaincodeParameters

Parameters returns the non-sequence info of the chaincode definition

func (*ChaincodeDefinition) String

func (cd *ChaincodeDefinition) String() string

type ChaincodeEndorsementInfo

type ChaincodeEndorsementInfo struct {
	Resources  *Resources
	Cache      ChaincodeInfoCache
	LegacyImpl LegacyLifecycle
}

func (*ChaincodeEndorsementInfo) CachedChaincodeInfo

func (cei *ChaincodeEndorsementInfo) CachedChaincodeInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*LocalChaincodeInfo, bool, error)

func (*ChaincodeEndorsementInfo) ChaincodeContainerInfo

func (cei *ChaincodeEndorsementInfo) ChaincodeContainerInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ccprovider.ChaincodeContainerInfo, error)

ChaincodeContainerInfo returns the information necessary to launch a chaincode

func (*ChaincodeEndorsementInfo) ChaincodeDefinition

func (cei *ChaincodeEndorsementInfo) ChaincodeDefinition(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (ccprovider.ChaincodeDefinition, error)

ChaincodeDefinition returns the details for a chaincode by name

type ChaincodeInfoCache

type ChaincodeInfoCache interface {
	ChaincodeInfo(channelID, chaincodeName string) (definition *LocalChaincodeInfo, err error)
}

type ChaincodeInstallInfo

type ChaincodeInstallInfo struct {
	PackageID p.PackageID
	Type      string
	Path      string
	Label     string
}

type ChaincodeLocalPackage

type ChaincodeLocalPackage struct {
	PackageID string
}

ChaincodePackage is a type of chaincode-source which may be serialized into the org's private data collection. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

type ChaincodeParameters

type ChaincodeParameters struct {
	EndorsementInfo *lb.ChaincodeEndorsementInfo
	ValidationInfo  *lb.ChaincodeValidationInfo
	Collections     *cb.CollectionConfigPackage
}

ChaincodeParameters are the parts of the chaincode definition which are serialized as values in the statedb. It is expected that any instance will have no nil fields once initialized. WARNING: This structure is serialized/deserialized from the DB, re-ordering or adding fields will cause opaque checks to fail.

func (*ChaincodeParameters) Equal

type ChaincodePrivateLedgerShim

type ChaincodePrivateLedgerShim struct {
	Stub       shim.ChaincodeStubInterface
	Collection string
}

ChaincodePrivateLedgerShim wraps the chaincode shim to make access to keys in a collection have the same semantics as normal public keys.

func (*ChaincodePrivateLedgerShim) DelState

func (cls *ChaincodePrivateLedgerShim) DelState(key string) error

DelState deletes the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetState

func (cls *ChaincodePrivateLedgerShim) GetState(key string) ([]byte, error)

GetState returns the value for the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetStateHash

func (cls *ChaincodePrivateLedgerShim) GetStateHash(key string) ([]byte, error)

GetStateHash return the hash of the pre-image for the key in the configured collection.

func (*ChaincodePrivateLedgerShim) GetStateRange

func (cls *ChaincodePrivateLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)

GetStateRange performs a range query in the configured collection for all keys beginning with a particular prefix. This function assumes that keys contain only ascii chars from \x00 to \x7e.

func (*ChaincodePrivateLedgerShim) PutState

func (cls *ChaincodePrivateLedgerShim) PutState(key string, value []byte) error

PutState sets the value for the key in the configured collection.

type ChaincodePublicLedgerShim

type ChaincodePublicLedgerShim struct {
	shim.ChaincodeStubInterface
}

ChaincodePublicLedgerShim decorates the chaincode shim to support the state interfaces required by the serialization code.

func (*ChaincodePublicLedgerShim) GetStateRange

func (cls *ChaincodePublicLedgerShim) GetStateRange(prefix string) (map[string][]byte, error)

GetStateRange performs a range query for keys beginning with a particular prefix, and returns it as a map. This function assumes that keys contain only ascii chars from \x00 to \x7e.

type ChaincodeResultIteratorShim

type ChaincodeResultIteratorShim struct {
	ResultsIterator shim.StateQueryIteratorInterface
}

func (*ChaincodeResultIteratorShim) Close

func (cris *ChaincodeResultIteratorShim) Close() error

func (*ChaincodeResultIteratorShim) Next

type ChaincodeStore

type ChaincodeStore interface {
	Save(label string, ccInstallPkg []byte) (p.PackageID, error)
	ListInstalledChaincodes() ([]chaincode.InstalledChaincode, error)
	Load(packageID p.PackageID) (ccInstallPkg []byte, err error)
}

ChaincodeStore provides a way to persist chaincodes

type ChannelCache

type ChannelCache struct {
	Chaincodes map[string]*CachedChaincodeDefinition

	// InterestingHashes is a map of hashed key names to the chaincode name which they affect.
	// These are to be used for the state listener, to mark chaincode definitions dirty when
	// a write is made into the implicit collection for this org.  Interesting hashes are
	// added when marking a definition clean, and deleted when marking it dirty.
	InterestingHashes map[string]string
}

type ChannelConfigSource

type ChannelConfigSource interface {
	// GetStableChannelConfig returns the channel config for a given channel id.
	// Note, it is a stable bundle, which means it will not be updated, even if
	// the channel is, so it should be discarded after use.
	GetStableChannelConfig(channelID string) channelconfig.Resources
}

ChannelConfigSource provides a way to retrieve the channel config for a given channel ID.

type DummyQueryExecutorShim

type DummyQueryExecutorShim struct {
}

DummyQueryExecutorShim implements the ReadableState interface. It is used to ensure channel-less system chaincode calls don't panic and return and error when an invalid operation is attempted (i.e. an InstallChaincode invocation against a chaincode other than _lifecycle)

func (*DummyQueryExecutorShim) GetState

func (*DummyQueryExecutorShim) GetState(key string) ([]byte, error)

type ErrNamespaceNotDefined

type ErrNamespaceNotDefined struct {
	Namespace string
}

ErrNamespaceNotDefined is the error returned when a namespace is not defined. This indicates that the chaincode definition has not been committed.

func (ErrNamespaceNotDefined) Error

func (e ErrNamespaceNotDefined) Error() string

type ExternalFunctions

type ExternalFunctions struct {
	Resources       *Resources
	InstallListener InstallListener
}

ExternalFunctions is intended primarily to support the SCC functions. In general, its methods signatures produce writes (which must be commmitted as part of an endorsement flow), or return human readable errors (for instance indicating a chaincode is not found) rather than sentinals. Instead, use the utility functions attached to the lifecycle Resources when needed.

func (*ExternalFunctions) ApproveChaincodeDefinitionForOrg

func (ef *ExternalFunctions) ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID p.PackageID, publicState ReadableState, orgState ReadWritableState) error

ApproveChaincodeDefinitionForOrg adds a chaincode definition entry into the passed in Org state. The definition must be for either the currently defined sequence number or the next sequence number. If the definition is for the current sequence number, then it must match exactly the current definition or it will be rejected.

func (*ExternalFunctions) CommitChaincodeDefinition

func (ef *ExternalFunctions) CommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) ([]bool, error)

CommitChaincodeDefinition takes a chaincode definition, checks that its sequence number is the next allowable sequence number, checks which organizations agree with the definition, and applies the definition to the public world state. It is the responsibility of the caller to check the agreement to determine if the result is valid (typically this means checking that the peer's own org is in agreement.)

func (*ExternalFunctions) DefaultEndorsementPolicyAsBytes

func (ef *ExternalFunctions) DefaultEndorsementPolicyAsBytes(channelID string) ([]byte, error)

DefaultEndorsementPolicyAsBytes returns a marshalled version of the default chaincode endorsement policy in the supplied channel

func (*ExternalFunctions) InstallChaincode

func (ef *ExternalFunctions) InstallChaincode(chaincodeInstallPackage []byte) (*chaincode.InstalledChaincode, 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 (*ExternalFunctions) QueryApprovalStatus

func (ef *ExternalFunctions) QueryApprovalStatus(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) ([]bool, error)

QueryApprovalStatus takes a chaincode definition, checks that its sequence number is the next allowable sequence number and checks which organizations agree with the definition

func (*ExternalFunctions) QueryChaincodeDefinition

func (ef *ExternalFunctions) QueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)

QueryChaincodeDefinition returns the defined chaincode by the given name (if it is committed, and a chaincode) or otherwise returns an error.

func (*ExternalFunctions) QueryInstalledChaincode

func (ef *ExternalFunctions) QueryInstalledChaincode(packageID p.PackageID) (*chaincode.InstalledChaincode, error)

QueryInstalledChaincode returns the hash of an installed chaincode of a given name and version.

func (*ExternalFunctions) QueryInstalledChaincodes

func (ef *ExternalFunctions) QueryInstalledChaincodes() ([]chaincode.InstalledChaincode, error)

QueryInstalledChaincodes returns a list of installed chaincodes

func (*ExternalFunctions) QueryNamespaceDefinitions

func (ef *ExternalFunctions) QueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)

QueryNamespaceDefinitions lists the publicly defined namespaces in a channel. Today it should only ever find Datatype encodings of 'ChaincodeDefinition'. In the future as we support encodings like 'TokenManagementSystem' or similar, additional statements will be added to the switch.

func (*ExternalFunctions) SetChaincodeDefinitionDefaults

func (ef *ExternalFunctions) SetChaincodeDefinitionDefaults(chname string, cd *ChaincodeDefinition) error

SetChaincodeDefinitionDefaults fills any empty fields in the supplied ChaincodeDefinition with the supplied channel's defaults

type InstallListener

type InstallListener interface {
	HandleChaincodeInstalled(md *persistence.ChaincodePackageMetadata, packageID p.PackageID)
}

type Invocation

type Invocation struct {
	ApplicationConfig channelconfig.Application // Note this may be nil
	Stub              shim.ChaincodeStubInterface
	SCC               *SCC
}

func (*Invocation) ApproveChaincodeDefinitionForMyOrg

func (i *Invocation) ApproveChaincodeDefinitionForMyOrg(input *lb.ApproveChaincodeDefinitionForMyOrgArgs) (proto.Message, error)

ApproveChaincodeDefinitionForMyOrg is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) CommitChaincodeDefinition

func (i *Invocation) CommitChaincodeDefinition(input *lb.CommitChaincodeDefinitionArgs) (proto.Message, error)

CommitChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) InstallChaincode

func (i *Invocation) InstallChaincode(input *lb.InstallChaincodeArgs) (proto.Message, error)

InstallChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryApprovalStatus

func (i *Invocation) QueryApprovalStatus(input *lb.QueryApprovalStatusArgs) (proto.Message, error)

QueryApprovalStatus is a SCC function that may be dispatched to the underlying lifecycle implementation

func (*Invocation) QueryChaincodeDefinition

func (i *Invocation) QueryChaincodeDefinition(input *lb.QueryChaincodeDefinitionArgs) (proto.Message, error)

QueryChaincodeDefinition is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryInstalledChaincode

func (i *Invocation) QueryInstalledChaincode(input *lb.QueryInstalledChaincodeArgs) (proto.Message, error)

QueryInstalledChaincode is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryInstalledChaincodes

func (i *Invocation) QueryInstalledChaincodes(input *lb.QueryInstalledChaincodesArgs) (proto.Message, error)

QueryInstalledChaincodes is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

func (*Invocation) QueryNamespaceDefinitions

func (i *Invocation) QueryNamespaceDefinitions(input *lb.QueryNamespaceDefinitionsArgs) (proto.Message, error)

QueryNamespaceDefinitions is a SCC function that may be dispatched to which routes to the underlying lifecycle implementation.

type LegacyDefinition

type LegacyDefinition struct {
	Name                string
	Version             string
	HashField           []byte
	EndorsementPlugin   string
	ValidationPlugin    string
	ValidationParameter []byte
	RequiresInitField   bool
}

LegacyDefinition is an implmentor of ccprovider.ChaincodeDefinition. It is a different data-type to allow differentiation at cast-time from chaincode definitions which require validaiton of instantiation policy.

func (*LegacyDefinition) CCName

func (ld *LegacyDefinition) CCName() string

CCName returns the chaincode name

func (*LegacyDefinition) CCVersion

func (ld *LegacyDefinition) CCVersion() string

CCVersion returns the version of the chaincode.

func (*LegacyDefinition) Endorsement

func (ld *LegacyDefinition) Endorsement() string

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

func (*LegacyDefinition) Hash

func (ld *LegacyDefinition) Hash() []byte

Hash returns the hash of <name>:<version>. This is useless, but is a hack to allow the rest of the code to have consistent view of what hash means for a chaincode definition. Ultimately, this should be removed.

func (*LegacyDefinition) RequiresInit

func (ld *LegacyDefinition) RequiresInit() bool

RequiresInit returns whether this chaincode must have Init commit before invoking.

func (*LegacyDefinition) Validation

func (ld *LegacyDefinition) 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 LegacyDeployedCCInfoProvider

type LegacyDeployedCCInfoProvider interface {
	ledger.DeployedChaincodeInfoProvider
}

type LegacyLifecycle

type LegacyLifecycle interface {
	corechaincode.Lifecycle
}

type LocalChaincode

type LocalChaincode struct {
	Info       *ChaincodeInstallInfo
	References map[string]map[string]*CachedChaincodeDefinition
}

type LocalChaincodeInfo

type LocalChaincodeInfo struct {
	Definition  *ChaincodeDefinition
	Approved    bool
	InstallInfo *ChaincodeInstallInfo
}

type Marshaler

type Marshaler func(proto.Message) ([]byte, error)

func (Marshaler) Marshal

func (m Marshaler) Marshal(msg proto.Message) ([]byte, error)

type OpaqueState

type OpaqueState interface {
	GetStateHash(key string) (value []byte, err error)
}

type PackageParser

type PackageParser interface {
	Parse(data []byte) (*persistence.ChaincodePackage, error)
}

type PrivateQueryExecutor

type PrivateQueryExecutor interface {
	GetPrivateDataHash(namespace, collection, key string) (value []byte, err error)
}

type PrivateQueryExecutorShim

type PrivateQueryExecutorShim struct {
	Namespace  string
	Collection string
	State      PrivateQueryExecutor
}

func (*PrivateQueryExecutorShim) GetStateHash

func (pqes *PrivateQueryExecutorShim) GetStateHash(key string) ([]byte, error)

type RangeableState

type RangeableState interface {
	GetStateRange(prefix string) (map[string][]byte, error)
}

type ReadWritableState

type ReadWritableState interface {
	ReadableState
	PutState(key string, value []byte) error
	DelState(key string) error
}

type ReadableState

type ReadableState interface {
	GetState(key string) (value []byte, err error)
}

type Resources

type Resources struct {
	ChannelConfigSource ChannelConfigSource
	ChaincodeStore      ChaincodeStore
	PackageParser       PackageParser
	Serializer          *Serializer
}

Resources stores the common functions needed by all components of the lifecycle by the SCC as well as internally. It also has some utility methods attached to it for querying the lifecycle definitions.

func (*Resources) ChaincodeDefinitionIfDefined

func (r *Resources) ChaincodeDefinitionIfDefined(chaincodeName string, state ReadableState) (bool, *ChaincodeDefinition, error)

ChaincodeDefinitionIfDefined returns whether the chaincode name is defined in the new lifecycle, a shim around the SimpleQueryExecutor to work with the serializer, or an error. If the namespace is defined, but it is not a chaincode, this is considered an error.

type ResultsIteratorShim

type ResultsIteratorShim struct {
	ResultsIterator commonledger.ResultsIterator
}

func (*ResultsIteratorShim) Close

func (ris *ResultsIteratorShim) Close() error

func (*ResultsIteratorShim) Next

func (ris *ResultsIteratorShim) Next() (*queryresult.KV, error)

type SCC

type SCC struct {
	OrgMSPID string

	ACLProvider aclmgmt.ACLProvider

	ChannelConfigSource ChannelConfigSource

	// Functions provides the backing implementation of lifecycle.
	Functions SCCFunctions

	// Dispatcher handles the rote protobuf boilerplate for unmarshaling/marshaling
	// the inputs and outputs of the SCC functions.
	Dispatcher *dispatcher.Dispatcher
}

SCC implements the required methods to satisfy the chaincode interface. It routes the invocation calls to the backing implementations.

func (*SCC) Chaincode

func (scc *SCC) Chaincode() shim.Chaincode

Chaincode returns a reference to itself

func (*SCC) Enabled

func (scc *SCC) Enabled() bool

Enabled returns true

func (*SCC) Init

func (scc *SCC) Init(stub shim.ChaincodeStubInterface) pb.Response

Init is mostly useless for system chaincodes and always returns success

func (*SCC) InitArgs

func (scc *SCC) InitArgs() [][]byte

InitArgs returns nil

func (*SCC) InvokableCC2CC

func (scc *SCC) InvokableCC2CC() bool

InvokableCC2CC returns true

func (*SCC) InvokableExternal

func (scc *SCC) InvokableExternal() bool

InvokableExternal returns true

func (*SCC) Invoke

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) Name

func (scc *SCC) Name() string

Name returns "_lifecycle"

func (*SCC) Path

func (scc *SCC) Path() string

Path returns "github.com/hyperledger/fabric/core/chaincode/lifecycle"

type SCCFunctions

type SCCFunctions interface {
	// InstallChaincode persists a chaincode definition to disk
	InstallChaincode([]byte) (*chaincode.InstalledChaincode, error)

	// QueryInstalledChaincode returns the hash for a given name and version of an installed chaincode
	QueryInstalledChaincode(packageID persistenceintf.PackageID) (*chaincode.InstalledChaincode, error)

	// QueryInstalledChaincodes returns the currently installed chaincodes
	QueryInstalledChaincodes() (chaincodes []chaincode.InstalledChaincode, err error)

	// ApproveChaincodeDefinitionForOrg records a chaincode definition into this org's implicit collection.
	ApproveChaincodeDefinitionForOrg(chname, ccname string, cd *ChaincodeDefinition, packageID persistenceintf.PackageID, publicState ReadableState, orgState ReadWritableState) error

	// QueryApprovalStatus returns an array of boolean to signal whether the orgs
	// whose orgStates was supplied as argument have approveed the specified definition
	QueryApprovalStatus(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) ([]bool, error)

	// CommitChaincodeDefinition records a new chaincode definition into the public state and returns the orgs which agreed with that definition.
	CommitChaincodeDefinition(chname, ccname string, cd *ChaincodeDefinition, publicState ReadWritableState, orgStates []OpaqueState) ([]bool, error)

	// QueryChaincodeDefinition reads a chaincode definition from the public state.
	QueryChaincodeDefinition(name string, publicState ReadableState) (*ChaincodeDefinition, error)

	// QueryNamespaceDefinitions returns all defined namespaces
	QueryNamespaceDefinitions(publicState RangeableState) (map[string]string, error)
}

SCCFunctions provides a backing implementation with concrete arguments for each of the SCC functions

type Serializer

type Serializer struct {
	// Marshaler, when nil uses the standard protobuf impl.
	// Can be overridden for test.
	Marshaler Marshaler
}

Serializer is used to write structures into the db and to read them back out. Although it's unfortunate to write a custom serializer, rather than to use something pre-written, like protobuf or JSON, in order to produce precise readwrite sets which only perform state updates for keys which are actually updated (and not simply set to the same value again) custom serialization is required.

func (*Serializer) Deserialize

func (s *Serializer) Deserialize(namespace, name string, metadata *lb.StateMetadata, structure interface{}, state ReadableState) error

Deserialize accepts a struct (of a type previously serialized) and populates it with the values from the db. Note: The struct names for the serialization and deserialization must match exactly. Unencoded fields are not populated, and the extraneous keys are ignored. The metadata provided should have been returned by a DeserializeMetadata call for the same namespace and name.

func (*Serializer) DeserializeAllMetadata

func (s *Serializer) DeserializeAllMetadata(namespace string, state RangeableState) (map[string]*lb.StateMetadata, error)

func (*Serializer) DeserializeField

func (s *Serializer) DeserializeField(namespace, name, field string, state ReadableState) (*lb.StateData, error)

func (*Serializer) DeserializeFieldAsBytes

func (s *Serializer) DeserializeFieldAsBytes(namespace, name, field string, state ReadableState) ([]byte, error)

func (*Serializer) DeserializeFieldAsInt64

func (s *Serializer) DeserializeFieldAsInt64(namespace, name, field string, state ReadableState) (int64, error)

func (*Serializer) DeserializeFieldAsProto

func (s *Serializer) DeserializeFieldAsProto(namespace, name, field string, state ReadableState, msg proto.Message) error

func (*Serializer) DeserializeFieldAsString

func (s *Serializer) DeserializeFieldAsString(namespace, name, field string, state ReadableState) (string, error)

func (*Serializer) DeserializeMetadata

func (s *Serializer) DeserializeMetadata(namespace, name string, state ReadableState) (*lb.StateMetadata, bool, error)

func (*Serializer) IsMetadataSerialized

func (s *Serializer) IsMetadataSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)

func (*Serializer) IsSerialized

func (s *Serializer) IsSerialized(namespace, name string, structure interface{}, state OpaqueState) (bool, error)

IsSerialized essentially checks if the hashes of a serialized version of a structure matches the hashes of the pre-image of some struct serialized into the database.

func (*Serializer) SerializableChecks

func (s *Serializer) SerializableChecks(structure interface{}) (reflect.Value, []string, error)

SerializableChecks performs some boilerplate checks to make sure the given structure is serializable. It returns the reflected version of the value and a slice of all field names, or an error.

func (*Serializer) Serialize

func (s *Serializer) Serialize(namespace, name string, structure interface{}, state ReadWritableState) error

Serialize takes a pointer to a struct, and writes each of its fields as keys into a namespace. It also writes the struct metadata (if it needs updating) and, deletes any keys in the namespace which are not found in the struct. Note: If a key already exists for the field, and the value is unchanged, then the key is _not_ written to.

type SimpleQueryExecutorShim

type SimpleQueryExecutorShim struct {
	Namespace           string
	SimpleQueryExecutor ledger.SimpleQueryExecutor
}

SimpleQueryExecutorShim implements the ReadableState and RangeableState interfaces based on an underlying ledger.SimpleQueryExecutor

func (*SimpleQueryExecutorShim) GetState

func (sqes *SimpleQueryExecutorShim) GetState(key string) ([]byte, error)

func (*SimpleQueryExecutorShim) GetStateRange

func (sqes *SimpleQueryExecutorShim) GetStateRange(prefix string) (map[string][]byte, error)

type StateIterator

type StateIterator interface {
	Close() error
	Next() (*queryresult.KV, error)
}

type ValidatorCommitter

type ValidatorCommitter struct {
	Resources                    *Resources
	LegacyDeployedCCInfoProvider LegacyDeployedCCInfoProvider
}

func (*ValidatorCommitter) ChaincodeImplicitCollections

func (vc *ValidatorCommitter) ChaincodeImplicitCollections(channelName string) ([]*cb.StaticCollectionConfig, error)

ChaincodeImplicitCollections assumes the chaincode exists in the new lifecycle and returns the implicit collections

func (*ValidatorCommitter) ChaincodeInfo

func (vc *ValidatorCommitter) ChaincodeInfo(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) (*ledger.DeployedChaincodeInfo, error)

func (*ValidatorCommitter) CollectionInfo

func (vc *ValidatorCommitter) CollectionInfo(channelName, chaincodeName, collectionName string, qe ledger.SimpleQueryExecutor) (*cb.StaticCollectionConfig, error)

CollectionInfo implements function in interface ledger.DeployedChaincodeInfoProvider, it returns config for both static and implicit collections.

func (*ValidatorCommitter) CollectionValidationInfo

func (vc *ValidatorCommitter) CollectionValidationInfo(channelID, chaincodeName, collectionName string, state validationState.State) (args []byte, unexpectedErr, validationErr error)

CollectionValidationInfo returns information about collections to the validation component

func (*ValidatorCommitter) ImplicitCollectionEndorsementPolicyAsBytes

func (vc *ValidatorCommitter) ImplicitCollectionEndorsementPolicyAsBytes(channelID, orgMSPID string) (policy []byte, unexpectedErr, validationErr error)

func (*ValidatorCommitter) ImplicitCollections

func (vc *ValidatorCommitter) ImplicitCollections(channelName, chaincodeName string, qe ledger.SimpleQueryExecutor) ([]*cb.StaticCollectionConfig, error)

ImplicitCollections implements function in interface ledger.DeployedChaincodeInfoProvider. It returns a slice that contains one proto msg for each of the implicit collections

func (*ValidatorCommitter) LifecycleEndorsementPolicyAsBytes

func (vc *ValidatorCommitter) LifecycleEndorsementPolicyAsBytes(channelID string) ([]byte, error)

func (*ValidatorCommitter) Namespaces

func (vc *ValidatorCommitter) Namespaces() []string

Namespaces returns the list of namespaces which are relevant to chaincode lifecycle

func (*ValidatorCommitter) UpdatedChaincodes

func (vc *ValidatorCommitter) UpdatedChaincodes(stateUpdates map[string][]*kvrwset.KVWrite) ([]*ledger.ChaincodeLifecycleInfo, error)

UpdatedChaincodes returns the chaincodes that are getting updated by the supplied 'stateUpdates'

func (*ValidatorCommitter) ValidationInfo

func (vc *ValidatorCommitter) ValidationInfo(channelID, chaincodeName string, qe ledger.SimpleQueryExecutor) (plugin string, args []byte, unexpectedErr error, validationErr error)

ValidationInfo returns the name and arguments of the validation plugin for the supplied chaincode. The function returns two types of errors, unexpected errors and validation errors. The reason for this is that this function is called from the validation code, which needs to differentiate the two types of error to halt processing on the channel if the unexpected error is not nil and mark the transaction as invalid if the validation error is not nil.

type ValidatorStateShim

type ValidatorStateShim struct {
	ValidatorState validatorstate.State
	Namespace      string
}

func (*ValidatorStateShim) GetState

func (vss *ValidatorStateShim) GetState(key string) ([]byte, error)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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