// Evaluate evaluates if witness policy has been satisfied for provided witnesses.
Evaluate evaluates if witness policy has been satisfied for provided witnesses.
// Evaluate evaluates if witness policy has been satisfied for provided witnesses .
func (wp *WitnessPolicy) Evaluate(witnesses []*proof.WitnessProof) (bool, error) {
	cfg, err := wp.getWitnessPolicyConfig()
	if err != nil {
		return false, err
	}
	totalSystemWitnesses := 0
	collectedSystemWitnesses := 0
	totalBatchWitnesses := 0
	collectedBatchWitnesses := 0
	for _, w := range witnesses {
		logOK := checkLog(cfg.LogRequired, w.HasLog)
		switch w.Type {
		case proof.WitnessTypeBatch:
			totalBatchWitnesses++
			if logOK && w.Proof != nil {
				collectedBatchWitnesses++
			}
		case proof.WitnessTypeSystem:
			totalSystemWitnesses++
			if logOK && w.Proof != nil {
				collectedSystemWitnesses++
			}
		}
	}
	batchCondition := evaluate(collectedBatchWitnesses, totalBatchWitnesses, cfg.MinNumberBatch, cfg.MinPercentBatch)
	systemCondition := evaluate(collectedSystemWitnesses, totalSystemWitnesses, cfg.MinNumberSystem, cfg.MinPercentSystem)
	evaluated := cfg.OperatorFnc(batchCondition, systemCondition)
	logger.Debugf("witness policy[%s] evaluated to[%t] with batch[%t] and system[%t] for witnesses: %s",
		cfg, evaluated, batchCondition, systemCondition, witnesses)
	return evaluated, nil
}
func ( wp * WitnessPolicy ) Evaluate ( witnesses [ ] * proof . WitnessProof ) ( bool , error ) { cfg , err := wp . getWitnessPolicyConfig ( ) if err != nil { return false , err } totalSystemWitnesses := 0 collectedSystemWitnesses := 0 totalBatchWitnesses := 0 collectedBatchWitnesses := 0 for _ , w := range witnesses { logOK := checkLog ( cfg . LogRequired , w . HasLog ) switch w . Type { case proof . WitnessTypeBatch : totalBatchWitnesses ++ if logOK && w . Proof != nil { collectedBatchWitnesses ++ } case proof . WitnessTypeSystem : totalSystemWitnesses ++ if logOK && w . Proof != nil { collectedSystemWitnesses ++ } } } batchCondition := evaluate ( collectedBatchWitnesses , totalBatchWitnesses , cfg . MinNumberBatch , cfg . MinPercentBatch ) systemCondition := evaluate ( collectedSystemWitnesses , totalSystemWitnesses , cfg . MinNumberSystem , cfg . MinPercentSystem ) evaluated := cfg . OperatorFnc ( batchCondition , systemCondition ) logger . Debugf ( " " , cfg , evaluated , batchCondition , systemCondition , witnesses ) return evaluated , nil }
Evaluate evaluates if witness policy has been satisfied for provided witnesses.
Evaluate evaluates if witness policy has been satisfied for provided witnesses .