chaincode

package
v0.0.0-...-fbe82ab Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//链码容器中的相互TLS身份验证客户端密钥和证书路径
	TLSClientKeyPath      string = "/etc/hyperledger/fabric/client.key"
	TLSClientCertPath     string = "/etc/hyperledger/fabric/client.crt"
	TLSClientRootCertPath string = "/etc/hyperledger/fabric/peer.crt"
)
View Source
const (
	//txSimulatorKey是用于提供分类帐的上下文键。txSimulator
	//从背书人到链码。
	TXSimulatorKey key = "txsimulatorkey"

	//HistoryQueryExecutorKey是用于提供
	//从背书人到链码的ledger.historyqueryexecutor。
	HistoryQueryExecutorKey key = "historyqueryexecutorkey"
)
View Source
const DevModeUserRunsChaincode string = "dev"

devmodeuserrunschaincode支持在开发中执行链码 环境

Variables

This section is empty.

Functions

func IsDevMode

func IsDevMode() bool

如果对等机配置了开发模式,则isdevmode返回true。 启用。

func NewTxKey

func NewTxKey(channelID, txID string) string

func ParseName

func ParseName(ccName string) *sysccprovider.ChaincodeInstance

ParseName将一个链代码名称解析为一个链代码实例。名字应该 格式为“chaincode name:version/channel name”,带有可选元素。

Types

type ACLProvider

type ACLProvider interface {
	CheckACL(resName string, channelID string, idinfo interface{}) error
}

ACLprovider在调用时执行访问控制检查 链码。

type ActiveTransactions

type ActiveTransactions struct {
	// contains filtered or unexported fields
}

func NewActiveTransactions

func NewActiveTransactions() *ActiveTransactions

func (*ActiveTransactions) Add

func (a *ActiveTransactions) Add(channelID, txID string) bool

func (*ActiveTransactions) Remove

func (a *ActiveTransactions) Remove(channelID, txID string)

type ApplicationConfigRetriever

type ApplicationConfigRetriever interface {
	//getapplicationconfig返回通道的channelconfig.application
	//以及应用程序配置是否存在
	GetApplicationConfig(cid string) (channelconfig.Application, bool)
}

ApplicationConfigRetriever检索通道的应用程序配置

type CCProviderImpl

type CCProviderImpl struct {
	// contains filtered or unexported fields
}

ccproviderimpl是ccprovider.chaincodeprovider接口的实现

func NewProvider

func NewProvider(cs *ChaincodeSupport) *CCProviderImpl

func (*CCProviderImpl) Execute

执行执行给定上下文和规范(调用或部署)的链代码。

func (*CCProviderImpl) ExecuteLegacyInit

executeLegacyInit执行一个不在lscc表中的链代码

func (*CCProviderImpl) Stop

type CertGenerator

type CertGenerator interface {
	//生成返回证书、私钥和关联项
	//具有给定链码名称的证书的哈希
	Generate(ccName string) (*accesscontrol.CertAndPrivKeyPair, error)
}

certgenerator为chaincode生成客户端证书。

type ChaincodeDefinitionGetter

type ChaincodeDefinitionGetter interface {
	ChaincodeDefinition(chaincodeName string, txSim ledger.QueryExecutor) (ccprovider.ChaincodeDefinition, error)
}

chaincodedefinitiongetter负责检索chaincode定义 来自系统。InstantiationPolicyChecker使用该定义。

type ChaincodeSupport

type ChaincodeSupport struct {
	Keepalive        time.Duration
	ExecuteTimeout   time.Duration
	UserRunsCC       bool
	Runtime          Runtime
	ACLProvider      ACLProvider
	HandlerRegistry  *HandlerRegistry
	Launcher         Launcher
	SystemCCProvider sysccprovider.SystemChaincodeProvider
	Lifecycle        Lifecycle

	HandlerMetrics *HandlerMetrics
	LaunchMetrics  *LaunchMetrics
	// contains filtered or unexported fields
}

Chaincode支持负责提供与对等端的Chaincode的接口。

func NewChaincodeSupport

func NewChaincodeSupport(
	config *Config,
	peerAddress string,
	userRunsCC bool,
	caCert []byte,
	certGenerator CertGenerator,
	packageProvider PackageProvider,
	lifecycle Lifecycle,
	aclProvider ACLProvider,
	processor Processor,
	SystemCCProvider sysccprovider.SystemChaincodeProvider,
	platformRegistry *platforms.Registry,
	appConfig ApplicationConfigRetriever,
	metricsProvider metrics.Provider,
) *ChaincodeSupport

NewChaincodeSupport创建新的ChaincodeSupport实例。

func (*ChaincodeSupport) Execute

execute调用chaincode并返回原始响应。

func (*ChaincodeSupport) ExecuteLegacyInit

executeLegacyInit是一种临时方法,在旧的样式生命周期后应将其移除。 完全不赞成。理想情况下,在引入新生命周期之后发布一个版本。 它不尝试基于生命周期中的信息启动链代码,而是 以chaincodedeploymentspec的形式直接接受容器信息。

func (*ChaincodeSupport) HandleChaincodeStream

func (cs *ChaincodeSupport) HandleChaincodeStream(stream ccintf.ChaincodeStream) error

handlechaincodestream实现ccintf.handlechaincodestream,以便所有虚拟机使用适当的流进行调用

func (*ChaincodeSupport) Invoke

invoke将调用chaincode并返回包含响应的消息。 如果链码尚未运行,则将启动链码。

func (*ChaincodeSupport) InvokeInit

func (*ChaincodeSupport) Launch

func (cs *ChaincodeSupport) Launch(chainID, chaincodeName, chaincodeVersion string, qe ledger.QueryExecutor) (*Handler, error)

如果链码尚未运行,则启动将开始执行链码。这种方法 阻止,直到对等端处理程序进入就绪状态或遇到致命错误

func (*ChaincodeSupport) LaunchInit

与v1.0-v1.2生命周期的情况一样,链代码还没有 在lscc表中定义

func (*ChaincodeSupport) Register

func (*ChaincodeSupport) Stop

如果正在运行,stop会停止链码。

type CheckInstantiationPolicyFunc

type CheckInstantiationPolicyFunc func(name, version string, cd *ccprovider.ChaincodeData) error

从函数到InstantiationPolicyChecker接口的适配器。

func (CheckInstantiationPolicyFunc) CheckInstantiationPolicy

func (c CheckInstantiationPolicyFunc) CheckInstantiationPolicy(name, version string, cd *ccprovider.ChaincodeData) error

type Config

type Config struct {
	TLSEnabled     bool
	Keepalive      time.Duration
	ExecuteTimeout time.Duration
	StartupTimeout time.Duration
	LogFormat      string
	LogLevel       string
	ShimLogLevel   string
}

func GlobalConfig

func GlobalConfig() *Config

type ContainerRuntime

type ContainerRuntime struct {
	CertGenerator    CertGenerator
	Processor        Processor
	CACert           []byte
	CommonEnv        []string
	PeerAddress      string
	PlatformRegistry *platforms.Registry
}

ContainerRuntime负责管理容器化的链代码。

func (*ContainerRuntime) LaunchConfig

func (c *ContainerRuntime) LaunchConfig(cname string, ccType string) (*LaunchConfig, error)

func (*ContainerRuntime) Start

func (c *ContainerRuntime) Start(ccci *ccprovider.ChaincodeContainerInfo, codePackage []byte) error

Start在运行时环境中启动链码。

func (*ContainerRuntime) Stop

stop终止chaincode及其容器运行时环境。

type ContextRegistry

type ContextRegistry interface {
	Create(txParams *ccprovider.TransactionParams) (*TransactionContext, error)
	Get(chainID, txID string) *TransactionContext
	Delete(chainID, txID string)
	Close()
}

type Handler

type Handler struct {
	//keep alive指定保持活动消息的发送间隔。
	Keepalive time.Duration
	//systemcversion指定当前系统链码版本
	SystemCCVersion string
	//definitiongetter用于从
	//生命周期系统链码。
	DefinitionGetter ChaincodeDefinitionGetter
	//调用程序用于调用链代码。
	Invoker Invoker
	//注册表用于跟踪活动的处理程序。
	Registry Registry
	//aclprovider用于检查是否允许调用chaincode。
	ACLProvider ACLProvider
	//
	//通过通道名称和事务ID访问的。
	TXContexts ContextRegistry
	//ActiveTransactions保存活动事务标识符。
	ActiveTransactions TransactionRegistry
	//SystemCCProvider提供对系统链码元数据的访问
	SystemCCProvider SystemCCProvider
	//InstantiationPolicyChecker用于评估链码实例化策略。
	InstantiationPolicyChecker InstantiationPolicyChecker
	//
	QueryResponseBuilder QueryResponseBuilder
	//Ledgergetter用于获取与渠道关联的分类帐
	LedgerGetter LedgerGetter
	//
	UUIDGenerator UUIDGenerator
	//AppConfig用于检索通道的应用程序配置
	AppConfig ApplicationConfigRetriever

	//度量保存链码处理程序度量
	Metrics *HandlerMetrics
	// contains filtered or unexported fields
}

处理程序实现链代码流的对等端。

func (*Handler) ChaincodeName

func (h *Handler) ChaincodeName() string

func (*Handler) Close

func (h *Handler) Close()

func (*Handler) Execute

func (*Handler) HandleDelState

func (h *Handler) HandleDelState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

func (*Handler) HandleGetHistoryForKey

func (h *Handler) HandleGetHistoryForKey(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理对分类帐历史记录数据库的查询

func (*Handler) HandleGetQueryResult

func (h *Handler) HandleGetQueryResult(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理对分类帐的查询以执行查询状态

func (*Handler) HandleGetState

func (h *Handler) HandleGetState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理对分类帐的查询以获取状态

func (*Handler) HandleGetStateByRange

func (h *Handler) HandleGetStateByRange(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理对分类帐的查询以调整查询状态

func (*Handler) HandleGetStateMetadata

func (h *Handler) HandleGetStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

func (*Handler) HandleInvokeChaincode

func (h *Handler) HandleInvokeChaincode(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理修改分类帐状态的请求

func (*Handler) HandlePutState

func (h *Handler) HandlePutState(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

func (*Handler) HandlePutStateMetadata

func (h *Handler) HandlePutStateMetadata(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

func (*Handler) HandleQueryStateClose

func (h *Handler) HandleQueryStateClose(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理状态迭代器的关闭

func (*Handler) HandleQueryStateNext

func (h *Handler) HandleQueryStateNext(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error)

处理下一个查询状态的分类帐查询

func (*Handler) HandleRegister

func (h *Handler) HandleRegister(msg *pb.ChaincodeMessage)

当chaincode尝试注册时调用handleregister。

func (*Handler) HandleTransaction

func (h *Handler) HandleTransaction(msg *pb.ChaincodeMessage, delegate handleFunc)

将消息转发给提供的委托之前的上下文。响应消息 代表返回的消息将发送到聊天流。返回的任何错误 委托打包为链码错误消息。

func (*Handler) Notify

func (h *Handler) Notify(msg *pb.ChaincodeMessage)

func (*Handler) ProcessStream

func (h *Handler) ProcessStream(stream ccintf.ChaincodeStream) error

func (*Handler) State

func (h *Handler) State() State

type HandlerMetrics

type HandlerMetrics struct {
	ShimRequestsReceived  metrics.Counter
	ShimRequestsCompleted metrics.Counter
	ShimRequestDuration   metrics.Histogram
	ExecuteTimeouts       metrics.Counter
}

func NewHandlerMetrics

func NewHandlerMetrics(p metrics.Provider) *HandlerMetrics

type HandlerRegistry

type HandlerRegistry struct {
	// contains filtered or unexported fields
}

handlerRegistry维护链式代码处理程序实例。

func NewHandlerRegistry

func NewHandlerRegistry(allowUnsolicitedRegistration bool) *HandlerRegistry

NewHandlerRegistry构造一个HandlerRegistry。

func (*HandlerRegistry) Deregister

func (r *HandlerRegistry) Deregister(cname string) error

取消注册清除对状态关联的指定链码的引用。 作为清理的一部分,它关闭处理程序以便清理任何状态。 如果注册表不包含提供的处理程序,则返回错误。

func (*HandlerRegistry) Failed

func (r *HandlerRegistry) Failed(cname string, err error)

func (*HandlerRegistry) Handler

func (r *HandlerRegistry) Handler(cname string) *Handler

func (*HandlerRegistry) Launching

func (r *HandlerRegistry) Launching(cname string) (*LaunchState, bool)

启动表示正在启动链码。洗衣店说 返回提供了确定操作何时 完成,是否失败。bool指示是否 链码已经启动。

func (*HandlerRegistry) Ready

func (r *HandlerRegistry) Ready(cname string)

就绪表示链码注册已完成,并且 准备好的响应已发送到链码。

func (*HandlerRegistry) Register

func (r *HandlerRegistry) Register(h *Handler) error

寄存器向注册表添加一个链式代码处理程序。 如果已经为注册了处理程序, 链码。如果chaincode还没有返回错误 已“启动”,不允许主动注册。

type InstantiationPolicyChecker

type InstantiationPolicyChecker interface {
	CheckInstantiationPolicy(name, version string, cd *ccprovider.ChaincodeData) error
}

InstantiationPolicyChecker用于评估实例化策略。

type Invoker

type Invoker interface {
	Invoke(txParams *ccprovider.TransactionParams, cccid *ccprovider.CCContext, spec *pb.ChaincodeInput) (*pb.ChaincodeMessage, error)
}

调用程序调用链代码。

type LaunchConfig

type LaunchConfig struct {
	Args  []string
	Envs  []string
	Files map[string][]byte
}

launchconfig保存链码启动参数、环境变量和文件。

func (*LaunchConfig) String

func (lc *LaunchConfig) String() string

type LaunchMetrics

type LaunchMetrics struct {
	LaunchDuration metrics.Histogram
	LaunchFailures metrics.Counter
	LaunchTimeouts metrics.Counter
}

func NewLaunchMetrics

func NewLaunchMetrics(p metrics.Provider) *LaunchMetrics

type LaunchRegistry

type LaunchRegistry interface {
	Launching(cname string) (launchState *LaunchState, started bool)
	Deregister(cname string) error
}

launchRegistry跟踪启动链代码实例。

type LaunchState

type LaunchState struct {
	// contains filtered or unexported fields
}

func NewLaunchState

func NewLaunchState() *LaunchState

func (*LaunchState) Done

func (l *LaunchState) Done() <-chan struct{}

func (*LaunchState) Err

func (l *LaunchState) Err() error

func (*LaunchState) Notify

func (l *LaunchState) Notify(err error)

type Launcher

type Launcher interface {
	Launch(ccci *ccprovider.ChaincodeContainerInfo) error
}

Launcher用于启动chaincode运行时。

type LedgerGetter

type LedgerGetter interface {
	GetLedger(cid string) ledger.PeerLedger
}

Ledgergetter用于获取链码的分类帐。

type Lifecycle

type Lifecycle interface {
	//chaincodedefinition按名称返回chaincode的详细信息
	ChaincodeDefinition(chaincodeName string, qe ledger.QueryExecutor) (ccprovider.ChaincodeDefinition, error)

	//chaincodecontainerinfo返回启动chaincode所需的包
	ChaincodeContainerInfo(chaincodeName string, qe ledger.QueryExecutor) (*ccprovider.ChaincodeContainerInfo, error)
}

Lifecycle提供了一种检索链码定义和运行它们所需的包的方法。

type MessageHandler

type MessageHandler interface {
	Handle(*pb.ChaincodeMessage, *TransactionContext) (*pb.ChaincodeMessage, error)
}

type PackageProvider

type PackageProvider interface {
	GetChaincodeCodePackage(ccname string, ccversion string) ([]byte, error)
}

PackageProvider从文件系统获取链码包。

type PendingQueryResult

type PendingQueryResult struct {
	// contains filtered or unexported fields
}

func (*PendingQueryResult) Add

func (p *PendingQueryResult) Add(queryResult commonledger.QueryResult) error

func (*PendingQueryResult) Cut

func (*PendingQueryResult) Size

func (p *PendingQueryResult) Size() int

type Processor

type Processor interface {
	Process(vmtype string, req container.VMCReq) error
}

处理器处理虚拟机和容器请求。

type QueryResponseBuilder

type QueryResponseBuilder interface {
	BuildQueryResponse(txContext *TransactionContext, iter commonledger.ResultsIterator,
		iterID string, isPaginated bool, totalReturnLimit int32) (*pb.QueryResponse, error)
}

QueryResponseBuilder负责为查询生成QueryResponse消息 由链码启动的事务。

type QueryResponseGenerator

type QueryResponseGenerator struct {
	MaxResultLimit int
}

func (*QueryResponseGenerator) BuildQueryResponse

func (q *QueryResponseGenerator) BuildQueryResponse(txContext *TransactionContext, iter commonledger.ResultsIterator,
	iterID string, isPaginated bool, totalReturnLimit int32) (*pb.QueryResponse, error)

BuildQueryResponse采用迭代器和获取状态来构造QueryResponse

type Registry

type Registry interface {
	Register(*Handler) error
	Ready(cname string)
	Failed(cname string, err error)
	Deregister(cname string) error
}

注册表负责跟踪处理程序。

type Runtime

type Runtime interface {
	Start(ccci *ccprovider.ChaincodeContainerInfo, codePackage []byte) error
	Stop(ccci *ccprovider.ChaincodeContainerInfo) error
}

运行时用于管理链码运行时实例。

type RuntimeLauncher

type RuntimeLauncher struct {
	Runtime         Runtime
	Registry        LaunchRegistry
	PackageProvider PackageProvider
	StartupTimeout  time.Duration
	Metrics         *LaunchMetrics
}

RuntimeLauncher负责启动链码运行时。

func (*RuntimeLauncher) Launch

type State

type State int
const (
	Created State = iota
	Established
	Ready
)

func (State) String

func (s State) String() string

type SystemCCProvider

type SystemCCProvider interface {
	IsSysCC(name string) bool
	IsSysCCAndNotInvokableCC2CC(name string) bool
}

SystemCCProvider提供系统链代码元数据。

type TransactionContext

type TransactionContext struct {
	ChainID              string
	SignedProp           *pb.SignedProposal
	Proposal             *pb.Proposal
	ResponseNotifier     chan *pb.ChaincodeMessage
	TXSimulator          ledger.TxSimulator
	HistoryQueryExecutor ledger.HistoryQueryExecutor
	CollectionStore      privdata.CollectionStore
	IsInitTransaction    bool

	//用于保存集合ACL结果的缓存
	//当为每个链代码创建TransactionContext时
	//调用(即使在调用链码的情况下,
	//我们不需要将命名空间存储在映射中,
	//仅收集就足够了。
	AllowedCollectionAccess map[string]bool
	// contains filtered or unexported fields
}

func (*TransactionContext) CleanupQueryContext

func (t *TransactionContext) CleanupQueryContext(queryID string)

func (*TransactionContext) CleanupQueryContextWithBookmark

func (t *TransactionContext) CleanupQueryContextWithBookmark(queryID string) string

func (*TransactionContext) CloseQueryIterators

func (t *TransactionContext) CloseQueryIterators()

func (*TransactionContext) GetPendingQueryResult

func (t *TransactionContext) GetPendingQueryResult(queryID string) *PendingQueryResult

func (*TransactionContext) GetQueryIterator

func (t *TransactionContext) GetQueryIterator(queryID string) commonledger.ResultsIterator

func (*TransactionContext) GetTotalReturnCount

func (t *TransactionContext) GetTotalReturnCount(queryID string) *int32

func (*TransactionContext) InitializeQueryContext

func (t *TransactionContext) InitializeQueryContext(queryID string, iter commonledger.ResultsIterator)

type TransactionContexts

type TransactionContexts struct {
	// contains filtered or unexported fields
}

TransactionContexts维护处理程序的活动事务上下文。

func NewTransactionContexts

func NewTransactionContexts() *TransactionContexts

NewTransactionContexts为活动事务上下文创建注册表。

func (*TransactionContexts) Close

func (c *TransactionContexts) Close()

关闭关闭与上下文关联的所有查询迭代器。

func (*TransactionContexts) Create

创建为指定链创建新的TransactionContext,并 事务ID。当事务上下文已经 已为指定的链和事务ID创建。

func (*TransactionContexts) Delete

func (c *TransactionContexts) Delete(chainID, txID string)

删除删除与指定链关联的事务上下文 和事务ID。

func (*TransactionContexts) Get

func (c *TransactionContexts) Get(chainID, txID string) *TransactionContext

get检索与链关联的事务上下文,并 事务ID。

type TransactionRegistry

type TransactionRegistry interface {
	Add(channelID, txID string) bool
	Remove(channelID, txID string)
}

TransactionRegistry跟踪每个通道的活动事务。

type UUIDGenerator

type UUIDGenerator interface {
	New() string
}

UuidGenerator负责创建唯一的查询标识符。

type UUIDGeneratorFunc

type UUIDGeneratorFunc func() string

func (UUIDGeneratorFunc) New

func (u UUIDGeneratorFunc) New() string

Directories

Path Synopsis
伪造者生成的代码。
伪造者生成的代码。
lib
cid
mock
伪造者生成的代码。
伪造者生成的代码。
伪造者生成的代码。
伪造者生成的代码。
mock
伪造者生成的代码。
伪造者生成的代码。
car
mock
伪造者生成的代码。
伪造者生成的代码。
包填充程序为链代码提供API以访问其状态 变量、事务上下文和调用其他链码。
包填充程序为链代码提供API以访问其状态 变量、事务上下文和调用其他链码。

Jump to

Keyboard shortcuts

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