diff options
Diffstat (limited to 'c2ec/attestor.go')
-rw-r--r-- | c2ec/attestor.go | 58 |
1 files changed, 8 insertions, 50 deletions
diff --git a/c2ec/attestor.go b/c2ec/attestor.go index f268a0a..fb2bda2 100644 --- a/c2ec/attestor.go +++ b/c2ec/attestor.go @@ -18,58 +18,16 @@ func RunAttestor( errs chan error, ) { - for _, p := range CONFIG.Providers { - if PROVIDER_CLIENTS[p.Name] == nil { - err := errors.New("no provider client initialized for provider " + p.Name) - LogError("attestor", err) - errs <- err - } - } - - notifications := make(chan *Notification, PAYMENT_NOTIFICATION_CHANNEL_BUFFER_SIZE) - go listenCallback(ctx, notifications, errs) -} - -func listenCallback( - ctx context.Context, - notifications chan *Notification, - errs chan error, -) { - - listener, err := NewListener(PS_PAYMENT_NOTIFICATION_CHANNEL, notifications) - if err != nil { - LogError("attestor", err) - errs <- errors.New("attestor needs to be setup first") - } - - go func() { - LogInfo("attestor", "attestor starts listening for payment notifications at the db") - err := listener.Listen(ctx) - if err != nil { - LogError("attestor-listener", err) - errs <- err - } - close(notifications) - close(errs) - }() - - // Listen is started async. We can therefore block here and must - // not run the retrieval logic in own goroutine - for { - select { - case notification := <-notifications: - // the dispatching and further attestation can be done asynchronously - // thus not blocking further incoming notifications. - LogInfo("attestor", "received notification upon payment. channel="+notification.Channel+", payload="+notification.Payload) - go dispatch(notification, errs) - case <-ctx.Done(): - errs <- ctx.Err() - return - } - } + go RunListener( + ctx, + PS_PAYMENT_NOTIFICATION_CHANNEL, + attestationCallback, + make(chan *Notification, PAYMENT_NOTIFICATION_CHANNEL_BUFFER_SIZE), + errs, + ) } -func dispatch(notification *Notification, errs chan error) { +func attestationCallback(notification *Notification, errs chan error) { LogInfo("attestor", fmt.Sprintf("retrieved information on channel=%s with payload=%s", notification.Channel, notification.Payload)) |