Skip to content
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
1 change: 1 addition & 0 deletions go/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
FeedVersion4
FeedVersion8
FeedVersion9
FeedVersion10
_
)

Expand Down
3 changes: 2 additions & 1 deletion go/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ethereum/go-ethereum/accounts/abi"
v1 "github.com/smartcontractkit/data-streams-sdk/go/report/v1"
v10 "github.com/smartcontractkit/data-streams-sdk/go/report/v10"
v2 "github.com/smartcontractkit/data-streams-sdk/go/report/v2"
v3 "github.com/smartcontractkit/data-streams-sdk/go/report/v3"
v4 "github.com/smartcontractkit/data-streams-sdk/go/report/v4"
Expand All @@ -14,7 +15,7 @@ import (

// Data represents the actual report data and attributes
type Data interface {
v1.Data | v2.Data | v3.Data | v4.Data | v8.Data | v9.Data
v1.Data | v2.Data | v3.Data | v4.Data | v8.Data | v9.Data | v10.Data
Schema() abi.Arguments
}

Expand Down
72 changes: 72 additions & 0 deletions go/report/v10/data.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package v10

import (
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/smartcontractkit/data-streams-sdk/go/feed"
)

var schema = Schema()

// Schema returns this data version schema
func Schema() abi.Arguments {
mustNewType := func(t string) abi.Type {
result, err := abi.NewType(t, "", []abi.ArgumentMarshaling{})
if err != nil {
panic(fmt.Sprintf("Unexpected error during abi.NewType: %s", err))
}
return result
}
return abi.Arguments([]abi.Argument{
{Name: "feedId", Type: mustNewType("bytes32")},
{Name: "validFromTimestamp", Type: mustNewType("uint32")},
{Name: "observationsTimestamp", Type: mustNewType("uint32")},
{Name: "nativeFee", Type: mustNewType("uint192")},
{Name: "linkFee", Type: mustNewType("uint192")},
{Name: "expiresAt", Type: mustNewType("uint32")},
{Name: "lastUpdateTimestamp", Type: mustNewType("uint64")},
{Name: "price", Type: mustNewType("int192")},
{Name: "marketStatus", Type: mustNewType("uint32")},
{Name: "currentMultiplier", Type: mustNewType("int192")},
{Name: "newMultiplier", Type: mustNewType("int192")},
{Name: "activationDateTime", Type: mustNewType("uint32")},
{Name: "tokenizedPrice", Type: mustNewType("int192")},
})
}

// Data is the container for this schema attributes
type Data struct {
FeedID feed.ID `abi:"feedId"`
ObservationsTimestamp uint32
ValidFromTimestamp uint32
ExpiresAt uint32
LinkFee *big.Int
NativeFee *big.Int
LastUpdateTimestamp uint64
Price *big.Int
MarketStatus uint32
CurrentMultiplier *big.Int
NewMultiplier *big.Int
ActivationDateTime uint32
TokenizedPrice *big.Int
}

// Schema returns this data version schema
Copy link

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

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

The comment is redundant as it duplicates the comment on line 13. Consider removing this duplicate comment or making it more specific to the method context.

Suggested change
// Schema returns this data version schema

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Keeping for consistency between earlier schemas (v8 and v9)

func (Data) Schema() abi.Arguments {
return Schema()
}

// Decode decodes the serialized data bytes
func Decode(data []byte) (*Data, error) {
values, err := schema.Unpack(data)
if err != nil {
return nil, fmt.Errorf("failed to decode report: %w", err)
}
decoded := new(Data)
if err = schema.Copy(decoded, values); err != nil {
return nil, fmt.Errorf("failed to copy report values to struct: %w", err)
}
return decoded, nil
}
55 changes: 55 additions & 0 deletions go/report/v10/data_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package v10

import (
"math/big"
"reflect"
"testing"
"time"
)

func TestData(t *testing.T) {
r := &Data{
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},
ValidFromTimestamp: uint32(time.Now().Unix()),
ObservationsTimestamp: uint32(time.Now().Unix()),
NativeFee: big.NewInt(10),
LinkFee: big.NewInt(10),
ExpiresAt: uint32(time.Now().Unix()) + 100,
LastUpdateTimestamp: uint64(time.Now().UnixNano()) - 100,
Price: big.NewInt(1100),
MarketStatus: 1,
CurrentMultiplier: big.NewInt(1000),
NewMultiplier: big.NewInt(1050),
ActivationDateTime: uint32(time.Now().Unix()) + 200,
TokenizedPrice: big.NewInt(11009),
}

b, err := schema.Pack(
r.FeedID,
r.ValidFromTimestamp,
r.ObservationsTimestamp,
r.NativeFee,
r.LinkFee,
r.ExpiresAt,
r.LastUpdateTimestamp,
r.Price,
r.MarketStatus,
r.CurrentMultiplier,
r.NewMultiplier,
r.ActivationDateTime,
r.TokenizedPrice,
)

if err != nil {
t.Errorf("failed to serialize report: %s", err)
}

d, err := Decode(b)
if err != nil {
t.Errorf("failed to deserialize report: %s", err)
}

if !reflect.DeepEqual(r, d) {
t.Errorf("expected: %#v, got %#v", r, d)
}
}