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

[CAPPL-31] feat(values): adds support for time.Time as value #787

Merged
merged 4 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 3 additions & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
golang 1.21.4
golang 1.22.7
protoc 25.1
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match to go.mod toolchain

protoc-gen-go-grpc 1.3.0
golangci-lint 1.55.2
Comment on lines +2 to +3
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match compilers to pipeline runners

mockery 2.43.2
11 changes: 11 additions & 0 deletions pkg/values/pb/values.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package pb

import (
"time"

"github.com/shopspring/decimal"
"google.golang.org/protobuf/types/known/timestamppb"
)

func NewBoolValue(b bool) *Value {
Expand Down Expand Up @@ -80,3 +83,11 @@ func NewBigIntValue(sign int, bib []byte) *Value {
},
}
}

func NewTime(t time.Time) *Value {
return &Value{
Value: &Value_TimeValue{
TimeValue: timestamppb.New(t),
},
}
}
150 changes: 87 additions & 63 deletions pkg/values/pb/values.pb.go

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

15 changes: 7 additions & 8 deletions pkg/values/pb/values.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
syntax = "proto3";

import "google/protobuf/timestamp.proto";

option go_package = "github.com/smartcontractkit/chainlink-common/pkg/values/pb";

package values;
Expand All @@ -15,21 +17,18 @@ message Value {
Decimal decimal_value = 6;
int64 int64_value = 7;
BigInt bigint_value = 9;
google.protobuf.Timestamp time_value = 10;
}
}

message BigInt {
bytes abs_val = 1;
int64 sign = 2;
bytes abs_val = 1;
int64 sign = 2;
}

message Map {
map<string, Value> fields = 1;
}
message Map { map<string, Value> fields = 1; }

message List {
repeated Value fields = 2;
}
message List { repeated Value fields = 2; }

message Decimal {
BigInt coefficient = 1;
Expand Down
41 changes: 41 additions & 0 deletions pkg/values/time.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package values

import (
"errors"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/values/pb"
)

type Time struct {
Underlying time.Time
}

func NewTime(t time.Time) *Time {
return &Time{Underlying: t}
}

func (t *Time) UnwrapTo(to any) error {
if t == nil {
return errors.New("could not unwrap nil values.Time")
}

return unwrapTo(t.Underlying, to)
}

func (t *Time) Unwrap() (any, error) {
tt := new(time.Time)
return *tt, t.UnwrapTo(tt)
}

func (t *Time) copy() Value {
if t == nil {
return nil
}

return NewTime(t.Underlying)
}

func (t *Time) proto() *pb.Value {
return pb.NewTime(t.Underlying)
}
Loading
Loading