blockvisitor

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2021 License: Apache-2.0 Imports: 16 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// LsccID is the ID of the Lifecycle system chaincode
	LsccID = "lscc"
	// CollectionSeparator is used as a separator between the namespace (chaincode ID) and collection name
	CollectionSeparator = "~"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockHandler added in v0.1.6

type BlockHandler func(block *cb.Block) error

BlockHandler publishes blocks

type CCEvent

type CCEvent struct {
	BlockNum uint64
	TxID     string
	TxNum    uint64
	Event    *pb.ChaincodeEvent
}

CCEvent contains all information related to a chaincode Event on the block

type CCEventHandler

type CCEventHandler func(ccEvent *CCEvent) error

CCEventHandler publishes chaincode events

type Category added in v0.1.3

type Category string

Category defines the error category

const (
	// UnmarshalErr indicates that an error occurred while attempting to unmarshal block data
	UnmarshalErr Category = "UNMARSHAL_ERROR"

	// ReadHandlerErr indicates that the read handler returned an error
	ReadHandlerErr Category = "READ_HANDLER_ERROR"

	// WriteHandlerErr indicates that the write handler returned an error
	WriteHandlerErr Category = "WRITE_HANDLER_ERROR"

	// CollHashReadHandlerErr indicates that the collection hash read handler returned an error
	CollHashReadHandlerErr Category = "COLL_HASH_READ_HANDLER_ERROR"

	// CollHashWriteHandlerErr indicates that the collection hash write handler returned an error
	CollHashWriteHandlerErr Category = "COLL_HASH_WRITE_HANDLER_ERROR"

	// LSCCWriteHandlerErr indicates that the LSCC write handler returned an error
	LSCCWriteHandlerErr Category = "LSCCWRITE_HANDLER_ERROR"

	// CCEventHandlerErr indicates that the chaincode event handler returned an error
	CCEventHandlerErr Category = "CCEVENT_HANDLER_ERROR"

	// ConfigUpdateHandlerErr indicates that the configuration update handler returned an error
	ConfigUpdateHandlerErr Category = "CONFIG_UPDATE_HANDLER_ERROR"

	// BlockHandlerErr indicates that the block handler returned an error
	BlockHandlerErr Category = "BLOCK_HANDLER_ERROR"
)

type CollHashRead added in v0.1.4

type CollHashRead struct {
	BlockNum   uint64
	TxID       string
	TxNum      uint64
	Namespace  string
	Collection string
	Read       *kvrwset.KVReadHash
}

CollHashRead contains all information related to a KV collection hash read on the block

type CollHashReadHandler added in v0.1.4

type CollHashReadHandler func(read *CollHashRead) error

CollHashReadHandler publishes KV collection hash read events

type CollHashWrite added in v0.1.4

type CollHashWrite struct {
	BlockNum   uint64
	TxID       string
	TxNum      uint64
	Namespace  string
	Collection string
	Write      *kvrwset.KVWriteHash
}

CollHashWrite contains all information related to a KV collection hash write on the block

type CollHashWriteHandler added in v0.1.4

type CollHashWriteHandler func(write *CollHashWrite) error

CollHashWriteHandler publishes KV collection hash write events

type ConfigUpdate

type ConfigUpdate struct {
	BlockNum     uint64
	ConfigUpdate *cb.ConfigUpdate
}

ConfigUpdate contains all information related to a config-update on the block

type ConfigUpdateHandler

type ConfigUpdateHandler func(update *ConfigUpdate) error

ConfigUpdateHandler publishes config updates

type Context added in v0.1.3

type Context struct {
	Category      Category
	ChannelID     string
	BlockNum      uint64
	TxNum         uint64
	TxID          string
	Read          *Read
	Write         *Write
	CollHashRead  *CollHashRead
	CollHashWrite *CollHashWrite
	CCEvent       *CCEvent
	LSCCWrite     *LSCCWrite
	ConfigUpdate  *ConfigUpdate
}

Context holds the context at the time of a Visitor error

func (*Context) String added in v0.1.3

func (c *Context) String() string

String returns the string representation of Context

type ErrorHandler added in v0.1.3

type ErrorHandler func(err error, ctx *Context) error

ErrorHandler allows clients to handle errors

type Handlers

type Handlers struct {
	HandleCCEvent       CCEventHandler
	HandleRead          ReadHandler
	HandleWrite         WriteHandler
	HandleCollHashRead  CollHashReadHandler
	HandleCollHashWrite CollHashWriteHandler
	HandleLSCCWrite     LSCCWriteHandler
	HandleConfigUpdate  ConfigUpdateHandler
	HandleBlock         BlockHandler
}

Handlers contains the full set of handlers

type LSCCWrite

type LSCCWrite struct {
	BlockNum uint64
	TxID     string
	TxNum    uint64
	CCID     string
	CCData   *ccprovider.ChaincodeData
	CCP      *pb.CollectionConfigPackage
}

LSCCWrite contains all information related to an LSCC write on the block

type LSCCWriteHandler

type LSCCWriteHandler func(lsccWrite *LSCCWrite) error

LSCCWriteHandler publishes LSCC write events

type Opt

type Opt func(options *Options)

Opt is a block visitor option

func WithBlockHandler added in v0.1.6

func WithBlockHandler(handler BlockHandler) Opt

WithBlockHandler sets the block handler

func WithCCEventHandler

func WithCCEventHandler(handler CCEventHandler) Opt

WithCCEventHandler sets the chaincode event handler

func WithCollHashReadHandler added in v0.1.4

func WithCollHashReadHandler(handler CollHashReadHandler) Opt

WithCollHashReadHandler sets the collection hash read handler

func WithCollHashWriteHandler added in v0.1.4

func WithCollHashWriteHandler(handler CollHashWriteHandler) Opt

WithCollHashWriteHandler sets the collection hash write handler

func WithConfigUpdateHandler

func WithConfigUpdateHandler(handler ConfigUpdateHandler) Opt

WithConfigUpdateHandler sets the config-update handler

func WithErrorHandler added in v0.1.3

func WithErrorHandler(handler ErrorHandler) Opt

WithErrorHandler provides an error handler that's invoked when an error occurs in one of the handlers.

func WithLSCCWriteHandler

func WithLSCCWriteHandler(handler LSCCWriteHandler) Opt

WithLSCCWriteHandler sets the LSCC write handler

func WithReadHandler

func WithReadHandler(handler ReadHandler) Opt

WithReadHandler sets the read handler

func WithWriteHandler

func WithWriteHandler(handler WriteHandler) Opt

WithWriteHandler sets the write handler

type Options

type Options struct {
	*Handlers
	HandleError ErrorHandler
}

Options contains all block Visitor options

type Read

type Read struct {
	BlockNum  uint64
	TxID      string
	TxNum     uint64
	Namespace string
	Read      *kvrwset.KVRead
}

Read contains all information related to a KV read on the block

type ReadHandler

type ReadHandler func(read *Read) error

ReadHandler publishes KV read events

type Visitor

type Visitor struct {
	*Options
	// contains filtered or unexported fields
}

Visitor traverses a block and publishes KV Read, KV Write, LSCC write, and chaincode events to registered handlers

func New

func New(channelID string, opts ...Opt) *Visitor

New returns a new block Visitor for the given channel

func (*Visitor) ChannelID

func (p *Visitor) ChannelID() string

ChannelID returns the channel ID for the vistor

func (*Visitor) LedgerHeight

func (p *Visitor) LedgerHeight() uint64

LedgerHeight returns ledger height based on last block published

func (*Visitor) SetLastCommittedBlockNum added in v0.1.1

func (p *Visitor) SetLastCommittedBlockNum(blockNum uint64)

SetLastCommittedBlockNum initializes the visitor with the given block number - only if the given block number is greater than the current last committed block number.

func (*Visitor) Visit

func (p *Visitor) Visit(block *cb.Block, pvtData ledger.TxPvtDataMap) error

Visit traverses the given block and invokes the applicable handlers

type Write

type Write struct {
	BlockNum  uint64
	TxID      string
	TxNum     uint64
	Namespace string
	Write     *kvrwset.KVWrite
}

Write contains all information related to a KV write on the block

type WriteHandler

type WriteHandler func(write *Write) error

WriteHandler publishes KV write events

Jump to

Keyboard shortcuts

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