Skip to content

Commit 10be4cd

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

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
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: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,11 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
100100
addresses, err := m.cfg.Store.GetAllStaticAddresses(ctx)
101101
if err != nil {
102102
m.Unlock()
103-
104103
return nil, err
105104
}
106105
if len(addresses) > 0 {
107-
clientPubKey := addresses[0].ClientPubkey
108-
serverPubKey := addresses[0].ServerPubkey
109-
expiry := int64(addresses[0].Expiry)
110-
111106
m.Unlock()
112-
113-
return m.GetTaprootAddress(clientPubKey, serverPubKey, expiry)
107+
return nil, ErrAddressAlreadyExists
114108
}
115109
m.Unlock()
116110

0 commit comments

Comments
 (0)