Skip to content

Commit 8b1c9a2

Browse files
committed
accounts: revert UpdateAccountBalanceAndExpiry balance type to be int64
In our mission to replace UpdateAccount, we need UpdatAccountBalanceAndExpiry to take a negative balance so that we can use it to replace the behaviour of UpdateAccount as it stands today.
1 parent 2724161 commit 8b1c9a2

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

accounts/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ type Store interface {
223223
// UpdateAccountBalanceAndExpiry updates the balance and/or expiry of an
224224
// account.
225225
UpdateAccountBalanceAndExpiry(ctx context.Context, id AccountID,
226-
newBalance fn.Option[lnwire.MilliSatoshi],
226+
newBalance fn.Option[int64],
227227
newExpiry fn.Option[time.Time]) error
228228

229229
// AddAccountInvoice adds an invoice hash to an account.

accounts/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ func (s *InterceptorService) UpdateAccount(ctx context.Context,
328328

329329
// If the new account balance was set, parse it as millisatoshis. A
330330
// value of -1 signals "don't update the balance".
331-
var balance fn.Option[lnwire.MilliSatoshi]
331+
var balance fn.Option[int64]
332332
if accountBalance >= 0 {
333333
// Convert from satoshis to millisatoshis for storage.
334-
balance = fn.Some(lnwire.MilliSatoshi(accountBalance) * 1000)
334+
balance = fn.Some(int64(accountBalance) * 1000)
335335
}
336336

337337
// Create the actual account in the macaroon account store.

accounts/store_kvdb.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,12 @@ func (s *BoltStore) UpdateAccount(_ context.Context,
208208
//
209209
// NOTE: This is part of the Store interface.
210210
func (s *BoltStore) UpdateAccountBalanceAndExpiry(_ context.Context,
211-
id AccountID, newBalance fn.Option[lnwire.MilliSatoshi],
211+
id AccountID, newBalance fn.Option[int64],
212212
newExpiry fn.Option[time.Time]) error {
213213

214214
update := func(account *OffChainBalanceAccount) error {
215-
newBalance.WhenSome(func(balance lnwire.MilliSatoshi) {
216-
account.CurrentBalance = int64(balance)
215+
newBalance.WhenSome(func(balance int64) {
216+
account.CurrentBalance = balance
217217
})
218218
newExpiry.WhenSome(func(expiry time.Time) {
219219
account.ExpirationDate = expiry

accounts/store_test.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/lightningnetwork/lnd/fn"
1010
"github.com/lightningnetwork/lnd/lnrpc"
1111
"github.com/lightningnetwork/lnd/lntypes"
12-
"github.com/lightningnetwork/lnd/lnwire"
1312
"github.com/stretchr/testify/require"
1413
)
1514

@@ -122,15 +121,15 @@ func TestAccountUpdateMethods(t *testing.T) {
122121
// Ensure that the function errors out if we try update an
123122
// account that does not exist.
124123
err := store.UpdateAccountBalanceAndExpiry(
125-
ctx, AccountID{}, fn.None[lnwire.MilliSatoshi](),
124+
ctx, AccountID{}, fn.None[int64](),
126125
fn.None[time.Time](),
127126
)
128127
require.ErrorIs(t, err, ErrAccNotFound)
129128

130129
acct, err := store.NewAccount(ctx, 0, time.Time{}, "foo")
131130
require.NoError(t, err)
132131

133-
assertBalanceAndExpiry := func(balance lnwire.MilliSatoshi,
132+
assertBalanceAndExpiry := func(balance int64,
134133
expiry time.Time) {
135134

136135
dbAcct, err := store.Account(ctx, acct.ID)
@@ -146,7 +145,7 @@ func TestAccountUpdateMethods(t *testing.T) {
146145
assertBalanceAndExpiry(0, time.Time{})
147146

148147
// Now, update just the balance of the account.
149-
newBalance := lnwire.MilliSatoshi(123)
148+
newBalance := int64(123)
150149
err = store.UpdateAccountBalanceAndExpiry(
151150
ctx, acct.ID, fn.Some(newBalance), fn.None[time.Time](),
152151
)
@@ -156,8 +155,7 @@ func TestAccountUpdateMethods(t *testing.T) {
156155
// Now update just the expiry of the account.
157156
newExpiry := clock.Now().Add(time.Hour)
158157
err = store.UpdateAccountBalanceAndExpiry(
159-
ctx, acct.ID, fn.None[lnwire.MilliSatoshi](),
160-
fn.Some(newExpiry),
158+
ctx, acct.ID, fn.None[int64](), fn.Some(newExpiry),
161159
)
162160
require.NoError(t, err)
163161
assertBalanceAndExpiry(newBalance, newExpiry)
@@ -174,8 +172,7 @@ func TestAccountUpdateMethods(t *testing.T) {
174172
// Finally, test an update that has no net changes to the
175173
// balance or expiry.
176174
err = store.UpdateAccountBalanceAndExpiry(
177-
ctx, acct.ID, fn.None[lnwire.MilliSatoshi](),
178-
fn.None[time.Time](),
175+
ctx, acct.ID, fn.None[int64](), fn.None[time.Time](),
179176
)
180177
require.NoError(t, err)
181178
assertBalanceAndExpiry(newBalance, newExpiry)

0 commit comments

Comments
 (0)