Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract core/store/models #11626

Merged
merged 31 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7f86b70
Extract URL
DylanTinianov Dec 19, 2023
8647fcd
tidy
DylanTinianov Dec 19, 2023
556b663
Extract duration tests
DylanTinianov Dec 19, 2023
3b595bc
Generate
DylanTinianov Dec 19, 2023
d9aaaaf
update imports
DylanTinianov Dec 19, 2023
f70c1a8
Extract duration to common
DylanTinianov Dec 21, 2023
e98bd92
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Dec 21, 2023
31e437e
tidy
DylanTinianov Dec 21, 2023
1f3a2d6
fix imports
DylanTinianov Dec 21, 2023
e8c14bd
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Dec 22, 2023
15472ea
tidy
DylanTinianov Dec 22, 2023
8ffd821
remove unused import
DylanTinianov Dec 22, 2023
4989dc4
Remove unused mock file
DylanTinianov Dec 22, 2023
ccfb274
fix imports
DylanTinianov Dec 22, 2023
83b6ad1
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 4, 2024
3e14488
Use commonconfig Duration
DylanTinianov Jan 4, 2024
f6b7170
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 4, 2024
365c127
Use commonconfig
DylanTinianov Jan 4, 2024
49c1fb2
Use commonconfig
DylanTinianov Jan 4, 2024
5054c05
Use MustNewDuration
DylanTinianov Jan 4, 2024
4adfa52
use commonconfig
DylanTinianov Jan 4, 2024
5c0d520
fix imports
DylanTinianov Jan 4, 2024
4f43418
fix imports
DylanTinianov Jan 4, 2024
c0b6d02
fmt
DylanTinianov Jan 4, 2024
c5d9272
Use common url
DylanTinianov Jan 4, 2024
3316e7c
fix imports
DylanTinianov Jan 5, 2024
e956d6b
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 5, 2024
64cc1bb
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 8, 2024
8ee1d45
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 10, 2024
0a6e88a
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 10, 2024
1df30a5
Merge branch 'develop' into BCI-2531-extract-core-store-models
DylanTinianov Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/txmgr/confirmer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/chains/label"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/utils"
commonhex "github.com/smartcontractkit/chainlink-common/pkg/utils/hex"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"

"github.com/smartcontractkit/chainlink/v2/common/client"
Expand Down Expand Up @@ -869,7 +869,7 @@ func (ec *Confirmer[CHAIN_ID, HEAD, ADDR, TX_HASH, BLOCK_HASH, R, SEQ, FEE]) han
lggr.Criticalw("Invariant violation: fatal error while re-attempting transaction",
"fee", attempt.TxFee,
"feeLimit", etx.FeeLimit,
"signedRawTx", utils.EnsureHexPrefix(hex.EncodeToString(attempt.SignedRawTx)),
"signedRawTx", commonhex.EnsurePrefix(hex.EncodeToString(attempt.SignedRawTx)),
"blockHeight", blockHeight,
)
ec.SvcErrBuffer.Append(sendError)
Expand Down
6 changes: 3 additions & 3 deletions core/chains/evm/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

configurl "github.com/smartcontractkit/chainlink-common/pkg/config"
commonconfig "github.com/smartcontractkit/chainlink/v2/common/config"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func TestChainScopedConfig(t *testing.T) {
Expand Down Expand Up @@ -383,8 +383,8 @@ func Test_chainScopedConfig_Validate(t *testing.T) {
c.EVM[0] = &toml.EVMConfig{ChainID: chainID, Enabled: ptr(true), Chain: toml.Defaults(chainID, chains...),
Nodes: toml.EVMNodes{{
Name: ptr("fake"),
WSURL: models.MustParseURL("wss://foo.test/ws"),
HTTPURL: models.MustParseURL("http://foo.test"),
WSURL: configurl.MustParseURL("wss://foo.test/ws"),
HTTPURL: configurl.MustParseURL("http://foo.test"),
}}}
})
}
Expand Down
7 changes: 4 additions & 3 deletions core/chains/evm/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"gopkg.in/guregu/null.v4"

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/models"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink/v2/common/config"
Expand All @@ -21,7 +23,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
configutils "github.com/smartcontractkit/chainlink/v2/core/utils/config"
)

Expand Down Expand Up @@ -742,8 +743,8 @@ func (o *OCR) setFrom(f *OCR) {

type Node struct {
Name *string
WSURL *models.URL
HTTPURL *models.URL
WSURL *commonconfig.URL
HTTPURL *commonconfig.URL
SendOnly *bool
Order *int32
}
Expand Down
3 changes: 2 additions & 1 deletion core/chains/evm/headtracker/head_broadcaster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/models"
"github.com/smartcontractkit/chainlink-common/pkg/services/servicetest"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"

commonhtrk "github.com/smartcontractkit/chainlink/v2/common/headtracker"
commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
Expand All @@ -25,7 +27,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/headtracker/head_listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/stretchr/testify/mock"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/models"
commonmocks "github.com/smartcontractkit/chainlink/v2/common/types/mocks"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/headtracker"
evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types"
Expand All @@ -21,7 +22,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/configtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func Test_HeadListener_HappyPath(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/headtracker/head_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/jmoiron/sqlx"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/models"
"github.com/smartcontractkit/chainlink-common/pkg/services"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox"
"github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox/mailboxtest"
Expand All @@ -37,7 +38,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"
)

Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/evm_tx_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/models"
txmgrcommon "github.com/smartcontractkit/chainlink/v2/common/txmgr"
txmgrtypes "github.com/smartcontractkit/chainlink/v2/common/txmgr/types"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
Expand All @@ -22,7 +23,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/pg"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
"github.com/smartcontractkit/chainlink/v2/core/utils"

"github.com/google/uuid"
Expand Down
2 changes: 1 addition & 1 deletion core/chains/evm/txmgr/resender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/models"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr"
ubig "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
Expand All @@ -23,7 +24,6 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/evmtest"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func Test_EthResender_resendUnconfirmed(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ require (
github.com/shirou/gopsutil/v3 v3.23.11 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218160643-bd451bb2dd94 // indirect
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231219184921-07a83946dc39 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20231127231053-2232d3a6766d // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1148,8 +1148,8 @@ github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704 h1:T3lFWumv
github.com/smartcontractkit/caigo v0.0.0-20230621050857-b29a4ca8c704/go.mod h1:2QuJdEouTWjh5BDy5o/vgGXQtR4Gz8yH1IYB5eT7u4M=
github.com/smartcontractkit/chainlink-automation v1.0.1 h1:vVjBFq2Zsz21kPy1Pb0wpjF9zrbJX+zjXphDeeR4XZk=
github.com/smartcontractkit/chainlink-automation v1.0.1/go.mod h1:INSchkV3ntyDdlZKGWA030MPDpp6pbeuiRkRKYFCm2k=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218160643-bd451bb2dd94 h1:mrxa3HrQfbMi4ji6gGcQHuLptvoNaRAv4TLnGJngbLc=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231218160643-bd451bb2dd94/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231219184921-07a83946dc39 h1:kN6X9gF6+0hFt4Xb1BoPXxrCmAbaZHU8icOGGc6tGJo=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231219184921-07a83946dc39/go.mod h1:IdlfCN9rUs8Q/hrOYe8McNBIwEOHEsi0jilb3Cw77xs=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5 h1:kBnmjv3fxU7krVIqZFvo1m4F6qBc4vPURQFX/mcChhI=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20231218175426-6e0427c661e5/go.mod h1:EoM7wQ81mov7wsUzG4zEnnr0EH0POEo/I0hRDg433TU=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20231204152908-a6e3fe8ff2a1 h1:xYqRgZO0nMSO8CBCMR0r3WA+LZ4kNL8a6bnbyk/oBtQ=
Expand Down
2 changes: 1 addition & 1 deletion core/services/pipeline/mocks/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

143 changes: 8 additions & 135 deletions core/store/models/common.go
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/tidwall/gjson"
"go.uber.org/multierr"

commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
commonmodels "github.com/smartcontractkit/chainlink-common/pkg/models"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/assets"
"github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils/big"
)
Expand Down Expand Up @@ -198,116 +200,22 @@ func (c Cron) String() string {
}

// Duration is a non-negative time duration.
type Duration struct{ d time.Duration }
type Duration = commonmodels.Duration

func MakeDuration(d time.Duration) (Duration, error) {
if d < time.Duration(0) {
return Duration{}, fmt.Errorf("cannot make negative time duration: %s", d)
}
return Duration{d: d}, nil
return commonmodels.MakeDuration(d)
}

func ParseDuration(s string) (Duration, error) {
d, err := time.ParseDuration(s)
if err != nil {
return Duration{}, err
}

return MakeDuration(d)
return commonmodels.ParseDuration(s)
}

func MustMakeDuration(d time.Duration) Duration {
rv, err := MakeDuration(d)
if err != nil {
panic(err)
}
return rv
return commonmodels.MustMakeDuration(d)
}

func MustNewDuration(d time.Duration) *Duration {
rv := MustMakeDuration(d)
return &rv
}

// Duration returns the value as the standard time.Duration value.
func (d Duration) Duration() time.Duration {
return d.d
}

// Before returns the time d units before time t
func (d Duration) Before(t time.Time) time.Time {
return t.Add(-d.Duration())
}

// Shorter returns true if and only if d is shorter than od.
func (d Duration) Shorter(od Duration) bool { return d.d < od.d }

// IsInstant is true if and only if d is of duration 0
func (d Duration) IsInstant() bool { return d.d == 0 }

// String returns a string representing the duration in the form "72h3m0.5s".
// Leading zero units are omitted. As a special case, durations less than one
// second format use a smaller unit (milli-, micro-, or nanoseconds) to ensure
// that the leading digit is non-zero. The zero duration formats as 0s.
func (d Duration) String() string {
return d.Duration().String()
}

// MarshalJSON implements the json.Marshaler interface.
func (d Duration) MarshalJSON() ([]byte, error) {
return json.Marshal(d.String())
}

// UnmarshalJSON implements the json.Unmarshaler interface.
func (d *Duration) UnmarshalJSON(input []byte) error {
var txt string
err := json.Unmarshal(input, &txt)
if err != nil {
return err
}
v, err := time.ParseDuration(string(txt))
if err != nil {
return err
}
*d, err = MakeDuration(v)
if err != nil {
return err
}
return nil
}

func (d *Duration) Scan(v interface{}) (err error) {
switch tv := v.(type) {
case int64:
*d, err = MakeDuration(time.Duration(tv))
return err
default:
return errors.Errorf(`don't know how to parse "%s" of type %T as a `+
`models.Duration`, tv, tv)
}
}

func (d Duration) Value() (driver.Value, error) {
return int64(d.d), nil
}

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

// UnmarshalText implements the text.Unmarshaler interface.
func (d *Duration) UnmarshalText(input []byte) error {
v, err := time.ParseDuration(string(input))
if err != nil {
return err
}
pd, err := MakeDuration(v)
if err != nil {
return err
}
*d = pd
return nil
return commonmodels.MustNewDuration(d)
}

// Interval represents a time.Duration stored as a Postgres interval type
Expand Down Expand Up @@ -514,7 +422,7 @@ func (s Sha256Hash) Value() (driver.Value, error) {
}

// URL extends url.URL to implement encoding.TextMarshaler.
DylanTinianov marked this conversation as resolved.
Show resolved Hide resolved
type URL url.URL
type URL = commonconfig.URL

func ParseURL(s string) (*URL, error) {
u, err := url.Parse(s)
Expand All @@ -532,41 +440,6 @@ func MustParseURL(s string) *URL {
return u
}

func (u *URL) String() string {
return (*url.URL)(u).String()
}

// URL returns a copy of u as a *url.URL
func (u *URL) URL() *url.URL {
if u == nil {
return nil
}
// defensive copy
r := url.URL(*u)
if u.User != nil {
r.User = new(url.Userinfo)
*r.User = *u.User
}
return &r
}

func (u *URL) IsZero() bool {
return (url.URL)(*u) == url.URL{}
}

func (u *URL) MarshalText() ([]byte, error) {
return []byte(u.String()), nil
}

func (u *URL) UnmarshalText(input []byte) error {
v, err := url.Parse(string(input))
if err != nil {
return err
}
*u = URL(*v)
return nil
}

// ServiceHeader is an HTTP header to include in POST to log service.
type ServiceHeader struct {
Header string
Expand Down
Loading
Loading