Refactored methods into pure functions.

This commit is contained in:
Jay
2025-10-31 19:48:56 -04:00
parent 67db088981
commit 4df91938ef
9 changed files with 42 additions and 42 deletions

View File

@@ -8,7 +8,7 @@ import (
// Serialize returns the canonical JSON array representation of the event.
// used for ID computation: [0, pubkey, created_at, kind, tags, content].
func (e *Event) Serialize() ([]byte, error) {
func Serialize(e Event) ([]byte, error) {
serialized := []interface{}{
0,
e.PubKey,
@@ -27,8 +27,8 @@ func (e *Event) Serialize() ([]byte, error) {
// GetID computes and returns the event ID as a lowercase, hex-encoded SHA-256 hash
// of the serialized event.
func (e *Event) GetID() (string, error) {
bytes, err := e.Serialize()
func GetID(e Event) (string, error) {
bytes, err := Serialize(e)
if err != nil {
return "", err
}