Skip to content

Commit 565ebe8

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 44625c3 commit 565ebe8

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

session/kvdb_store.go

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

1313
"github.com/btcsuite/btcd/btcec/v2"
14+
"github.com/lightninglabs/lightning-terminal/accounts"
1415
"github.com/lightningnetwork/lnd/clock"
1516
"go.etcd.io/bbolt"
1617
"gopkg.in/macaroon-bakery.v2/bakery"
@@ -83,13 +84,17 @@ type BoltStore struct {
8384
*bbolt.DB
8485

8586
clock clock.Clock
87+
88+
accounts accounts.Store
8689
}
8790

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

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

@@ -113,8 +118,9 @@ func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
113118
}
114119

115120
return &BoltStore{
116-
DB: db,
117-
clock: clock,
121+
DB: db,
122+
clock: clock,
123+
accounts: store,
118124
}, nil
119125
}
120126

session/test_kvdb.go

Lines changed: 19 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,24 @@ 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+
store, err := NewDB(dbPath, DBFilename, clock, acctStore)
24+
require.NoError(t, err)
25+
26+
t.Cleanup(func() {
27+
require.NoError(t, store.DB.Close())
28+
})
29+
30+
return store
31+
}
32+
33+
// NewTestDBWithAccounts creates a new test session Store with access to an
34+
// existing accounts DB.
35+
func NewTestDBWithAccounts(t *testing.T, clock clock.Clock,
36+
acctStore accounts.Store) *BoltStore {
37+
38+
store, err := NewDB(t.TempDir(), DBFilename, clock, acctStore)
2139
require.NoError(t, err)
2240

2341
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)