Skip to content

Commit

Permalink
Extract common
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanTinianov committed Dec 13, 2023
1 parent dd05367 commit 54962a4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 42 deletions.
4 changes: 4 additions & 0 deletions core/services/pipeline/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (

type Spec = common.Spec

func SpecPipeline(s Spec) (*Pipeline, error) {
return Parse(s.DotDagSource)
}

type Run struct {
ID int64 `json:"-"`
PipelineSpecID int32 `json:"-"`
Expand Down
2 changes: 1 addition & 1 deletion core/services/vrf/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *Delegate) ServicesForSpec(jb job.Job) ([]job.ServiceCtx, error) {
if jb.VRFSpec == nil || jb.PipelineSpec == nil {
return nil, errors.Errorf("vrf.Delegate expects a VRFSpec and PipelineSpec to be present, got %+v", jb)
}
pl, err := jb.PipelineSpec.Pipeline()
pl, err := pipeline.SpecPipeline(*jb.PipelineSpec)
if err != nil {
return nil, err
}
Expand Down
43 changes: 2 additions & 41 deletions core/store/models/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/tidwall/gjson"
"go.uber.org/multierr"

"github.com/smartcontractkit/chainlink-common/pkg/utils"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)
Expand Down Expand Up @@ -311,7 +312,7 @@ func (d *Duration) UnmarshalText(input []byte) error {
}

// Interval represents a time.Duration stored as a Postgres interval type
type Interval time.Duration
type Interval = utils.Interval

// NewInterval creates Interval for specified duration
func NewInterval(d time.Duration) *Interval {
Expand All @@ -320,46 +321,6 @@ func NewInterval(d time.Duration) *Interval {
return i
}

func (i Interval) Duration() time.Duration {
return time.Duration(i)
}

// MarshalText implements the text.Marshaler interface.
func (i Interval) MarshalText() ([]byte, error) {
return []byte(time.Duration(i).String()), nil
}

// UnmarshalText implements the text.Unmarshaler interface.
func (i *Interval) UnmarshalText(input []byte) error {
v, err := time.ParseDuration(string(input))
if err != nil {
return err
}
*i = Interval(v)
return nil
}

func (i *Interval) Scan(v interface{}) error {
if v == nil {
*i = Interval(time.Duration(0))
return nil
}
asInt64, is := v.(int64)
if !is {
return errors.Errorf("models.Interval#Scan() wanted int64, got %T", v)
}
*i = Interval(time.Duration(asInt64) * time.Nanosecond)
return nil
}

func (i Interval) Value() (driver.Value, error) {
return time.Duration(i).Nanoseconds(), nil
}

func (i Interval) IsZero() bool {
return time.Duration(i) == time.Duration(0)
}

// SendEtherRequest represents a request to transfer ETH.
type SendEtherRequest struct {
DestinationAddress common.Address `json:"address"`
Expand Down

0 comments on commit 54962a4

Please sign in to comment.