Skip to content

Commit

Permalink
fix: move StartSubscription to start.go
Browse files Browse the repository at this point in the history
  • Loading branch information
frnandu committed Oct 29, 2024
1 parent aa2c3c1 commit 9f69b1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
25 changes: 0 additions & 25 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,6 @@ func (svc *service) noticeHandler(notice string) {
logger.Logger.Infof("Received a notice %s", notice)
}

func (svc *service) StartSubscription(ctx context.Context, sub *nostr.Subscription) error {
svc.nip47Service.StartNotifier(ctx, sub.Relay, svc.lnClient)

go func() {
// block till EOS is received
<-sub.EndOfStoredEvents
logger.Logger.Debug("Received EOS")

// loop through incoming events
for event := range sub.Events {
go svc.nip47Service.HandleEvent(ctx, sub.Relay, event, svc.lnClient)
}
logger.Logger.Debug("Relay subscription events channel ended")
}()

<-ctx.Done()

if sub.Relay.ConnectionError != nil {
logger.Logger.WithField("connectionError", sub.Relay.ConnectionError).Error("Relay error")
return sub.Relay.ConnectionError
}
logger.Logger.Info("Exiting subscription...")
return nil
}

func finishRestoreNode(workDir string) error {
restoreDir := filepath.Join(workDir, "restore")
if restoreDirStat, err := os.Stat(restoreDir); err == nil && restoreDirStat.IsDir() {
Expand Down
25 changes: 25 additions & 0 deletions service/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,31 @@ func (svc *service) startAppWalletSubscription(ctx context.Context, relay *nostr
return nil
}

func (svc *service) StartSubscription(ctx context.Context, sub *nostr.Subscription) error {
svc.nip47Service.StartNotifier(ctx, sub.Relay, svc.lnClient)

go func() {
// block till EOS is received
<-sub.EndOfStoredEvents
logger.Logger.Debug("Received EOS")

// loop through incoming events
for event := range sub.Events {
go svc.nip47Service.HandleEvent(ctx, sub.Relay, event, svc.lnClient)
}
logger.Logger.Debug("Relay subscription events channel ended")
}()

<-ctx.Done()

if sub.Relay.ConnectionError != nil {
logger.Logger.WithField("connectionError", sub.Relay.ConnectionError).Error("Relay error")
return sub.Relay.ConnectionError
}
logger.Logger.Info("Exiting subscription...")
return nil
}

func (svc *service) StartApp(encryptionKey string) error {
if svc.lnClient != nil {
return errors.New("app already started")
Expand Down

0 comments on commit 9f69b1a

Please sign in to comment.