mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
accounts: export kvdb DB
The next commit that adds the kvdb to sql code migration will need to initialize the accounts kvdb DB. This commit exports that struct so that it can be referenced outside of the accounts package.
This commit is contained in:
parent
0c6b3c0539
commit
9c6464f7e4
5 changed files with 17 additions and 17 deletions
|
|
@ -370,7 +370,7 @@ func (s *InterceptorService) CreditAccount(ctx context.Context,
|
|||
return nil, ErrAccountServiceDisabled
|
||||
}
|
||||
|
||||
// Credit the account in the db.
|
||||
// Credit the account in the DB.
|
||||
err := s.store.CreditAccount(ctx, accountID, amount)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to credit account: %w", err)
|
||||
|
|
@ -395,7 +395,7 @@ func (s *InterceptorService) DebitAccount(ctx context.Context,
|
|||
return nil, ErrAccountServiceDisabled
|
||||
}
|
||||
|
||||
// Debit the account in the db.
|
||||
// Debit the account in the DB.
|
||||
err := s.store.DebitAccount(ctx, accountID, amount)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to debit account: %w", err)
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ func TestAccountService(t *testing.T) {
|
|||
|
||||
// Ensure that the service was started successfully and
|
||||
// still running though, despite the closing of the
|
||||
// db store.
|
||||
// DB store.
|
||||
require.True(t, s.IsRunning())
|
||||
|
||||
// Now let's send the invoice update, which should fail.
|
||||
|
|
|
|||
|
|
@ -300,7 +300,7 @@ func TestAccountStoreMigration(t *testing.T) {
|
|||
)
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, kvStore.db.Close())
|
||||
require.NoError(t, kvStore.DB.Close())
|
||||
})
|
||||
|
||||
// Populate the kv store.
|
||||
|
|
@ -335,7 +335,7 @@ func TestAccountStoreMigration(t *testing.T) {
|
|||
ctx, sqldb.WriteTxOpt(),
|
||||
func(tx *sqlcmig6.Queries) error {
|
||||
return MigrateAccountStoreToSQL(
|
||||
ctx, kvStore.db, tx,
|
||||
ctx, kvStore.DB, tx,
|
||||
)
|
||||
}, sqldb.NoOpReset,
|
||||
)
|
||||
|
|
@ -439,7 +439,7 @@ func rapidRandomizeAccounts(t *testing.T, kvStore *BoltStore) {
|
|||
acct := makeAccountGen().Draw(t, "account")
|
||||
|
||||
// Then proceed to insert the account with its invoices and
|
||||
// payments into the db
|
||||
// payments into the DB
|
||||
newAcct, err := kvStore.NewAccount(
|
||||
ctx, acct.balance, acct.expiry, acct.label,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ var (
|
|||
|
||||
// BoltStore wraps the bolt DB that stores all accounts and their balances.
|
||||
type BoltStore struct {
|
||||
db kvdb.Backend
|
||||
DB kvdb.Backend
|
||||
clock clock.Clock
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ func NewBoltStore(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
|
|||
|
||||
// Return the DB wrapped in a BoltStore object.
|
||||
return &BoltStore{
|
||||
db: db,
|
||||
DB: db,
|
||||
clock: clock,
|
||||
}, nil
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func NewBoltStore(dir, fileName string, clock clock.Clock) (*BoltStore, error) {
|
|||
//
|
||||
// NOTE: This is part of the Store interface.
|
||||
func (s *BoltStore) Close() error {
|
||||
return s.db.Close()
|
||||
return s.DB.Close()
|
||||
}
|
||||
|
||||
// NewAccount creates a new OffChainBalanceAccount with the given balance and a
|
||||
|
|
@ -156,7 +156,7 @@ func (s *BoltStore) NewAccount(ctx context.Context, balance lnwire.MilliSatoshi,
|
|||
|
||||
// Try storing the account in the account database, so we can keep track
|
||||
// of its balance.
|
||||
err := s.db.Update(func(tx walletdb.ReadWriteTx) error {
|
||||
err := s.DB.Update(func(tx walletdb.ReadWriteTx) error {
|
||||
bucket := tx.ReadWriteBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
@ -402,7 +402,7 @@ func (s *BoltStore) DeleteAccountPayment(_ context.Context, id AccountID,
|
|||
func (s *BoltStore) updateAccount(id AccountID,
|
||||
updateFn func(*OffChainBalanceAccount) error) error {
|
||||
|
||||
return s.db.Update(func(tx kvdb.RwTx) error {
|
||||
return s.DB.Update(func(tx kvdb.RwTx) error {
|
||||
bucket := tx.ReadWriteBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
@ -489,7 +489,7 @@ func (s *BoltStore) Account(_ context.Context, id AccountID) (
|
|||
// Try looking up and reading the account by its ID from the local
|
||||
// bolt DB.
|
||||
var accountBinary []byte
|
||||
err := s.db.View(func(tx kvdb.RTx) error {
|
||||
err := s.DB.View(func(tx kvdb.RTx) error {
|
||||
bucket := tx.ReadBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
@ -531,7 +531,7 @@ func (s *BoltStore) Accounts(_ context.Context) ([]*OffChainBalanceAccount,
|
|||
error) {
|
||||
|
||||
var accounts []*OffChainBalanceAccount
|
||||
err := s.db.View(func(tx kvdb.RTx) error {
|
||||
err := s.DB.View(func(tx kvdb.RTx) error {
|
||||
// This function will be called in the ForEach and receive
|
||||
// the key and value of each account in the DB. The key, which
|
||||
// is also the ID is not used because it is also marshaled into
|
||||
|
|
@ -575,7 +575,7 @@ func (s *BoltStore) Accounts(_ context.Context) ([]*OffChainBalanceAccount,
|
|||
//
|
||||
// NOTE: This is part of the Store interface.
|
||||
func (s *BoltStore) RemoveAccount(_ context.Context, id AccountID) error {
|
||||
return s.db.Update(func(tx kvdb.RwTx) error {
|
||||
return s.DB.Update(func(tx kvdb.RwTx) error {
|
||||
bucket := tx.ReadWriteBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
@ -598,7 +598,7 @@ func (s *BoltStore) LastIndexes(_ context.Context) (uint64, uint64, error) {
|
|||
var (
|
||||
addValue, settleValue []byte
|
||||
)
|
||||
err := s.db.View(func(tx kvdb.RTx) error {
|
||||
err := s.DB.View(func(tx kvdb.RTx) error {
|
||||
bucket := tx.ReadBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
@ -644,7 +644,7 @@ func (s *BoltStore) StoreLastIndexes(_ context.Context, addIndex,
|
|||
byteOrder.PutUint64(addValue, addIndex)
|
||||
byteOrder.PutUint64(settleValue, settleIndex)
|
||||
|
||||
return s.db.Update(func(tx kvdb.RwTx) error {
|
||||
return s.DB.Update(func(tx kvdb.RwTx) error {
|
||||
bucket := tx.ReadWriteBucket(accountBucketName)
|
||||
if bucket == nil {
|
||||
return ErrAccountBucketNotFound
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func NewTestDBFromPath(t *testing.T, dbPath string,
|
|||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
require.NoError(t, store.db.Close())
|
||||
require.NoError(t, store.DB.Close())
|
||||
})
|
||||
|
||||
return store
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue