Skip to content

Commit 369b52c

Browse files
committed
staticaddr: return error if address already exists
1 parent 38d7401 commit 369b52c

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

staticaddr/address/interface.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ package address
22

33
import (
44
"context"
5-
"fmt"
65

76
"github.com/btcsuite/btcd/btcec/v2"
87
"github.com/lightninglabs/loop/staticaddr/version"
98
"github.com/lightningnetwork/lnd/keychain"
9+
"google.golang.org/grpc/codes"
10+
"google.golang.org/grpc/status"
1011
)
1112

1213
var (
13-
ErrAddressAlreadyExists = fmt.Errorf("address already exists")
14+
ErrAddressAlreadyExists = status.Error(codes.AlreadyExists,
15+
"address already exists")
1416
)
1517

1618
// Store is the database interface that is used to store and retrieve

staticaddr/address/manager.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,15 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
9797
// If there's already a static address in the database, we can return
9898
// it.
9999
m.Lock()
100+
defer m.Unlock()
101+
100102
addresses, err := m.cfg.Store.GetAllStaticAddresses(ctx)
101103
if err != nil {
102-
m.Unlock()
103-
104104
return nil, err
105105
}
106106
if len(addresses) > 0 {
107-
clientPubKey := addresses[0].ClientPubkey
108-
serverPubKey := addresses[0].ServerPubkey
109-
expiry := int64(addresses[0].Expiry)
110-
111-
m.Unlock()
112-
113-
return m.GetTaprootAddress(clientPubKey, serverPubKey, expiry)
107+
return nil, ErrAddressAlreadyExists
114108
}
115-
m.Unlock()
116109

117110
// We are fetching a new L402 token from the server. There is one static
118111
// address per L402 token allowed.

0 commit comments

Comments
 (0)