Skip to content

Commit 4111a31

Browse files
committed
Implement V11 support for Go.
1 parent e2097ca commit 4111a31

File tree

10 files changed

+222
-21
lines changed

10 files changed

+222
-21
lines changed

go/feed/feed.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
FeedVersion8
2222
FeedVersion9
2323
FeedVersion10
24+
FeedVersion11
2425
FeedVersion13
2526
_
2627
)

go/report/common/marketstatus.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package common
2+
3+
const (
4+
MarketStatusUnknown uint32 = iota
5+
MarketStatusClosed
6+
MarketStatusOpen
7+
)

go/report/report.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
v1 "github.com/smartcontractkit/data-streams-sdk/go/report/v1"
99
v10 "github.com/smartcontractkit/data-streams-sdk/go/report/v10"
10+
v11 "github.com/smartcontractkit/data-streams-sdk/go/report/v11"
1011
v13 "github.com/smartcontractkit/data-streams-sdk/go/report/v13"
1112
v2 "github.com/smartcontractkit/data-streams-sdk/go/report/v2"
1213
v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
@@ -20,7 +21,7 @@ import (
2021

2122
// Data represents the actual report data and attributes
2223
type Data interface {
23-
v1.Data | v2.Data | v3.Data | v4.Data | v5.Data | v6.Data | v7.Data | v8.Data | v9.Data | v10.Data | v13.Data
24+
v1.Data | v2.Data | v3.Data | v4.Data | v5.Data | v6.Data | v7.Data | v8.Data | v9.Data | v10.Data | v11.Data | v13.Data
2425
Schema() abi.Arguments
2526
}
2627

go/report/report_test.go

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

1010
"github.com/ethereum/go-ethereum/accounts/abi"
1111

12+
"github.com/smartcontractkit/data-streams-sdk/go/report/common"
1213
v1 "github.com/smartcontractkit/data-streams-sdk/go/report/v1"
1314
v10 "github.com/smartcontractkit/data-streams-sdk/go/report/v10"
15+
v11 "github.com/smartcontractkit/data-streams-sdk/go/report/v11"
1416
v13 "github.com/smartcontractkit/data-streams-sdk/go/report/v13"
1517
v2 "github.com/smartcontractkit/data-streams-sdk/go/report/v2"
1618
v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
@@ -163,6 +165,20 @@ func TestReport(t *testing.T) {
163165
t.Errorf("expected: %#v, got: %#v", v10Report, rv10)
164166
}
165167

168+
b, err = schema.Pack(v11Report.ReportContext, v11Report.ReportBlob, v11Report.RawRs, v11Report.RawSs, v11Report.RawVs)
169+
if err != nil {
170+
t.Errorf("failed to encode report: %s", err)
171+
}
172+
173+
rv11, err := Decode[v11.Data](b)
174+
if err != nil {
175+
t.Errorf("failed to decode report: %s", err)
176+
}
177+
178+
if !reflect.DeepEqual(v11Report, rv11) {
179+
t.Errorf("expected: %#v, got: %#v", v11Report, rv11)
180+
}
181+
166182
b, err = schema.Pack(v13Report.ReportContext, v13Report.ReportBlob, v13Report.RawRs, v13Report.RawSs, v13Report.RawVs)
167183
if err != nil {
168184
t.Errorf("failed to encode report: %s", err)
@@ -268,6 +284,15 @@ var v10Report = &Report[v10.Data]{
268284
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},
269285
}
270286

287+
var v11Report = &Report[v11.Data]{
288+
Data: v11Data,
289+
ReportContext: [3][32]uint8{},
290+
ReportBlob: mustPackData(v11Data),
291+
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}},
292+
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}},
293+
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},
294+
}
295+
271296
var v13Report = &Report[v13.Data]{
272297
Data: v13Data,
273298
ReportContext: [3][32]uint8{},
@@ -319,7 +344,7 @@ var v4Data = v4.Data{
319344
LinkFee: big.NewInt(10),
320345
ExpiresAt: uint32(time.Now().Unix()) + 100,
321346
BenchmarkPrice: big.NewInt(100),
322-
MarketStatus: v4.MarketStatusOpen,
347+
MarketStatus: common.MarketStatusOpen,
323348
}
324349

325350
var v5Data = v5.Data{
@@ -399,6 +424,23 @@ var v10Data = v10.Data{
399424
TokenizedPrice: big.NewInt(1001),
400425
}
401426

427+
var v11Data = v11.Data{
428+
FeedID: [32]uint8{00, 11, 251, 109, 19, 88, 151, 228, 170, 245, 101, 123, 255, 211, 176, 180, 143, 142, 42, 81, 49, 33, 76, 158, 194, 214, 46, 172, 93, 83, 32, 103},
429+
ValidFromTimestamp: uint32(time.Now().Unix()),
430+
ObservationsTimestamp: uint32(time.Now().Unix()),
431+
NativeFee: big.NewInt(10),
432+
LinkFee: big.NewInt(10),
433+
ExpiresAt: uint32(time.Now().Unix()) + 100,
434+
Mid: big.NewInt(103),
435+
LastSeenTimestampNs: uint64(time.Now().Unix()),
436+
Bid: big.NewInt(101),
437+
BidVolume: 10002,
438+
Ask: big.NewInt(105),
439+
AskVolume: 10001,
440+
LastTradedPrice: big.NewInt(103),
441+
MarketStatus: common.MarketStatusOpen,
442+
}
443+
402444
var v13Data = v13.Data{
403445
FeedID: [32]uint8{00, 13, 19, 169, 185, 197, 227, 122, 9, 159, 55, 78, 146, 195, 121, 20, 175, 92, 38, 143, 58, 138, 151, 33, 241, 114, 81, 53, 191, 180, 203, 184},
404446
ValidFromTimestamp: uint32(time.Now().Unix()),
@@ -550,6 +592,24 @@ func mustPackData(d interface{}) []byte {
550592
v.ActivationDateTime,
551593
v.TokenizedPrice,
552594
}
595+
case v11.Data:
596+
dataSchema = v11.Schema()
597+
args = []interface{}{
598+
v.FeedID,
599+
v.ValidFromTimestamp,
600+
v.ObservationsTimestamp,
601+
v.NativeFee,
602+
v.LinkFee,
603+
v.ExpiresAt,
604+
v.Mid,
605+
v.LastSeenTimestampNs,
606+
v.Bid,
607+
v.BidVolume,
608+
v.Ask,
609+
v.AskVolume,
610+
v.LastTradedPrice,
611+
v.MarketStatus,
612+
}
553613
case v13.Data:
554614
dataSchema = v13.Schema()
555615
args = []interface{}{

go/report/v11/data.go

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

go/report/v11/data_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package v11
2+
3+
import (
4+
"math/big"
5+
"reflect"
6+
"testing"
7+
"time"
8+
9+
"github.com/smartcontractkit/data-streams-sdk/go/report/common"
10+
)
11+
12+
func TestData(t *testing.T) {
13+
r := &Data{
14+
// 0x000bfb6d135897e4aaf5657bffd3b0b48f8e2a5131214c9ec2d62eac5d532067
15+
FeedID: [32]uint8{0, 11, 251, 109, 19, 88, 151, 228, 170, 245, 101, 123, 255, 211, 176, 180, 143, 142, 42, 81, 49, 33, 76, 158, 194, 214, 46, 172, 93, 83, 32, 103},
16+
ValidFromTimestamp: uint32(time.Now().Unix()),
17+
ObservationsTimestamp: uint32(time.Now().Unix()),
18+
NativeFee: big.NewInt(10),
19+
LinkFee: big.NewInt(10),
20+
ExpiresAt: uint32(time.Now().Unix()) + 100,
21+
22+
Mid: big.NewInt(103),
23+
LastSeenTimestampNs: uint64(time.Now().Unix()),
24+
Bid: big.NewInt(101),
25+
BidVolume: 10002,
26+
Ask: big.NewInt(105),
27+
AskVolume: 10001,
28+
LastTradedPrice: big.NewInt(103),
29+
MarketStatus: common.MarketStatusOpen,
30+
}
31+
32+
b, err := schema.Pack(
33+
r.FeedID,
34+
r.ValidFromTimestamp,
35+
r.ObservationsTimestamp,
36+
r.NativeFee,
37+
r.LinkFee,
38+
r.ExpiresAt,
39+
r.Mid,
40+
r.LastSeenTimestampNs,
41+
r.Bid,
42+
r.BidVolume,
43+
r.Ask,
44+
r.AskVolume,
45+
r.LastTradedPrice,
46+
r.MarketStatus,
47+
)
48+
49+
if err != nil {
50+
t.Errorf("failed to serialize report: %s", err)
51+
}
52+
53+
d, err := Decode(b)
54+
if err != nil {
55+
t.Errorf("failed to deserialize report: %s", err)
56+
}
57+
58+
if !reflect.DeepEqual(r, d) {
59+
t.Errorf("expected: %#v, got %#v", r, d)
60+
}
61+
}

go/report/v4/data.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66

77
"github.com/ethereum/go-ethereum/accounts/abi"
8+
89
"github.com/smartcontractkit/data-streams-sdk/go/feed"
910
)
1011

@@ -19,7 +20,7 @@ func Schema() abi.Arguments {
1920
}
2021
return result
2122
}
22-
return abi.Arguments([]abi.Argument{
23+
return []abi.Argument{
2324
{Name: "feedId", Type: mustNewType("bytes32")},
2425
{Name: "validFromTimestamp", Type: mustNewType("uint32")},
2526
{Name: "observationsTimestamp", Type: mustNewType("uint32")},
@@ -28,15 +29,9 @@ func Schema() abi.Arguments {
2829
{Name: "expiresAt", Type: mustNewType("uint32")},
2930
{Name: "benchmarkPrice", Type: mustNewType("int192")},
3031
{Name: "marketStatus", Type: mustNewType("uint32")},
31-
})
32+
}
3233
}
3334

34-
const (
35-
MarketStatusUnknown uint32 = iota
36-
MarketStatusClosed
37-
MarketStatusOpen
38-
)
39-
4035
// Data is the container for this schema attributes
4136
type Data struct {
4237
FeedID feed.ID `abi:"feedId"`

go/report/v4/data_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"reflect"
66
"testing"
77
"time"
8+
9+
"github.com/smartcontractkit/data-streams-sdk/go/report/common"
810
)
911

1012
func TestData(t *testing.T) {
@@ -16,7 +18,7 @@ func TestData(t *testing.T) {
1618
LinkFee: big.NewInt(10),
1719
ExpiresAt: uint32(time.Now().Unix()) + 100,
1820
BenchmarkPrice: big.NewInt(100),
19-
MarketStatus: MarketStatusOpen,
21+
MarketStatus: common.MarketStatusOpen,
2022
}
2123

2224
b, err := schema.Pack(

go/report/v8/data.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math/big"
66

77
"github.com/ethereum/go-ethereum/accounts/abi"
8+
89
"github.com/smartcontractkit/data-streams-sdk/go/feed"
910
)
1011

@@ -19,7 +20,7 @@ func Schema() abi.Arguments {
1920
}
2021
return result
2122
}
22-
return abi.Arguments([]abi.Argument{
23+
return []abi.Argument{
2324
{Name: "feedId", Type: mustNewType("bytes32")},
2425
{Name: "validFromTimestamp", Type: mustNewType("uint32")},
2526
{Name: "observationsTimestamp", Type: mustNewType("uint32")},
@@ -29,16 +30,10 @@ func Schema() abi.Arguments {
2930
{Name: "lastUpdateTimestamp", Type: mustNewType("uint64")},
3031
{Name: "midPrice", Type: mustNewType("int192")},
3132
{Name: "marketStatus", Type: mustNewType("uint32")},
32-
})
33+
}
3334
}
3435

35-
const (
36-
MarketStatusUnknown uint32 = iota
37-
MarketStatusClosed
38-
MarketStatusOpen
39-
)
40-
41-
// Data is the container for this schema attributes
36+
// Data is the container for this schema's attributes
4237
type Data struct {
4338
FeedID feed.ID `abi:"feedId"`
4439
ObservationsTimestamp uint32

go/report/v8/data_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"reflect"
66
"testing"
77
"time"
8+
9+
"github.com/smartcontractkit/data-streams-sdk/go/report/common"
810
)
911

1012
func TestData(t *testing.T) {
@@ -17,7 +19,7 @@ func TestData(t *testing.T) {
1719
ExpiresAt: uint32(time.Now().Unix()) + 100,
1820
LastUpdateTimestamp: uint64(time.Now().UnixNano() - int64(10*time.Second)),
1921
MidPrice: big.NewInt(100),
20-
MarketStatus: MarketStatusOpen,
22+
MarketStatus: common.MarketStatusOpen,
2123
}
2224

2325
b, err := schema.Pack(

0 commit comments

Comments
 (0)