-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,451 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
golang 1.21.4 | ||
protoc 23.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,38 @@ | ||
module github.com/smartcontractkit/chainlink-data-streams | ||
|
||
go 1.21.3 | ||
go 1.21 | ||
|
||
require ( | ||
github.com/pkg/errors v0.9.1 | ||
github.com/shopspring/decimal v1.3.1 | ||
github.com/smartcontractkit/chainlink-common v0.1.7-0.20231204152334-1f32103bbb4c | ||
github.com/smartcontractkit/libocr v0.0.0-20231107151413-13e0202ae8d7 | ||
github.com/smartcontractkit/chain-selectors v1.0.5 | ||
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240206175150-8264f16d8815 | ||
github.com/smartcontractkit/libocr v0.0.0-20240112202000-6359502d2ff1 | ||
github.com/stretchr/testify v1.8.4 | ||
google.golang.org/protobuf v1.32.0 | ||
) | ||
|
||
require ( | ||
github.com/beorn7/perks v1.0.1 // indirect | ||
github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/google/uuid v1.3.1 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
github.com/mr-tron/base58 v1.2.0 // indirect | ||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect | ||
github.com/prometheus/client_golang v1.17.0 // indirect | ||
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 // indirect | ||
github.com/prometheus/common v0.44.0 // indirect | ||
github.com/prometheus/procfs v0.11.1 // indirect | ||
github.com/rogpeppe/go-internal v1.11.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.26.0 // indirect | ||
golang.org/x/crypto v0.13.0 // indirect | ||
golang.org/x/crypto v0.17.0 // indirect | ||
golang.org/x/net v0.18.0 // indirect | ||
golang.org/x/sys v0.15.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect | ||
google.golang.org/grpc v1.58.3 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package llo | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" | ||
"github.com/smartcontractkit/libocr/offchainreporting2/types" | ||
) | ||
|
||
var _ ReportCodec = JSONReportCodec{} | ||
|
||
// JSONReportCodec is a chain-agnostic reference implementation | ||
|
||
type JSONReportCodec struct{} | ||
|
||
func (cdc JSONReportCodec) Encode(r Report) ([]byte, error) { | ||
return json.Marshal(r) | ||
} | ||
|
||
func (cdc JSONReportCodec) Decode(b []byte) (r Report, err error) { | ||
type decode struct { | ||
ConfigDigest string | ||
ChainSelector uint64 | ||
SeqNr uint64 | ||
ChannelID commontypes.ChannelID | ||
ValidAfterSeconds uint32 | ||
ValidUntilSeconds uint32 | ||
Values []*big.Int | ||
Specimen bool | ||
} | ||
d := decode{} | ||
err = json.Unmarshal(b, &d) | ||
if err != nil { | ||
return r, fmt.Errorf("failed to decode report: expected JSON (got: %s); %w", b, err) | ||
} | ||
cdBytes, err := hex.DecodeString(d.ConfigDigest) | ||
if err != nil { | ||
return r, fmt.Errorf("invalid ConfigDigest; %w", err) | ||
} | ||
cd, err := types.BytesToConfigDigest(cdBytes) | ||
if err != nil { | ||
return r, fmt.Errorf("invalid ConfigDigest; %w", err) | ||
} | ||
|
||
return Report{ | ||
ConfigDigest: cd, | ||
ChainSelector: d.ChainSelector, | ||
SeqNr: d.SeqNr, | ||
ChannelID: d.ChannelID, | ||
ValidAfterSeconds: d.ValidAfterSeconds, | ||
ValidUntilSeconds: d.ValidUntilSeconds, | ||
Values: d.Values, | ||
Specimen: d.Specimen, | ||
}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package llo | ||
|
||
import ( | ||
"math/big" | ||
"testing" | ||
|
||
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" | ||
"github.com/smartcontractkit/libocr/offchainreporting2/types" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_JSONCodec(t *testing.T) { | ||
t.Run("Encode=>Decode", func(t *testing.T) { | ||
r := Report{ | ||
ConfigDigest: types.ConfigDigest([32]byte{1, 2, 3}), | ||
ChainSelector: 42, | ||
SeqNr: 43, | ||
ChannelID: commontypes.ChannelID(46), | ||
ValidAfterSeconds: 44, | ||
ValidUntilSeconds: 45, | ||
Values: []*big.Int{big.NewInt(1), big.NewInt(2)}, | ||
Specimen: true, | ||
} | ||
|
||
cdc := JSONReportCodec{} | ||
|
||
encoded, err := cdc.Encode(r) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, `{"ConfigDigest":"0102030000000000000000000000000000000000000000000000000000000000","ChainSelector":42,"SeqNr":43,"ChannelID":46,"ValidAfterSeconds":44,"ValidUntilSeconds":45,"Values":[1,2],"Specimen":true}`, string(encoded)) | ||
|
||
decoded, err := cdc.Decode(encoded) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, r, decoded) | ||
}) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
syntax="proto3"; | ||
|
||
package v1; | ||
option go_package = ".;llo"; | ||
|
||
message LLOOffchainConfigProto { | ||
bytes predecessorConfigDigest = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package llo | ||
|
||
func must[T any](x T, err error) T { | ||
if err != nil { | ||
panic(err) | ||
} | ||
return x | ||
} |
Oops, something went wrong.