Skip to content

Commit fb56ce0

Browse files
authored
Go: Add v5, v6 & v7 Report Schemas (#27)
This PR adds the following Report Schemas to Go SDK: ### v5 ```ts const reportBlobAbiV5 = [ { type: 'bytes32', name: 'feedId' }, { type: 'uint32', name: 'validFromTimestamp' }, { type: 'uint32', name: 'observationsTimestamp' }, { type: 'uint192', name: 'nativeFee' }, { type: 'uint192', name: 'linkFee' }, { type: 'uint32', name: 'expiresAt' }, { type: 'int192', name: 'rate' }, { type: 'uint32', name: 'timestamp' }, { type: 'uint32', name: 'duration' }, ] ``` ### v6 ```ts const reportBlobAbiV6 = [ { type: 'bytes32', name: 'feedId' }, { type: 'uint32', name: 'validFromTimestamp' }, { type: 'uint32', name: 'observationsTimestamp' }, { type: 'uint192', name: 'nativeFee' }, { type: 'uint192', name: 'linkFee' }, { type: 'uint32', name: 'expiresAt' }, { type: 'int192', name: 'price' }, { type: 'int192', name: 'price2' }, { type: 'int192', name: 'price3' }, { type: 'int192', name: 'price4' }, { type: 'int192', name: 'price5' }, ] ``` ### v7 ```ts const reportBlobAbiV7 = [ { type: 'bytes32', name: 'feedId' }, { type: 'uint32', name: 'validFromTimestamp' }, { type: 'uint32', name: 'observationsTimestamp' }, { type: 'uint192', name: 'nativeFee' }, { type: 'uint192', name: 'linkFee' }, { type: 'uint32', name: 'expiresAt' }, { type: 'int192', name: 'exchangeRate' }, ] ```
1 parent b271d52 commit fb56ce0

File tree

9 files changed

+545
-2
lines changed

9 files changed

+545
-2
lines changed

go/feed/feed.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ const (
1515
FeedVersion2
1616
FeedVersion3
1717
FeedVersion4
18+
FeedVersion5
19+
FeedVersion6
20+
FeedVersion7
1821
FeedVersion8
1922
FeedVersion9
2023
FeedVersion10

go/report/report.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@ import (
99
v2 "github.com/smartcontractkit/data-streams-sdk/go/report/v2"
1010
v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
1111
v4 "github.com/smartcontractkit/data-streams-sdk/go/report/v4"
12+
v5 "github.com/smartcontractkit/data-streams-sdk/go/report/v5"
13+
v6 "github.com/smartcontractkit/data-streams-sdk/go/report/v6"
14+
v7 "github.com/smartcontractkit/data-streams-sdk/go/report/v7"
1215
v8 "github.com/smartcontractkit/data-streams-sdk/go/report/v8"
1316
v9 "github.com/smartcontractkit/data-streams-sdk/go/report/v9"
1417
)
1518

1619
// Data represents the actual report data and attributes
1720
type Data interface {
18-
v1.Data | v2.Data | v3.Data | v4.Data | v8.Data | v9.Data | v10.Data
21+
v1.Data | v2.Data | v3.Data | v4.Data | v5.Data | v6.Data | v7.Data | v8.Data | v9.Data | v10.Data
1922
Schema() abi.Arguments
2023
}
2124

go/report/report_test.go

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import (
99

1010
"github.com/ethereum/go-ethereum/accounts/abi"
1111
v1 "github.com/smartcontractkit/data-streams-sdk/go/report/v1"
12+
v10 "github.com/smartcontractkit/data-streams-sdk/go/report/v10"
1213
v2 "github.com/smartcontractkit/data-streams-sdk/go/report/v2"
1314
v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
1415
v4 "github.com/smartcontractkit/data-streams-sdk/go/report/v4"
16+
v5 "github.com/smartcontractkit/data-streams-sdk/go/report/v5"
17+
v6 "github.com/smartcontractkit/data-streams-sdk/go/report/v6"
18+
v7 "github.com/smartcontractkit/data-streams-sdk/go/report/v7"
1519
v8 "github.com/smartcontractkit/data-streams-sdk/go/report/v8"
1620
v9 "github.com/smartcontractkit/data-streams-sdk/go/report/v9"
1721
)
@@ -73,6 +77,48 @@ func TestReport(t *testing.T) {
7377
t.Errorf("expected: %#v, got: %#v", v4Report, rv4)
7478
}
7579

80+
b, err = schema.Pack(v5Report.ReportContext, v5Report.ReportBlob, v5Report.RawRs, v5Report.RawSs, v5Report.RawVs)
81+
if err != nil {
82+
t.Errorf("failed to encode report: %s", err)
83+
}
84+
85+
rv5, err := Decode[v5.Data](b)
86+
if err != nil {
87+
t.Errorf("failed to decode report: %s", err)
88+
}
89+
90+
if !reflect.DeepEqual(v5Report, rv5) {
91+
t.Errorf("expected: %#v, got: %#v", v5Report, rv5)
92+
}
93+
94+
b, err = schema.Pack(v6Report.ReportContext, v6Report.ReportBlob, v6Report.RawRs, v6Report.RawSs, v6Report.RawVs)
95+
if err != nil {
96+
t.Errorf("failed to encode report: %s", err)
97+
}
98+
99+
rv6, err := Decode[v6.Data](b)
100+
if err != nil {
101+
t.Errorf("failed to decode report: %s", err)
102+
}
103+
104+
if !reflect.DeepEqual(v6Report, rv6) {
105+
t.Errorf("expected: %#v, got: %#v", v6Report, rv6)
106+
}
107+
108+
b, err = schema.Pack(v7Report.ReportContext, v7Report.ReportBlob, v7Report.RawRs, v7Report.RawSs, v7Report.RawVs)
109+
if err != nil {
110+
t.Errorf("failed to encode report: %s", err)
111+
}
112+
113+
rv7, err := Decode[v7.Data](b)
114+
if err != nil {
115+
t.Errorf("failed to decode report: %s", err)
116+
}
117+
118+
if !reflect.DeepEqual(v7Report, rv7) {
119+
t.Errorf("expected: %#v, got: %#v", v7Report, rv7)
120+
}
121+
76122
b, err = schema.Pack(v8Report.ReportContext, v8Report.ReportBlob, v8Report.RawRs, v8Report.RawSs, v8Report.RawVs)
77123
if err != nil {
78124
t.Errorf("failed to encode report: %s", err)
@@ -97,9 +143,23 @@ func TestReport(t *testing.T) {
97143
t.Errorf("failed to decode report: %s", err)
98144
}
99145

100-
if !reflect.DeepEqual(v8Report, rv8) {
146+
if !reflect.DeepEqual(v9Report, rv9) {
101147
t.Errorf("expected: %#v, got: %#v", v9Report, rv9)
102148
}
149+
150+
b, err = schema.Pack(v10Report.ReportContext, v10Report.ReportBlob, v10Report.RawRs, v10Report.RawSs, v10Report.RawVs)
151+
if err != nil {
152+
t.Errorf("failed to encode report: %s", err)
153+
}
154+
155+
rv10, err := Decode[v10.Data](b)
156+
if err != nil {
157+
t.Errorf("failed to decode report: %s", err)
158+
}
159+
160+
if !reflect.DeepEqual(v10Report, rv10) {
161+
t.Errorf("expected: %#v, got: %#v", v10Report, rv10)
162+
}
103163
}
104164

105165
var v1Report = &Report[v1.Data]{
@@ -138,6 +198,33 @@ var v4Report = &Report[v4.Data]{
138198
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
139199
}
140200

201+
var v5Report = &Report[v5.Data]{
202+
Data: v5Data,
203+
ReportContext: [3][32]uint8{},
204+
ReportBlob: mustPackData(v5Data),
205+
RawRs: [][32]uint8{{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14}},
206+
RawSs: [][32]uint8{{01, 02, 10, 73, 65, 19, 14, 27, 42, 48, 52, 18, 39, 116, 67, 85, 13, 82, 33, 48, 23, 33, 49, 32, 67, 50, 37, 32, 63, 77, 14, 64}},
207+
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
208+
}
209+
210+
var v6Report = &Report[v6.Data]{
211+
Data: v6Data,
212+
ReportContext: [3][32]uint8{},
213+
ReportBlob: mustPackData(v6Data),
214+
RawRs: [][32]uint8{{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14}},
215+
RawSs: [][32]uint8{{01, 02, 10, 73, 65, 19, 14, 27, 42, 48, 52, 18, 39, 116, 67, 85, 13, 82, 33, 48, 23, 33, 49, 32, 67, 50, 37, 32, 63, 77, 14, 64}},
216+
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
217+
}
218+
219+
var v7Report = &Report[v7.Data]{
220+
Data: v7Data,
221+
ReportContext: [3][32]uint8{},
222+
ReportBlob: mustPackData(v7Data),
223+
RawRs: [][32]uint8{{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14}},
224+
RawSs: [][32]uint8{{01, 02, 10, 73, 65, 19, 14, 27, 42, 48, 52, 18, 39, 116, 67, 85, 13, 82, 33, 48, 23, 33, 49, 32, 67, 50, 37, 32, 63, 77, 14, 64}},
225+
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
226+
}
227+
141228
var v8Report = &Report[v8.Data]{
142229
Data: v8Data,
143230
ReportContext: [3][32]uint8{},
@@ -156,6 +243,15 @@ var v9Report = &Report[v9.Data]{
156243
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
157244
}
158245

246+
var v10Report = &Report[v10.Data]{
247+
Data: v10Data,
248+
ReportContext: [3][32]uint8{},
249+
ReportBlob: mustPackData(v10Data),
250+
RawRs: [][32]uint8{{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14}},
251+
RawSs: [][32]uint8{{01, 02, 10, 73, 65, 19, 14, 27, 42, 48, 52, 18, 39, 116, 67, 85, 13, 82, 33, 48, 23, 33, 49, 32, 67, 50, 37, 32, 63, 77, 14, 64}},
252+
RawVs: [32]uint8{00, 01, 10, 74, 67, 29, 24, 17, 12, 18, 22, 11, 69, 11, 63, 86, 12, 86, 23, 58, 13, 53, 29, 12, 17, 10, 17, 12, 63, 27, 12, 14},
253+
}
254+
159255
var v1Data = v1.Data{
160256
FeedID: [32]uint8{00, 01, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
161257
ObservationsTimestamp: uint32(time.Now().Unix()),
@@ -201,6 +297,42 @@ var v4Data = v4.Data{
201297
MarketStatus: v4.MarketStatusOpen,
202298
}
203299

300+
var v5Data = v5.Data{
301+
FeedID: [32]uint8{00, 5, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
302+
ValidFromTimestamp: uint32(time.Now().Unix()),
303+
ObservationsTimestamp: uint32(time.Now().Unix()),
304+
NativeFee: big.NewInt(10),
305+
LinkFee: big.NewInt(10),
306+
ExpiresAt: uint32(time.Now().Unix()) + 100,
307+
Rate: big.NewInt(550),
308+
Timestamp: uint32(time.Now().Unix()),
309+
Duration: uint32(86400),
310+
}
311+
312+
var v6Data = v6.Data{
313+
FeedID: [32]uint8{00, 6, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
314+
ValidFromTimestamp: uint32(time.Now().Unix()),
315+
ObservationsTimestamp: uint32(time.Now().Unix()),
316+
NativeFee: big.NewInt(10),
317+
LinkFee: big.NewInt(10),
318+
ExpiresAt: uint32(time.Now().Unix()) + 100,
319+
Price: big.NewInt(600),
320+
Price2: big.NewInt(601),
321+
Price3: big.NewInt(602),
322+
Price4: big.NewInt(603),
323+
Price5: big.NewInt(604),
324+
}
325+
326+
var v7Data = v7.Data{
327+
FeedID: [32]uint8{00, 7, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
328+
ValidFromTimestamp: uint32(time.Now().Unix()),
329+
ObservationsTimestamp: uint32(time.Now().Unix()),
330+
NativeFee: big.NewInt(10),
331+
LinkFee: big.NewInt(10),
332+
ExpiresAt: uint32(time.Now().Unix()) + 100,
333+
ExchangeRate: big.NewInt(700),
334+
}
335+
204336
var v8Data = v8.Data{
205337
FeedID: [32]uint8{00, 8, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
206338
ValidFromTimestamp: uint32(time.Now().Unix()),
@@ -226,6 +358,22 @@ var v9Data = v9.Data{
226358
Ripcord: 108,
227359
}
228360

361+
var v10Data = v10.Data{
362+
FeedID: [32]uint8{00, 10, 107, 74, 167, 229, 124, 167, 182, 138, 225, 191, 69, 101, 63, 86, 182, 86, 253, 58, 163, 53, 239, 127, 174, 105, 107, 102, 63, 27, 132, 114},
363+
ValidFromTimestamp: uint32(time.Now().Unix()),
364+
ObservationsTimestamp: uint32(time.Now().Unix()),
365+
NativeFee: big.NewInt(10),
366+
LinkFee: big.NewInt(10),
367+
ExpiresAt: uint32(time.Now().Unix()) + 100,
368+
LastUpdateTimestamp: uint64(time.Now().UnixNano() - int64(10*time.Second)),
369+
Price: big.NewInt(1000),
370+
MarketStatus: 1,
371+
CurrentMultiplier: big.NewInt(100),
372+
NewMultiplier: big.NewInt(101),
373+
ActivationDateTime: uint32(time.Now().Unix()) + 200,
374+
TokenizedPrice: big.NewInt(1001),
375+
}
376+
229377
func mustPackData(d interface{}) []byte {
230378
var args []interface{}
231379
var dataSchema abi.Arguments
@@ -280,6 +428,45 @@ func mustPackData(d interface{}) []byte {
280428
v.BenchmarkPrice,
281429
v.MarketStatus,
282430
}
431+
case v5.Data:
432+
dataSchema = v5.Schema()
433+
args = []interface{}{
434+
v.FeedID,
435+
v.ValidFromTimestamp,
436+
v.ObservationsTimestamp,
437+
v.NativeFee,
438+
v.LinkFee,
439+
v.ExpiresAt,
440+
v.Rate,
441+
v.Timestamp,
442+
v.Duration,
443+
}
444+
case v6.Data:
445+
dataSchema = v6.Schema()
446+
args = []interface{}{
447+
v.FeedID,
448+
v.ValidFromTimestamp,
449+
v.ObservationsTimestamp,
450+
v.NativeFee,
451+
v.LinkFee,
452+
v.ExpiresAt,
453+
v.Price,
454+
v.Price2,
455+
v.Price3,
456+
v.Price4,
457+
v.Price5,
458+
}
459+
case v7.Data:
460+
dataSchema = v7.Schema()
461+
args = []interface{}{
462+
v.FeedID,
463+
v.ValidFromTimestamp,
464+
v.ObservationsTimestamp,
465+
v.NativeFee,
466+
v.LinkFee,
467+
v.ExpiresAt,
468+
v.ExchangeRate,
469+
}
283470
case v8.Data:
284471
dataSchema = v8.Schema()
285472
args = []interface{}{
@@ -307,6 +494,23 @@ func mustPackData(d interface{}) []byte {
307494
v.Aum,
308495
v.Ripcord,
309496
}
497+
case v10.Data:
498+
dataSchema = v10.Schema()
499+
args = []interface{}{
500+
v.FeedID,
501+
v.ValidFromTimestamp,
502+
v.ObservationsTimestamp,
503+
v.NativeFee,
504+
v.LinkFee,
505+
v.ExpiresAt,
506+
v.LastUpdateTimestamp,
507+
v.Price,
508+
v.MarketStatus,
509+
v.CurrentMultiplier,
510+
v.NewMultiplier,
511+
v.ActivationDateTime,
512+
v.TokenizedPrice,
513+
}
310514
default:
311515
panic(fmt.Sprintf("invalid type to pack: %#v", v))
312516
}

go/report/v5/data.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package v5
2+
3+
import (
4+
"fmt"
5+
"math/big"
6+
7+
"github.com/ethereum/go-ethereum/accounts/abi"
8+
"github.com/smartcontractkit/data-streams-sdk/go/feed"
9+
)
10+
11+
var schema = Schema()
12+
13+
// Schema returns this data version schema
14+
func Schema() abi.Arguments {
15+
mustNewType := func(t string) abi.Type {
16+
result, err := abi.NewType(t, "", []abi.ArgumentMarshaling{})
17+
if err != nil {
18+
panic(fmt.Sprintf("Unexpected error during abi.NewType: %s", err))
19+
}
20+
return result
21+
}
22+
return abi.Arguments([]abi.Argument{
23+
{Name: "feedId", Type: mustNewType("bytes32")},
24+
{Name: "validFromTimestamp", Type: mustNewType("uint32")},
25+
{Name: "observationsTimestamp", Type: mustNewType("uint32")},
26+
{Name: "nativeFee", Type: mustNewType("uint192")},
27+
{Name: "linkFee", Type: mustNewType("uint192")},
28+
{Name: "expiresAt", Type: mustNewType("uint32")},
29+
{Name: "rate", Type: mustNewType("int192")},
30+
{Name: "timestamp", Type: mustNewType("uint32")},
31+
{Name: "duration", Type: mustNewType("uint32")},
32+
})
33+
}
34+
35+
// Data is the container for this schema attributes
36+
type Data struct {
37+
FeedID feed.ID `abi:"feedId"`
38+
ValidFromTimestamp uint32
39+
ObservationsTimestamp uint32
40+
NativeFee *big.Int
41+
LinkFee *big.Int
42+
ExpiresAt uint32
43+
Rate *big.Int
44+
Timestamp uint32
45+
Duration uint32
46+
}
47+
48+
// Schema returns this data version schema
49+
func (Data) Schema() abi.Arguments {
50+
return Schema()
51+
}
52+
53+
// Decode decodes the serialized data bytes
54+
func Decode(data []byte) (*Data, error) {
55+
values, err := schema.Unpack(data)
56+
if err != nil {
57+
return nil, fmt.Errorf("failed to decode report: %w", err)
58+
}
59+
decoded := new(Data)
60+
if err = schema.Copy(decoded, values); err != nil {
61+
return nil, fmt.Errorf("failed to copy report values to struct: %w", err)
62+
}
63+
return decoded, nil
64+
}

0 commit comments

Comments
 (0)