-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
task.lessthan.go
50 lines (40 loc) · 1.06 KB
/
task.lessthan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package pipeline
import (
"context"
"github.com/pkg/errors"
"go.uber.org/multierr"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)
// Return types:
//
// bool
type LessThanTask struct {
BaseTask `mapstructure:",squash"`
Left string `json:"input"`
Right string `json:"limit"`
}
var (
_ Task = (*LessThanTask)(nil)
)
func (t *LessThanTask) Type() TaskType {
return TaskTypeLessThan
}
func (t *LessThanTask) Run(_ context.Context, _ logger.Logger, vars Vars, inputs []Result) (result Result, runInfo RunInfo) {
_, err := CheckInputs(inputs, 0, 1, 0)
if err != nil {
return Result{Error: errors.Wrap(err, "task inputs")}, runInfo
}
var (
a DecimalParam
b DecimalParam
)
err = multierr.Combine(
errors.Wrap(ResolveParam(&a, From(VarExpr(t.Left, vars), NonemptyString(t.Left), Input(inputs, 0))), "left"),
errors.Wrap(ResolveParam(&b, From(VarExpr(t.Right, vars), NonemptyString(t.Right))), "right"),
)
if err != nil {
return Result{Error: err}, runInfo
}
value := a.Decimal().LessThan(b.Decimal())
return Result{Value: value}, runInfo
}