@@ -90,9 +90,10 @@ func (m *Manager) Run(ctx context.Context) error {
90
90
}
91
91
}
92
92
93
- // NewAddress starts a new address creation flow.
93
+ // NewAddress creates a new static address with the server or returns an
94
+ // existing one.
94
95
func (m * Manager ) NewAddress (ctx context.Context ) (* btcutil.AddressTaproot ,
95
- error ) {
96
+ int64 , error ) {
96
97
97
98
// If there's already a static address in the database, we can return
98
99
// it.
@@ -101,31 +102,38 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
101
102
if err != nil {
102
103
m .Unlock ()
103
104
104
- return nil , err
105
+ return nil , 0 , err
105
106
}
106
107
if len (addresses ) > 0 {
107
108
clientPubKey := addresses [0 ].ClientPubkey
108
109
serverPubKey := addresses [0 ].ServerPubkey
109
110
expiry := int64 (addresses [0 ].Expiry )
110
111
111
- m .Unlock ()
112
+ defer m .Unlock ()
113
+
114
+ address , err := m .GetTaprootAddress (
115
+ clientPubKey , serverPubKey , expiry ,
116
+ )
117
+ if err != nil {
118
+ return nil , 0 , err
119
+ }
112
120
113
- return m . GetTaprootAddress ( clientPubKey , serverPubKey , expiry )
121
+ return address , expiry , nil
114
122
}
115
123
m .Unlock ()
116
124
117
125
// We are fetching a new L402 token from the server. There is one static
118
126
// address per L402 token allowed.
119
127
err = m .cfg .FetchL402 (ctx )
120
128
if err != nil {
121
- return nil , err
129
+ return nil , 0 , err
122
130
}
123
131
124
132
clientPubKey , err := m .cfg .WalletKit .DeriveNextKey (
125
133
ctx , swap .StaticAddressKeyFamily ,
126
134
)
127
135
if err != nil {
128
- return nil , err
136
+ return nil , 0 , err
129
137
}
130
138
131
139
// Send our clientPubKey to the server and wait for the server to
@@ -138,27 +146,27 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
138
146
},
139
147
)
140
148
if err != nil {
141
- return nil , err
149
+ return nil , 0 , err
142
150
}
143
151
144
152
serverParams := resp .GetParams ()
145
153
146
154
serverPubKey , err := btcec .ParsePubKey (serverParams .ServerKey )
147
155
if err != nil {
148
- return nil , err
156
+ return nil , 0 , err
149
157
}
150
158
151
159
staticAddress , err := script .NewStaticAddress (
152
160
input .MuSig2Version100RC2 , int64 (serverParams .Expiry ),
153
161
clientPubKey .PubKey , serverPubKey ,
154
162
)
155
163
if err != nil {
156
- return nil , err
164
+ return nil , 0 , err
157
165
}
158
166
159
167
pkScript , err := staticAddress .StaticAddressScript ()
160
168
if err != nil {
161
- return nil , err
169
+ return nil , 0 , err
162
170
}
163
171
164
172
// Create the static address from the parameters the server provided and
@@ -179,7 +187,7 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
179
187
}
180
188
err = m .cfg .Store .CreateStaticAddress (ctx , addrParams )
181
189
if err != nil {
182
- return nil , err
190
+ return nil , 0 , err
183
191
}
184
192
185
193
// Import the static address tapscript into our lnd wallet, so we can
@@ -189,15 +197,20 @@ func (m *Manager) NewAddress(ctx context.Context) (*btcutil.AddressTaproot,
189
197
)
190
198
addr , err := m .cfg .WalletKit .ImportTaprootScript (ctx , tapScript )
191
199
if err != nil {
192
- return nil , err
200
+ return nil , 0 , err
193
201
}
194
202
195
203
log .Infof ("Imported static address taproot script to lnd wallet: %v" ,
196
204
addr )
197
205
198
- return m .GetTaprootAddress (
206
+ address , err := m .GetTaprootAddress (
199
207
clientPubKey .PubKey , serverPubKey , int64 (serverParams .Expiry ),
200
208
)
209
+ if err != nil {
210
+ return nil , 0 , err
211
+ }
212
+
213
+ return address , int64 (serverParams .Expiry ), nil
201
214
}
202
215
203
216
// GetTaprootAddress returns a taproot address for the given client and server
0 commit comments