Skip to content

Commit

Permalink
add Type to Event JSON response
Browse files Browse the repository at this point in the history
  • Loading branch information
chris124567 committed Dec 3, 2024
1 parent 206cccb commit ef766a5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions explorer/events.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package explorer

import (
"encoding/json"
"time"

"go.sia.tech/core/consensus"
Expand Down Expand Up @@ -37,6 +38,20 @@ type Event struct {
Data eventData `json:"data"`
}

// MarshalJSON implements the json.Marshaler interface.
func (e Event) MarshalJSON() ([]byte, error) {
type Alias Event

// Marshal a new struct with the additional `Type` field.
return json.Marshal(&struct {
Alias
Type string `json:"type"`
}{
Alias: Alias(e),
Type: e.Data.EventType(),
})
}

// EventType implements Event.
func (*EventTransaction) EventType() string { return EventTypeTransaction }

Expand Down

0 comments on commit ef766a5

Please sign in to comment.