-
Notifications
You must be signed in to change notification settings - Fork 8
Go: Add FeedVersion10 #25
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ const ( | |
| FeedVersion4 | ||
| FeedVersion8 | ||
| FeedVersion9 | ||
| FeedVersion10 | ||
| _ | ||
| ) | ||
|
|
||
|
|
||
This file contains hidden or 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 hidden or 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,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 | ||
| 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 | ||
| } | ||
This file contains hidden or 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,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) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)