rules

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFailedResult

func NewFailedResult(ruleName string, violation *interfaces.RuleViolation) interfaces.RuleResult

NewFailedResult creates a result for a failed rule validation

func NewPassedResult

func NewPassedResult(ruleName string) interfaces.RuleResult

NewPassedResult creates a result for a passed rule validation

func NewRuleViolation

func NewRuleViolation(ruleName, message, code string, severity interfaces.ViolationSeverity) *interfaces.RuleViolation

NewRuleViolation creates a new rule violation

func ViolationError

func ViolationError(v *interfaces.RuleViolation) string

ViolationError returns the violation as an error string

func ViolationToResponse

func ViolationToResponse(v *interfaces.RuleViolation) interfaces.ViolationResponse

ViolationToResponse converts a violation to a violation response

func WithDetail

func WithDetail(v *interfaces.RuleViolation, key string, value any) *interfaces.RuleViolation

WithDetail adds a detail to the violation

func WithMetadata

func WithMetadata(r interfaces.RuleResult, key string, value any) interfaces.RuleResult

WithMetadata adds metadata to a rule result

func WithRemedy

func WithRemedy(v *interfaces.RuleViolation, remedy string) *interfaces.RuleViolation

WithRemedy adds a remedy suggestion

Types

type BaseRule

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

BaseRule provides a basic implementation of ConsensusRule

func NewBaseRule

func NewBaseRule(name, description string, priority int, validator func(ctx context.Context, block interfaces.Block) interfaces.RuleResult) *BaseRule

NewBaseRule creates a new base rule

func (*BaseRule) Disable

func (r *BaseRule) Disable()

Disable deactivates this rule

func (*BaseRule) Enable

func (r *BaseRule) Enable()

Enable activates this rule

func (*BaseRule) GetDescription

func (r *BaseRule) GetDescription() string

GetDescription returns a human-readable description of the rule

func (*BaseRule) GetName

func (r *BaseRule) GetName() string

GetName returns the rule's unique identifier

func (*BaseRule) GetPriority

func (r *BaseRule) GetPriority() int

GetPriority returns the execution priority

func (*BaseRule) IsEnabled

func (r *BaseRule) IsEnabled() bool

IsEnabled returns whether this rule is currently active

func (*BaseRule) Validate

func (r *BaseRule) Validate(ctx context.Context, block interfaces.Block) interfaces.RuleResult

Validate checks if a block satisfies this rule

type RegistryMetrics

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

RegistryMetrics tracks rule execution statistics

func NewRegistryMetrics

func NewRegistryMetrics() *RegistryMetrics

NewRegistryMetrics creates new registry metrics

type RegistryResult

type RegistryResult struct {
	// Passed indicates if all rules passed
	Passed bool

	// RuleResults contains individual rule results
	RuleResults []interfaces.RuleResult

	// Violations contains all violations that occurred
	Violations []*interfaces.RuleViolation

	// Responses contains recommended responses for violations
	Responses []interfaces.ViolationResponse

	// ExecutedRuleCount is the number of rules that were executed
	ExecutedRuleCount int

	// SkippedRuleCount is the number of rules that were skipped
	SkippedRuleCount int
}

RegistryResult contains the results of validating against all rules

type RuleRegistry

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

RuleRegistry manages consensus rules with registration and execution

func NewRuleRegistry

func NewRuleRegistry() *RuleRegistry

NewRuleRegistry creates a new rule registry

func (*RuleRegistry) Clear

func (r *RuleRegistry) Clear()

Clear removes all rules from the registry

func (*RuleRegistry) Count

func (r *RuleRegistry) Count() int

Count returns the number of registered rules

func (*RuleRegistry) DisableAll

func (r *RuleRegistry) DisableAll()

DisableAll disables all rules

func (*RuleRegistry) DisableRule

func (r *RuleRegistry) DisableRule(name string) error

DisableRule disables a specific rule

func (*RuleRegistry) EnableAll

func (r *RuleRegistry) EnableAll()

EnableAll enables all rules

func (*RuleRegistry) EnableRule

func (r *RuleRegistry) EnableRule(name string) error

EnableRule enables a specific rule

func (*RuleRegistry) GetAllRules

func (r *RuleRegistry) GetAllRules() []interfaces.ConsensusRule

GetAllRules returns all registered rules

func (*RuleRegistry) GetEnabledRules

func (r *RuleRegistry) GetEnabledRules() []interfaces.ConsensusRule

GetEnabledRules returns all enabled rules

func (*RuleRegistry) GetMetrics

func (r *RuleRegistry) GetMetrics() *RegistryMetrics

GetMetrics returns registry metrics

func (*RuleRegistry) GetRule

func (r *RuleRegistry) GetRule(name string) (interfaces.ConsensusRule, bool)

GetRule retrieves a rule by name

func (*RuleRegistry) GetRuleExecutionCount

func (r *RuleRegistry) GetRuleExecutionCount(name string) uint64

GetRuleExecutionCount returns the execution count for a specific rule

func (*RuleRegistry) GetRuleFailureCount

func (r *RuleRegistry) GetRuleFailureCount(name string) uint64

GetRuleFailureCount returns the failure count for a specific rule

func (*RuleRegistry) GetStopOnFirstFail

func (r *RuleRegistry) GetStopOnFirstFail() bool

GetStopOnFirstFail returns whether validation stops on first failure

func (*RuleRegistry) Register

func (r *RuleRegistry) Register(rule interfaces.ConsensusRule) error

Register adds a rule to the registry

func (*RuleRegistry) SetStopOnFirstFail

func (r *RuleRegistry) SetStopOnFirstFail(stop bool)

SetStopOnFirstFail sets whether to stop validation on first failure

func (*RuleRegistry) Unregister

func (r *RuleRegistry) Unregister(name string) error

Unregister removes a rule from the registry

func (*RuleRegistry) Validate

func (r *RuleRegistry) Validate(ctx context.Context, block interfaces.Block) RegistryResult

Validate validates a block against all registered rules

Jump to

Keyboard shortcuts

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