session+terminal: give session Store access to the accounts store

When we link a session to an account, we want to be able to validate
that the account actually does exist. So in preparation for that, we
first give the session store access to the accounts store.
This commit is contained in:
Elle Mouton 2025-02-27 08:31:44 +02:00
parent 64dba89bb6
commit 2717aa0bc2
No known key found for this signature in database
GPG key ID: D7D916376026F177
3 changed files with 30 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import (
"time"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/lightninglabs/lightning-terminal/accounts"
"github.com/lightningnetwork/lnd/clock"
"go.etcd.io/bbolt"
)
@ -82,13 +83,17 @@ type BoltStore struct {
*bbolt.DB
clock clock.Clock
accounts accounts.Store
}
// A compile-time check to ensure that BoltStore implements the Store interface.
var _ Store = (*BoltStore)(nil)
// NewDB creates a new bolt database that can be found at the given directory.
func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
func NewDB(dir, fileName string, clock clock.Clock,
store accounts.Store) (*BoltStore, error) {
firstInit := false
path := filepath.Join(dir, fileName)
@ -112,8 +117,9 @@ func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
}
return &BoltStore{
DB: db,
clock: clock,
DB: db,
clock: clock,
accounts: store,
}, nil
}

View file

@ -3,6 +3,7 @@ package session
import (
"testing"
"github.com/lightninglabs/lightning-terminal/accounts"
"github.com/lightningnetwork/lnd/clock"
"github.com/stretchr/testify/require"
)
@ -17,7 +18,23 @@ func NewTestDB(t *testing.T, clock clock.Clock) *BoltStore {
func NewTestDBFromPath(t *testing.T, dbPath string,
clock clock.Clock) *BoltStore {
store, err := NewDB(dbPath, DBFilename, clock)
acctStore := accounts.NewTestDB(t, clock)
return newDBFromPathWithAccounts(t, clock, dbPath, acctStore)
}
// NewTestDBWithAccounts creates a new test session Store with access to an
// existing accounts DB.
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
acctStore accounts.Store) *BoltStore {
return newDBFromPathWithAccounts(t, clock, t.TempDir(), acctStore)
}
func newDBFromPathWithAccounts(t *testing.T, clock clock.Clock, dbPath string,
acctStore accounts.Store) *BoltStore {
store, err := NewDB(dbPath, DBFilename, clock, acctStore)
require.NoError(t, err)
t.Cleanup(func() {

View file

@ -449,7 +449,9 @@ func (g *LightningTerminal) start(ctx context.Context) error {
g.ruleMgrs = rules.NewRuleManagerSet()
// Create an instance of the local Terminal Connect session store DB.
g.sessionDB, err = session.NewDB(networkDir, session.DBFilename, clock)
g.sessionDB, err = session.NewDB(
networkDir, session.DBFilename, clock, g.accountsStore,
)
if err != nil {
return fmt.Errorf("error creating session DB: %v", err)
}