mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
ntfn: use l402 store for tokens
This commit changes the way we fetch the l402 tokens for the notification stream. Instead of fetching them from the server and paying an invoice, we now look into our local store for the token. This means that a loop client will not autofetch a token.
This commit is contained in:
parent
15ee9789d9
commit
e9f1a1aef3
3 changed files with 15 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lightninglabs/aperture/l402"
|
||||
"github.com/lightninglabs/loop/swapserverrpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
|
@ -37,8 +38,9 @@ type Config struct {
|
|||
// Client is the client used to communicate with the swap server.
|
||||
Client Client
|
||||
|
||||
// FetchL402 is the function used to fetch the l402 token.
|
||||
FetchL402 func(context.Context) error
|
||||
// CurrentToken returns the token that is currently contained in the
|
||||
// store or an l402.ErrNoToken error if there is none.
|
||||
CurrentToken func() (*l402.Token, error)
|
||||
}
|
||||
|
||||
// Manager is a manager for notifications that the swap server sends to the
|
||||
|
|
@ -113,9 +115,13 @@ func (m *Manager) Run(ctx context.Context) error {
|
|||
// the FetchL402 method. As a client might not have outbound capacity
|
||||
// yet, we'll retry until we get a valid response.
|
||||
if !m.hasL402 {
|
||||
err := m.cfg.FetchL402(ctx)
|
||||
_, err := m.cfg.CurrentToken()
|
||||
if err != nil {
|
||||
log.Errorf("Error fetching L402: %v", err)
|
||||
// We only log the error if it's not the case that we
|
||||
// don't have a token yet to avoid spamming the logs.
|
||||
if err != l402.ErrNoToken {
|
||||
log.Errorf("Error getting L402 from store: %v", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
m.hasL402 = true
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/lightninglabs/aperture/l402"
|
||||
"github.com/lightninglabs/loop/swapserverrpc"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc"
|
||||
|
|
@ -101,9 +102,9 @@ func TestManager_ReservationNotification(t *testing.T) {
|
|||
// Create a Manager with the mock client
|
||||
mgr := NewManager(&Config{
|
||||
Client: mockClient,
|
||||
FetchL402: func(ctx context.Context) error {
|
||||
CurrentToken: func() (*l402.Token, error) {
|
||||
// Simulate successful fetching of L402
|
||||
return nil
|
||||
return nil, nil
|
||||
},
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue