Skip to content

Commit

Permalink
Support v0.3 schema report format in LLO (#74)
Browse files Browse the repository at this point in the history
* Support v0.3 schema report format in LLO

- Support types of stream value other than big int
- Support multiple different methods of aggregation
- Closes MERC-3525
  • Loading branch information
samsondav authored Aug 20, 2024
1 parent fd75761 commit cf4b159
Show file tree
Hide file tree
Showing 13 changed files with 1,688 additions and 1,337 deletions.
26 changes: 26 additions & 0 deletions llo/channel_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package llo

import (
"fmt"
"sort"

llotypes "github.com/smartcontractkit/chainlink-common/pkg/types/llo"
)
Expand All @@ -27,3 +28,28 @@ func VerifyChannelDefinitions(channelDefs llotypes.ChannelDefinitions) error {
}
return nil
}

func subtractChannelDefinitions(minuend llotypes.ChannelDefinitions, subtrahend llotypes.ChannelDefinitions, limit int) llotypes.ChannelDefinitions {
differenceList := []ChannelDefinitionWithID{}
for channelID, channelDefinition := range minuend {
if _, ok := subtrahend[channelID]; !ok {
differenceList = append(differenceList, ChannelDefinitionWithID{channelDefinition, channelID})
}
}

// Sort so we return deterministic result
sort.Slice(differenceList, func(i, j int) bool {
return differenceList[i].ChannelID < differenceList[j].ChannelID
})

if len(differenceList) > limit {
differenceList = differenceList[:limit]
}

difference := llotypes.ChannelDefinitions{}
for _, defWithID := range differenceList {
difference[defWithID.ChannelID] = defWithID.ChannelDefinition
}

return difference
}
3 changes: 3 additions & 0 deletions llo/json_codec.go → llo/json_report_codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ func (cdc JSONReportCodec) Encode(r Report, _ llotypes.ChannelDefinition) ([]byt
}
values := make([]JSONStreamValue, len(r.Values))
for i, sv := range r.Values {
if sv == nil {
return nil, ErrNilStreamValue
}
b, err := sv.MarshalText()
if err != nil {
return nil, fmt.Errorf("failed to encode StreamValue: %w", err)
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions llo/onchain_config.go

This file was deleted.

Loading

0 comments on commit cf4b159

Please sign in to comment.