Skip to content

Commit 1c10058

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 bc4439f commit 1c10058

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
)
@@ -81,13 +82,17 @@ type BoltStore struct {
8182
*bbolt.DB
8283

8384
clock clock.Clock
85+
86+
accounts accounts.Store
8487
}
8588

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

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

@@ -111,8 +116,9 @@ func NewDB(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
111116
}
112117

113118
return &BoltStore{
114-
DB: db,
115-
clock: clock,
119+
DB: db,
120+
clock: clock,
121+
accounts: store,
116122
}, nil
117123
}
118124

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)