From ef766a5649e637e36ab07d20f78762488e9d64fd Mon Sep 17 00:00:00 2001 From: Christopher Tarry Date: Tue, 3 Dec 2024 15:27:24 -0500 Subject: [PATCH] add Type to Event JSON response --- explorer/events.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/explorer/events.go b/explorer/events.go index 9328961..9e231a9 100644 --- a/explorer/events.go +++ b/explorer/events.go @@ -1,6 +1,7 @@ package explorer import ( + "encoding/json" "time" "go.sia.tech/core/consensus" @@ -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 }