Skip to content

Commit 2717aa0

Browse files
committed
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.
1 parent 64dba89 commit 2717aa0

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

session/kvdb_store.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"time"
1313

1414
"github.com/btcsuite/btcd/btcec/v2"
15+
"github.com/lightninglabs/lightning-terminal/accounts"
1516
"github.com/lightningnetwork/lnd/clock"
1617
"go.etcd.io/bbolt"
1718
)
@@ -82,13 +83,17 @@ type BoltStore struct {
8283
*bbolt.DB
8384

8485
clock clock.Clock
86+
87+
accounts accounts.Store
8588
}
8689

8790
// A compile-time check to ensure that BoltStore implements the Store interface.
8891
var _ Store = (*BoltStore)(nil)
8992

9093
// NewDB creates a new bolt database that can be found at the given directory.
91-
func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
94+
func NewDB(dir, fileName string, clock clock.Clock,
95+
store accounts.Store) (*BoltStore, error) {
96+
9297
firstInit := false
9398
path := filepath.Join(dir, fileName)
9499

@@ -112,8 +117,9 @@ func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
112117
}
113118

114119
return &BoltStore{
115-
DB: db,
116-
clock: clock,
120+
DB: db,
121+
clock: clock,
122+
accounts: store,
117123
}, nil
118124
}
119125

session/test_kvdb.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package session
33
import (
44
"testing"
55

6+
"github.com/lightninglabs/lightning-terminal/accounts"
67
"github.com/lightningnetwork/lnd/clock"
78
"github.com/stretchr/testify/require"
89
)
@@ -17,7 +18,23 @@ func NewTestDB(t *testing.T, clock clock.Clock) *BoltStore {
1718
func NewTestDBFromPath(t *testing.T, dbPath string,
1819
clock clock.Clock) *BoltStore {
1920

20-
store, err := NewDB(dbPath, DBFilename, clock)
21+
acctStore := accounts.NewTestDB(t, clock)
22+
23+
return newDBFromPathWithAccounts(t, clock, dbPath, acctStore)
24+
}
25+
26+
// NewTestDBWithAccounts creates a new test session Store with access to an
27+
// existing accounts DB.
28+
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
29+
acctStore accounts.Store) *BoltStore {
30+
31+
return newDBFromPathWithAccounts(t, clock, t.TempDir(), acctStore)
32+
}
33+
34+
func newDBFromPathWithAccounts(t *testing.T, clock clock.Clock, dbPath string,
35+
acctStore accounts.Store) *BoltStore {
36+
37+
store, err := NewDB(dbPath, DBFilename, clock, acctStore)
2138
require.NoError(t, err)
2239

2340
t.Cleanup(func() {

terminal.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,9 @@ func (g *LightningTerminal) start(ctx context.Context) error {
449449
g.ruleMgrs = rules.NewRuleManagerSet()
450450

451451
// Create an instance of the local Terminal Connect session store DB.
452-
g.sessionDB, err = session.NewDB(networkDir, session.DBFilename, clock)
452+
g.sessionDB, err = session.NewDB(
453+
networkDir, session.DBFilename, clock, g.accountsStore,
454+
)
453455
if err != nil {
454456
return fmt.Errorf("error creating session DB: %v", err)
455457
}

0 commit comments

Comments
 (0)