implement Stringer for Event.

This commit is contained in:
fiatjaf
2023-04-11 07:36:59 -03:00
parent 4507477486
commit 7b0af23f1a

View File

@@ -3,6 +3,7 @@ package nostr
import ( import (
"crypto/sha256" "crypto/sha256"
"encoding/hex" "encoding/hex"
"encoding/json"
"fmt" "fmt"
"time" "time"
@@ -41,6 +42,15 @@ const (
KindZap int = 9735 KindZap int = 9735
) )
// Event Stringer interface, just returns the raw JSON as a string
func (evt *Event) String() string {
if evt == nil {
return "null"
}
j, _ := json.Marshal(evt)
return string(j)
}
// GetID serializes and returns the event ID as a string // GetID serializes and returns the event ID as a string
func (evt *Event) GetID() string { func (evt *Event) GetID() string {
h := sha256.Sum256(evt.Serialize()) h := sha256.Sum256(evt.Serialize())