Documentation
¶
Index ¶
- func NewFailedResult(ruleName string, violation *interfaces.RuleViolation) interfaces.RuleResult
- func NewPassedResult(ruleName string) interfaces.RuleResult
- func NewRuleViolation(ruleName, message, code string, severity interfaces.ViolationSeverity) *interfaces.RuleViolation
- func ViolationError(v *interfaces.RuleViolation) string
- func ViolationToResponse(v *interfaces.RuleViolation) interfaces.ViolationResponse
- func WithDetail(v *interfaces.RuleViolation, key string, value any) *interfaces.RuleViolation
- func WithMetadata(r interfaces.RuleResult, key string, value any) interfaces.RuleResult
- func WithRemedy(v *interfaces.RuleViolation, remedy string) *interfaces.RuleViolation
- type BaseRule
- func (r *BaseRule) Disable()
- func (r *BaseRule) Enable()
- func (r *BaseRule) GetDescription() string
- func (r *BaseRule) GetName() string
- func (r *BaseRule) GetPriority() int
- func (r *BaseRule) IsEnabled() bool
- func (r *BaseRule) Validate(ctx context.Context, block interfaces.Block) interfaces.RuleResult
- type RegistryMetrics
- type RegistryResult
- type RuleRegistry
- func (r *RuleRegistry) Clear()
- func (r *RuleRegistry) Count() int
- func (r *RuleRegistry) DisableAll()
- func (r *RuleRegistry) DisableRule(name string) error
- func (r *RuleRegistry) EnableAll()
- func (r *RuleRegistry) EnableRule(name string) error
- func (r *RuleRegistry) GetAllRules() []interfaces.ConsensusRule
- func (r *RuleRegistry) GetEnabledRules() []interfaces.ConsensusRule
- func (r *RuleRegistry) GetMetrics() *RegistryMetrics
- func (r *RuleRegistry) GetRule(name string) (interfaces.ConsensusRule, bool)
- func (r *RuleRegistry) GetRuleExecutionCount(name string) uint64
- func (r *RuleRegistry) GetRuleFailureCount(name string) uint64
- func (r *RuleRegistry) GetStopOnFirstFail() bool
- func (r *RuleRegistry) Register(rule interfaces.ConsensusRule) error
- func (r *RuleRegistry) SetStopOnFirstFail(stop bool)
- func (r *RuleRegistry) Unregister(name string) error
- func (r *RuleRegistry) Validate(ctx context.Context, block interfaces.Block) RegistryResult
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) GetDescription ¶
GetDescription returns a human-readable description of the rule
func (*BaseRule) GetPriority ¶
GetPriority returns the execution priority
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) DisableRule ¶
func (r *RuleRegistry) DisableRule(name string) error
DisableRule disables a specific rule
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