Skip to content

Commit 8cd2a70

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 76c63db commit 8cd2a70

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
@@ -203,12 +203,12 @@ func (s *BoltStore) UpdateAccount(_ context.Context,
203203
//
204204
// NOTE: This is part of the Store interface.
205205
func (s *BoltStore) UpdateAccountBalanceAndExpiry(_ context.Context,
206-
id AccountID, newBalance fn.Option[lnwire.MilliSatoshi],
206+
id AccountID, newBalance fn.Option[int64],
207207
newExpiry fn.Option[time.Time]) error {
208208

209209
update := func(account *OffChainBalanceAccount) error {
210-
newBalance.WhenSome(func(balance lnwire.MilliSatoshi) {
211-
account.CurrentBalance = int64(balance)
210+
newBalance.WhenSome(func(balance int64) {
211+
account.CurrentBalance = balance
212212
})
213213
newExpiry.WhenSome(func(expiry time.Time) {
214214
account.ExpirationDate = expiry

accounts/store_test.go

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

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

127126
acct, err := store.NewAccount(ctx, 0, time.Time{}, "foo")
128127
require.NoError(t, err)
129128

130-
assertBalanceAndExpiry := func(balance lnwire.MilliSatoshi,
129+
assertBalanceAndExpiry := func(balance int64,
131130
expiry time.Time) {
132131

133132
dbAcct, err := store.Account(ctx, acct.ID)
@@ -143,7 +142,7 @@ func TestAccountUpdateMethods(t *testing.T) {
143142
assertBalanceAndExpiry(0, time.Time{})
144143

145144
// Now, update just the balance of the account.
146-
newBalance := lnwire.MilliSatoshi(123)
145+
newBalance := int64(123)
147146
err = store.UpdateAccountBalanceAndExpiry(
148147
ctx, acct.ID, fn.Some(newBalance), fn.None[time.Time](),
149148
)
@@ -153,8 +152,7 @@ func TestAccountUpdateMethods(t *testing.T) {
153152
// Now update just the expiry of the account.
154153
newExpiry := time.Now().Add(time.Hour)
155154
err = store.UpdateAccountBalanceAndExpiry(
156-
ctx, acct.ID, fn.None[lnwire.MilliSatoshi](),
157-
fn.Some(newExpiry),
155+
ctx, acct.ID, fn.None[int64](), fn.Some(newExpiry),
158156
)
159157
require.NoError(t, err)
160158
assertBalanceAndExpiry(newBalance, newExpiry)
@@ -171,8 +169,7 @@ func TestAccountUpdateMethods(t *testing.T) {
171169
// Finally, test an update that has no net changes to the
172170
// balance or expiry.
173171
err = store.UpdateAccountBalanceAndExpiry(
174-
ctx, acct.ID, fn.None[lnwire.MilliSatoshi](),
175-
fn.None[time.Time](),
172+
ctx, acct.ID, fn.None[int64](), fn.None[time.Time](),
176173
)
177174
require.NoError(t, err)
178175
assertBalanceAndExpiry(newBalance, newExpiry)

0 commit comments

Comments
 (0)