Skip to content

Commit

Permalink
missing mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
anatolie-ssv committed Feb 6, 2025
1 parent c2b6260 commit b008504
Showing 1 changed file with 62 additions and 21 deletions.
83 changes: 62 additions & 21 deletions api/handlers/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,20 @@ type decided struct {
}

type round struct {
Proposer spectypes.OperatorID `json:"proposer"`
Prepares []message `json:"prepares"`
Commits []message `json:"commits"`
RoundChanges []roundChange `json:"roundChanges"`
ProposalTrace *proposalTrace `json:"proposal"`
Proposer spectypes.OperatorID `json:"proposer"`
Prepares []message `json:"prepares"`
Commits []message `json:"commits"`
RoundChanges []roundChange `json:"roundChanges"`
}

type proposalTrace struct {
Round uint64 `json:"round"`
BeaconRoot phase0.Root `json:"beaconRoot"`
Signer spectypes.OperatorID `json:"signer"`
RoundChanges []roundChange `json:"roundChanges"`
PrepareMessages []message `json:"prepareMessages"`
ReceivedTime time.Time `json:"time"`
}

type roundChange struct {
Expand All @@ -50,14 +60,20 @@ type message struct {
ReceivedTime time.Time `json:"time"`
}

type partialSigMessage struct {
BeaconRoot phase0.Root `json:"beaconRoot"`
Signer spectypes.OperatorID `json:"signer"`
Validator phase0.ValidatorIndex `json:"validator"`
}

func toValidatorTrace(t *model.ValidatorDutyTrace) validatorTrace {
return validatorTrace{
Slot: t.Slot,
Role: t.Role,
Validator: t.Validator,
Pre: toMessageTrace(t.Pre),
Post: toMessageTrace(t.Post),
Rounds: toRoundTrace(t.Rounds),
Rounds: toRounds(t.Rounds),
}

Check warning on line 77 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L69-L77

Added lines #L69 - L77 were not covered by tests
}

Expand All @@ -72,18 +88,33 @@ func toMessageTrace(m []*model.PartialSigMessageTrace) (out []message) {
return

Check warning on line 88 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L80-L88

Added lines #L80 - L88 were not covered by tests
}

func toRoundTrace(r []*model.RoundTrace) (out []round) {
func toRounds(r []*model.RoundTrace) (out []round) {
for _, rt := range r {
out = append(out, round{
Proposer: rt.Proposer,
Prepares: toUIMessageTrace(rt.Prepares),
Commits: toUIMessageTrace(rt.Commits),
RoundChanges: toUIRoundChangeTrace(rt.RoundChanges),
ProposalTrace: toProposalTrace(rt.ProposalTrace),
Proposer: rt.Proposer,
Prepares: toUIMessageTrace(rt.Prepares),
Commits: toUIMessageTrace(rt.Commits),
RoundChanges: toUIRoundChangeTrace(rt.RoundChanges),
})
}
return

Check warning on line 101 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L91-L101

Added lines #L91 - L101 were not covered by tests
}

func toProposalTrace(rt *model.ProposalTrace) *proposalTrace {
if rt == nil {
return nil
}
return &proposalTrace{
Round: rt.Round,
BeaconRoot: rt.BeaconRoot,
Signer: rt.Signer,
RoundChanges: toUIRoundChangeTrace(rt.RoundChanges),
PrepareMessages: toUIMessageTrace(rt.PrepareMessages),
ReceivedTime: rt.ReceivedTime,
}

Check warning on line 115 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L104-L115

Added lines #L104 - L115 were not covered by tests
}

func toUIMessageTrace(m []*model.MessageTrace) (out []message) {
for _, mt := range m {
out = append(out, message{
Expand Down Expand Up @@ -130,18 +161,17 @@ type committeeTrace struct {
}

type committeeMessage struct {
message
BeaconRoot []phase0.Root `json:"beaconRoot"`
Validators []phase0.ValidatorIndex `json:"validators"`
Signer spectypes.OperatorID `json:"signer"`
ReceivedTime time.Time `json:"time"`
Type spectypes.PartialSigMsgType `json:"type"`
Signer spectypes.OperatorID `json:"signer"`
Messages []partialSigMessage `json:"messages"`
ReceivedTime time.Time `json:"time"`
}

func toCommitteeTrace(t *model.CommitteeDutyTrace) committeeTrace {
return committeeTrace{
Slot: t.Slot,
Rounds: toRoundTrace(t.Rounds),
Post: toCommitteeMessageTrace(t.Post),
Rounds: toRounds(t.Rounds),
Post: toCommitteePost(t.Post),
CommitteeID: hex.EncodeToString(t.CommitteeID[:]),
OperatorIDs: t.OperatorIDs,
Decideds: toDecidedTrace(t.Decideds),
Expand All @@ -161,15 +191,26 @@ func toDecidedTrace(d []*model.DecidedTrace) (out []decided) {
return

Check warning on line 191 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L191

Added line #L191 was not covered by tests
}

func toCommitteeMessageTrace(m []*model.CommitteePartialSigMessageTrace) (out []committeeMessage) {
func toCommitteePost(m []*model.CommitteePartialSigMessageTrace) (out []committeeMessage) {
for _, mt := range m {
out = append(out, committeeMessage{
// Type: mt.Type,
// BeaconRoot: mt.BeaconRoot,
// Validators: mt.Validators,
Type: mt.Type,
Signer: mt.Signer,
ReceivedTime: mt.ReceivedTime,
Messages: toUIPartSigMessage(mt.Messages),
})
}
return

Check warning on line 203 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L194-L203

Added lines #L194 - L203 were not covered by tests
}

func toUIPartSigMessage(m []*model.PartialSigMessage) (out []partialSigMessage) {
for _, mt := range m {
out = append(out, partialSigMessage{
BeaconRoot: mt.BeaconRoot,
Signer: mt.Signer,
Validator: mt.ValidatorIndex,
})
}

Check warning on line 213 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L206-L213

Added lines #L206 - L213 were not covered by tests

return

Check warning on line 215 in api/handlers/model.go

View check run for this annotation

Codecov / codecov/patch

api/handlers/model.go#L215

Added line #L215 was not covered by tests
}

0 comments on commit b008504

Please sign in to comment.