Documentation
¶
Overview ¶
Package rule provides a set of rules for filtering transactions.
Index ¶
- Constants
- Variables
- func CheckRule(raw string) error
- func CompareRules(mr string, sr string) bool
- func CopyTx(src *common.Transaction) *common.Transaction
- func LoadNotEquals(cs []*Converge) [][]string
- func NewRandomString(length int) string
- func NewTx() *common.Transaction
- func SetContracts(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
- func SetIds(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
- func SetOrgs(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
- func SetTxIds(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
- func SetTxTypes(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
- type ArrayIdent
- type ContainOfFunc
- type ContractMatcher
- type Converge
- func (r *Converge) AppendContract(op, contract string)
- func (r *Converge) AppendId(op, id string)
- func (r *Converge) AppendOrg(op, org string)
- func (r *Converge) AppendTxId(op, txId string)
- func (r *Converge) AppendTxType(op, txType string)
- func (r *Converge) Copy() *Converge
- func (r *Converge) Merge(rd *Converge) *Converge
- func (r *Converge) ToDatas() []*common.Transaction
- func (r *Converge) ToDatasWithNotEqual(neps [][]string) []*common.Transaction
- func (r *Converge) ToString() string
- type ErrIdent
- type ErrKind
- type ErrStatement
- type ErrToken
- type FunNameIdent
- type FuncArgIdent
- type FuncIdent
- type IdentityMatcher
- type InArrayFunc
- type LabelIdent
- type LeafIdent
- type LeafOperator
- type NormalizedLabel
- type OrgMatcher
- type RegMatcher
- type Specification
- type TxIDMatcher
- type TxMatcher
- type TxSpecification
- type TxSpecificationFunc
- type TxTypeMatcher
- type ValueIdent
Constants ¶
const ( // FuncContainsOf the token of function contain_of FuncContainsOf = "contain_of" // FuncInArray the token of function in_array FuncInArray = "in_array" )
const ( // KeyEqual macro for == KeyEqual = "==" // KeyNotEqual macro for != KeyNotEqual = "!=" // KeyContains macro for %= KeyContains = "%=" // DefaultLength default length of random string DefaultLength = 16 // PartLength default length. PartLength = 3 )
const ( // Letters for random string. Letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" // ExpandFactor is the number of times to expand the rule ExpandFactor = 1 )
Variables ¶
Functions ¶
func CheckRule ¶
CheckRule validates a given rule string and returns an error if it is invalid.
func CompareRules ¶
CompareRules Compare two rules mr: rule corresponding to local node sr: rule corresponding to remote node return: true if mr contains sr
func CopyTx ¶
func CopyTx(src *common.Transaction) *common.Transaction
CopyTx Duplicate a transaction, copying only the fields of interest.
func LoadNotEquals ¶
LoadNotEquals load not equals conditions
func NewRandomString ¶
NewRandomString Create a random string of specified length
func NewTx ¶
func NewTx() *common.Transaction
NewTx Create a transaction, mainly to initialize some fields in the transaction.
func SetContracts ¶
func SetContracts(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
SetContracts Generate a transaction set based on the input 'baseDatas' and the 'contracts' rules. The transaction set includes all parts corresponding to the CONTRACT properties.
func SetIds ¶
func SetIds(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
SetIds Generate a transaction set based on the input 'baseDatas' and the 'ids' rules. The transaction set includes all parts corresponding to the ID properties.
func SetOrgs ¶
func SetOrgs(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
SetOrgs Generate a transaction set based on the input 'baseDatas' and the 'orgs' rules. The transaction set includes all parts corresponding to the ORG properties.
func SetTxIds ¶
func SetTxIds(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
SetTxIds Generate a transaction set based on the input 'baseDatas' and the 'txIds' rules. The transaction set includes all parts corresponding to the TXID properties.
func SetTxTypes ¶
func SetTxTypes(r *Converge, baseDatas []*common.Transaction, nes []string) []*common.Transaction
SetTxTypes Generate a transaction set based on the input 'baseDatas' and the 'txTypes' rules. The transaction set includes all parts corresponding to the TXTYPE properties.
Types ¶
type ArrayIdent ¶
type ArrayIdent struct {
// contains filtered or unexported fields
}
ArrayIdent is a array expression.
func (*ArrayIdent) Check ¶
func (i *ArrayIdent) Check() error
Check checks if the array expression is valid.
type ContainOfFunc ¶
type ContainOfFunc struct {
// contains filtered or unexported fields
}
ContainOfFunc the function of contain_of.
func (*ContainOfFunc) Check ¶
func (l *ContainOfFunc) Check() error
Check check for grammatical errors
func (*ContainOfFunc) Parse ¶
func (l *ContainOfFunc) Parse() (TxSpecification, error)
Parse the ContainOfFunc to TxSpecification
type ContractMatcher ¶
type ContractMatcher struct {
// contains filtered or unexported fields
}
ContractMatcher the matcher used to match the contract.
func (*ContractMatcher) MatchTx ¶
func (m *ContractMatcher) MatchTx(tx *common.Transaction) bool
MatchTx determines if a given transaction matches the contract name or contract name and method as specified by the ContractMatcher's matcher.
tx: A pointer to a common.Transaction object representing a transaction. bool: A boolean value indicating if the transaction matches the contract name or contract name and method.
type Converge ¶
type Converge struct {
Orgs map[string][]string
Ids map[string][]string
TxTypes map[string][]string
TxIds map[string][]string
Contracts map[string][]string
}
Converge This is a rule definition parsed from ast.Expr. There is an 'OR' relationship between different Converges, while there is an 'AND' relationship between fields within the same Converge.
func Parse2Converges ¶
Parse2Converges transforms expr into a collection of Converge
func (*Converge) AppendContract ¶
AppendContract append contract name data
func (*Converge) AppendId ¶
AppendId append identity data
func (*Converge) AppendTxId ¶
AppendTxId append transaction id data
func (*Converge) AppendTxType ¶
AppendTxType append transaction type data
func (*Converge) Copy ¶
Copy copy a new Converge, it is important to note that all fields in the new Converge are deep copied.
func (*Converge) Merge ¶
Merge Merge two Converge together.
func (*Converge) ToDatas ¶
func (r *Converge) ToDatas() []*common.Transaction
ToDatas Convert Converge to a transaction set. For each Converge, it may generate multiple transaction records depending on its rule attribute settings. In general, the inclusion property will affect the generation of multiple records, while the equal and not equal properties will not.
func (*Converge) ToDatasWithNotEqual ¶
func (r *Converge) ToDatasWithNotEqual(neps [][]string) []*common.Transaction
ToDatasWithNotEqual Convert Converge to a transaction set. This method is different from ToDatas. It has an input called 'neps', which suggests the equal value when generating transaction data, mainly used for comparison. However, it should be noted that compared to 'neps', one's own not equal permission is higher.
type ErrIdent ¶
type ErrIdent struct {
// contains filtered or unexported fields
}
ErrIdent represents an error caused by an invalid label.
type ErrKind ¶
type ErrKind struct {
// contains filtered or unexported fields
}
ErrKind represents an error caused by an invalid token.
type ErrStatement ¶
type ErrStatement struct {
// contains filtered or unexported fields
}
ErrStatement is a custom error type that represents a problem with a statement.
func (ErrStatement) Error ¶
func (r ErrStatement) Error() string
Error returns the error message for ErrStatement.
type ErrToken ¶
type ErrToken struct {
// contains filtered or unexported fields
}
ErrToken represents an error type for invalid tokens in a lexer.
type FunNameIdent ¶
FunNameIdent the ident of function name.
func (*FunNameIdent) Check ¶
func (l *FunNameIdent) Check() error
Check check for grammatical errors.
type FuncArgIdent ¶
type FuncArgIdent struct {
// contains filtered or unexported fields
}
FuncArgIdent the ident of function argument.
type FuncIdent ¶
FuncIdent function ident.
func (FuncIdent) Parse ¶
func (l FuncIdent) Parse() (TxSpecification, error)
Parse the FuncIdent to TxSpecification.
type IdentityMatcher ¶
type IdentityMatcher struct {
// contains filtered or unexported fields
}
IdentityMatcher the matcher used to match the identity.
func (*IdentityMatcher) MatchTx ¶
func (m *IdentityMatcher) MatchTx(tx *common.Transaction) bool
MatchTx checks if the given transaction matches the identity matcher.
tx: pointer to common.Transaction that needs to be matched returns a boolean indicating if the transaction matches or not
type InArrayFunc ¶
type InArrayFunc struct {
// contains filtered or unexported fields
}
InArrayFunc the function of in_array
func (*InArrayFunc) Parse ¶
func (l *InArrayFunc) Parse() (TxSpecification, error)
Parse the InArrayFunc to TxSpecification
type LabelIdent ¶
LabelIdent is the rule lable.
func (*LabelIdent) Check ¶
func (l *LabelIdent) Check() error
Check checks if the rule lable is a legal lable(such as O, I, C, TT, TD)
type LeafIdent ¶
type LeafIdent ast.BinaryExpr
LeafIdent is a leaf expression, such as O=="ORG1", 'O' is the rule lable, '==' is the operator, 'ORG1' is the value.
func (*LeafIdent) Check ¶
Check checks if the leaf expression is valid. Such as O=="ORG1", 'O' is the rule lable, '==' is the operator, 'ORG1' is the value.
func (*LeafIdent) Parse ¶
func (l *LeafIdent) Parse() (TxSpecification, error)
Parse parses the leaf expression to TxSpecification.
type LeafOperator ¶
type LeafOperator struct {
// contains filtered or unexported fields
}
LeafOperator is a leaf operator, such as O=="ORG1", '==' is the operator
func (LeafOperator) Check ¶
func (l LeafOperator) Check() error
Check checks if the leaf operator is valid.
type NormalizedLabel ¶
type NormalizedLabel string
NormalizedLabel is a normalized label.
const ( ORG_LABEL NormalizedLabel = "O" ID_LABEL NormalizedLabel = "I" TX_TYPE_LABEL NormalizedLabel = "TT" TX_ID_LABEL NormalizedLabel = "TD" CONTRACT_LABEL NormalizedLabel = "C" )
组织:O,身份:I,交易类型:TT,交易ID:TD, 合约:C
func (NormalizedLabel) String ¶
func (l NormalizedLabel) String() string
String returns the string representation of the NormalizedLabel.
type OrgMatcher ¶
type OrgMatcher struct {
// contains filtered or unexported fields
}
OrgMatcher the matcher used to match the order label.
func (*OrgMatcher) MatchTx ¶
func (m *OrgMatcher) MatchTx(tx *common.Transaction) bool
MatchTx checks if the organization ID of the transaction sender matches the pattern specified in the OrgMatcher.
tx: A pointer to a common.Transaction object. Returns a boolean value representing whether the organization ID matches or not.
type RegMatcher ¶
type RegMatcher struct {
// contains filtered or unexported fields
}
RegMatcher is a struct used to match regular expressions.
func (*RegMatcher) MatchV ¶
func (r *RegMatcher) MatchV(v interface{}) bool
MatchV checks if the given interface is a string and matches the regular expression defined in the RegMatcher struct.
v: The interface to be checked. bool: Returns true if the interface is a string and matches the regular expression.
type Specification ¶
type Specification struct {
// contains filtered or unexported fields
}
Specification is a TxSpecification interface implementation. Specification only implement logic operations.
func (*Specification) IsSpecifiedTx ¶
func (s *Specification) IsSpecifiedTx(tx *common.Transaction) bool
IsSpecifiedTx checks if the provided transaction matches the specification. tx: *common.Transaction - the transaction to check. bool - returns true if the transaction matches the specification,
type TxIDMatcher ¶
type TxIDMatcher struct {
// contains filtered or unexported fields
}
TxIDMatcher the matcher used to match the transaction ID.
func (*TxIDMatcher) MatchTx ¶
func (m *TxIDMatcher) MatchTx(tx *common.Transaction) bool
MatchTx is a function that takes a pointer to a TxIDMatcher struct and a pointer to a common Transaction struct as its parameters. It returns a bool value. The function matches the transaction ID of the specified transaction using the matcher.MatchV method.
type TxMatcher ¶
type TxMatcher interface {
MatchTx(tx *common.Transaction) bool
}
TxMatcher is the interface used to match transaction.
type TxSpecification ¶
type TxSpecification interface {
// IsSpecifiedTx checks if a given transaction meets the specification
IsSpecifiedTx(*common.Transaction) bool
// contains filtered or unexported methods
}
TxSpecification is an interface for transaction specifications
func ParseRule ¶
func ParseRule(raw string) (TxSpecification, error)
ParseRule parses a string and returns a TxSpecification or an error.
type TxSpecificationFunc ¶
type TxSpecificationFunc func(*common.Transaction) bool
TxSpecificationFunc is a function type that implements TxSpecification interface.
func (TxSpecificationFunc) IsSpecifiedTx ¶
func (f TxSpecificationFunc) IsSpecifiedTx(tx *common.Transaction) bool
IsSpecifiedTx wrapper function call implements IsSpecifiedTx interface function.
type TxTypeMatcher ¶
type TxTypeMatcher struct {
// contains filtered or unexported fields
}
TxTypeMatcher the matcher used to match the transaction type.
func (*TxTypeMatcher) MatchTx ¶
func (m *TxTypeMatcher) MatchTx(tx *common.Transaction) bool
MatchTx returns true if the payload of the given transaction matches the TxTypeMatcher.
tx: A pointer to a common.Transaction struct. bool: A boolean indicating whether the transaction's payload matches the TxTypeMatcher.
type ValueIdent ¶
ValueIdent is the value of the leaf expression
func (*ValueIdent) Check ¶
func (l *ValueIdent) Check() error
Check checks if the type of the value is supported.
func (*ValueIdent) Parse ¶
func (l *ValueIdent) Parse() (interface{}, error)
Parse the value according to the type.
Source Files
¶
- error.go
- function.go
- parser.go
- rule.go
- rule_data.go
- rule_func.go
- rule_util.go
- types.go