Skip to content

Commit

Permalink
chore: use constants in json response
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed May 30, 2024
1 parent 3a3abd9 commit 3ef3a1e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 9 additions & 4 deletions internal/nostr/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ import (
)

const (
NIP_47_INFO_EVENT_KIND = 13194
NIP_47_REQUEST_KIND = 23194
NIP_47_RESPONSE_KIND = 23195
NIP_47_INFO_EVENT_KIND = 13194
NIP_47_REQUEST_KIND = 23194
NIP_47_RESPONSE_KIND = 23195
NIP_47_NOTIFICATION_KIND = 23196

// state of request event
REQUEST_EVENT_PUBLISH_CONFIRMED = "CONFIRMED"
REQUEST_EVENT_PUBLISH_FAILED = "FAILED"
EVENT_PUBLISHED = "PUBLISHED"
EVENT_ALREADY_PUBLISHED = "ALREADY_PUBLISHED"
WEBHOOK_RECEIVED = "WEBHOOK_RECEIVED"
SUBSCRIPTION_CLOSED = "CLOSED"
SUBSCRIPTION_ALREADY_CLOSED = "ALREADY_CLOSED"
)

type Subscription struct {
Expand Down
16 changes: 8 additions & 8 deletions internal/nostr/nostr.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ func (svc *Service) PublishHandler(c echo.Context) error {
return c.JSON(http.StatusOK, PublishResponse{
EventId: requestData.SignedEvent.ID,
RelayUrl: requestData.RelayUrl,
State: "PUBLISHED",
State: EVENT_PUBLISHED,
})
}

Expand Down Expand Up @@ -317,7 +317,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
CreatedAt: nostr.Timestamp(responseEvent.RepliedAt.Unix()),
Content: responseEvent.Content,
},
State: "ALREADY_PUBLISHED",
State: EVENT_ALREADY_PUBLISHED,
})
}
} else {
Expand Down Expand Up @@ -359,7 +359,7 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
if subscription.WebhookUrl != "" {
go svc.startSubscription(svc.Ctx, &subscription)
return c.JSON(http.StatusOK, NIP47Response{
State: "WEBHOOK_RECEIVED",
State: WEBHOOK_RECEIVED,
})
}

Expand All @@ -384,10 +384,10 @@ func (svc *Service) NIP47Handler(c echo.Context) error {
"relayUrl": requestData.RelayUrl,
"walletPubkey": requestData.WalletPubkey,
"eventId": event.ID,
}).Info("Received info event")
}).Info("Received response event")
return c.JSON(http.StatusOK, NIP47Response{
Event: event,
State: "PUBLISHED",
State: EVENT_PUBLISHED,
})
}
}
Expand Down Expand Up @@ -428,7 +428,7 @@ func (svc *Service) NIP47NotificationHandler(c echo.Context) error {
WebhookUrl: requestData.WebhookUrl,
Open: true,
Authors: &[]string{requestData.WalletPubkey},
Kinds: &[]int{23196},
Kinds: &[]int{NIP_47_NOTIFICATION_KIND},
}

tags := new(nostr.TagMap)
Expand Down Expand Up @@ -551,7 +551,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error {

return c.JSON(http.StatusAlreadyReported, StopSubscriptionResponse{
Message: "Subscription is already closed",
State: "ALREADY_CLOSED",
State: SUBSCRIPTION_ALREADY_CLOSED,
})
}

Expand All @@ -565,7 +565,7 @@ func (svc *Service) StopSubscriptionHandler(c echo.Context) error {

return c.JSON(http.StatusOK, StopSubscriptionResponse{
Message: "Subscription stopped successfully",
State: "CLOSED",
State: SUBSCRIPTION_CLOSED,
})
}

Expand Down

0 comments on commit 3ef3a1e

Please sign in to comment.