burrow event query

Query

Matches() is used to decide if query match tag, which we just disscuss above.

type Query interface {
	Matches(tags Tagged) bool
	String() string
	MatchError() error
}

implements:

Empty
EventID
PegQuery

Now EventID is only used to Query For TxExecution.
PegQuery is flexible that we can query with peg grammar like python.
Empty is used to pass when queryString is empty.

func NewOrEmpty(queryString string) (Query, error) {
	if isEmpty(queryString) {
		return Empty{}, nil
	}
	return New(queryString)
}

EventID is simple to as example:

type EventID string

func (eid EventID) Matches(tags query.Tagged) bool {
	value, ok := tags.Get(EventIDKey)
	if !ok {
		return false
	}
	return string(eid) == value
}

func (eid EventID) String() string {
	return fmt.Sprintf("%s = %s", EventIDKey, string(eid))
}

func (eid EventID) MatchError() error {
	return nil
}

Queryable

type Queryable interface {
	Query() (Query, error)
}

implements:

Builder
Empty
EventClass
PegQuery
String
parsedQuery

Tag

type Tagged interface {
	Get(key string) (value interface{}, ok bool)
}

It has many implements:

Account
BlockExecution
CombinedTags
names.Entry
Envelope
Event
EventSpec
LogEvent
StreamEvent
Tx
TxExecution
TagMap
taggedPrefix

Keys of Tagged.Get()

const (
	EventTypeKey   = "EventType"
	EventIDKey     = "EventID"
	MessageTypeKey = "MessageType"
	TxHashKey      = "TxHash"
	HeightKey      = "Height"
	IndexKey       = "Index"
	StackDepthKey  = "StackDepth"
	AddressKey     = "Address"
)


Event ID Key
// block 
func EventStringBlockExecution(height uint64) string { return fmt.Sprintf("Execution/Block/%v", height) }

// tx
func EventStringTxExecution(txHash []byte) string { return fmt.Sprintf("Execution/Tx/%X", txHash) }

// txe events
func EventStringAccountInput(addr crypto.Address) string  { return fmt.Sprintf("Acc/%s/Input", addr) }
func EventStringAccountOutput(addr crypto.Address) string { return fmt.Sprintf("Acc/%s/Output", addr) }

func EventStringAccountCall(addr crypto.Address) string    { return fmt.Sprintf("Acc/%s/Call", addr) }
func EventStringLogEvent(addr crypto.Address) string       { return fmt.Sprintf("Log/%s", addr) }
func EventStringTxExecution(txHash []byte) string          { return fmt.Sprintf("Execution/Tx/%X", txHash) }
func EventStringGovernAccount(addr *crypto.Address) string { return fmt.Sprintf("Govern/Acc/%v", addr) }

// log event
const LogNKeyPrefix = "Log"
func LogNKey(topic int) string {
	return fmt.Sprintf("%s%d", LogNKeyPrefix, topic)
}
func LogNTextKey(topic int) string {
	return fmt.Sprintf("%s%dText", LogNKeyPrefix, topic)
}

Event Type Key
// Execution event types
const (
	TypeUnknown EventType = iota
	TypeCall
	TypeLog
	TypeAccountInput
	TypeAccountOutput
	TypeTxExecution
	TypeBlockExecution
	TypeGovernAccount
	TypeBeginBlock
	TypeBeginTx
	TypeEnvelope
	TypeEndTx
	TypeEndBlock
)

你可能感兴趣的:(burrow)