mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
accounts: pass Store impl to NewService
We want to be able to pass different DB implementations to NewService. In preparation for this, we make it implementation agnostic by letting it take a `Store` instead of constructing one itself. This this change, we also let LiT handle the closing of the accounts Store instead of the accounts service
This commit is contained in:
parent
86fc2ccf79
commit
82eeadd819
4 changed files with 34 additions and 15 deletions
|
|
@ -523,7 +523,9 @@ func testSendPayment(t *testing.T, uri string) {
|
|||
errFunc := func(err error) {
|
||||
lndMock.mainErrChan <- err
|
||||
}
|
||||
service, err := NewService(t.TempDir(), errFunc)
|
||||
store, err := NewBoltStore(t.TempDir(), DBFilename)
|
||||
require.NoError(t, err)
|
||||
service, err := NewService(store, errFunc)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.Start(ctx, lndMock, routerMock, chainParams)
|
||||
|
|
@ -719,7 +721,9 @@ func TestSendPaymentV2(t *testing.T) {
|
|||
errFunc := func(err error) {
|
||||
lndMock.mainErrChan <- err
|
||||
}
|
||||
service, err := NewService(t.TempDir(), errFunc)
|
||||
store, err := NewBoltStore(t.TempDir(), DBFilename)
|
||||
require.NoError(t, err)
|
||||
service, err := NewService(store, errFunc)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.Start(ctx, lndMock, routerMock, chainParams)
|
||||
|
|
@ -906,7 +910,9 @@ func TestSendToRouteV2(t *testing.T) {
|
|||
errFunc := func(err error) {
|
||||
lndMock.mainErrChan <- err
|
||||
}
|
||||
service, err := NewService(t.TempDir(), errFunc)
|
||||
store, err := NewBoltStore(t.TempDir(), DBFilename)
|
||||
require.NoError(t, err)
|
||||
service, err := NewService(store, errFunc)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = service.Start(ctx, lndMock, routerMock, chainParams)
|
||||
|
|
|
|||
|
|
@ -78,16 +78,11 @@ type InterceptorService struct {
|
|||
|
||||
// NewService returns a service backed by the macaroon Bolt DB stored in the
|
||||
// passed-in directory.
|
||||
func NewService(dir string,
|
||||
errCallback func(error)) (*InterceptorService, error) {
|
||||
|
||||
accountStore, err := NewBoltStore(dir, DBFilename)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func NewService(store Store, errCallback func(error)) (*InterceptorService,
|
||||
error) {
|
||||
|
||||
return &InterceptorService{
|
||||
store: accountStore,
|
||||
store: store,
|
||||
invoiceToAccount: make(map[lntypes.Hash]AccountID),
|
||||
pendingPayments: make(map[lntypes.Hash]*trackedPayment),
|
||||
requestValuesStore: newRequestValuesStore(),
|
||||
|
|
@ -242,7 +237,7 @@ func (s *InterceptorService) Stop() error {
|
|||
close(s.quit)
|
||||
s.wg.Wait()
|
||||
|
||||
return s.store.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsRunning checks if the account service is running, and returns a boolean
|
||||
|
|
|
|||
|
|
@ -243,7 +243,7 @@ func TestAccountService(t *testing.T) {
|
|||
// Start by closing the store. This should cause an
|
||||
// error once we make an invoice update, as the service
|
||||
// will fail when persisting the invoice update.
|
||||
s.store.Close()
|
||||
require.NoError(t, s.store.Close())
|
||||
|
||||
// Ensure that the service was started successfully and
|
||||
// still running though, despite the closing of the
|
||||
|
|
@ -833,7 +833,9 @@ func TestAccountService(t *testing.T) {
|
|||
errFunc := func(err error) {
|
||||
lndMock.mainErrChan <- err
|
||||
}
|
||||
service, err := NewService(t.TempDir(), errFunc)
|
||||
store, err := NewBoltStore(t.TempDir(), DBFilename)
|
||||
require.NoError(tt, err)
|
||||
service, err := NewService(store, errFunc)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Is a setup call required to initialize initial
|
||||
|
|
|
|||
18
terminal.go
18
terminal.go
|
|
@ -214,6 +214,7 @@ type LightningTerminal struct {
|
|||
middleware *mid.Manager
|
||||
middlewareStarted bool
|
||||
|
||||
accountsStore *accounts.BoltStore
|
||||
accountService *accounts.InterceptorService
|
||||
accountServiceStarted bool
|
||||
|
||||
|
|
@ -412,8 +413,15 @@ func (g *LightningTerminal) start(ctx context.Context) error {
|
|||
)
|
||||
}
|
||||
|
||||
g.accountsStore, err = accounts.NewBoltStore(
|
||||
filepath.Dir(g.cfg.MacaroonPath), accounts.DBFilename,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating accounts store: %w", err)
|
||||
}
|
||||
|
||||
g.accountService, err = accounts.NewService(
|
||||
filepath.Dir(g.cfg.MacaroonPath), accountServiceErrCallback,
|
||||
g.accountsStore, accountServiceErrCallback,
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating account service: %v", err)
|
||||
|
|
@ -1421,6 +1429,14 @@ func (g *LightningTerminal) shutdownSubServers() error {
|
|||
}
|
||||
}
|
||||
|
||||
if g.accountsStore != nil {
|
||||
err = g.accountsStore.Close()
|
||||
if err != nil {
|
||||
log.Errorf("Error closing accounts store: %v", err)
|
||||
returnErr = err
|
||||
}
|
||||
}
|
||||
|
||||
if g.middlewareStarted {
|
||||
g.middleware.Stop()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue