1
1
package deposit
2
2
3
3
import (
4
+ "context"
4
5
"encoding/hex"
5
6
"fmt"
6
7
"time"
7
8
9
+ "github.com/btcsuite/btcd/btcec/v2"
8
10
"github.com/btcsuite/btcd/wire"
9
11
"github.com/btcsuite/btcwallet/wtxmgr"
12
+ "github.com/lightninglabs/loop/assets"
10
13
"github.com/lightninglabs/taproot-assets/proof"
11
14
)
12
15
@@ -130,9 +133,11 @@ type DepositInfo struct {
130
133
// only set if the deposit has been confirmed.
131
134
Expiry uint32
132
135
133
- // SweepAddr is the address we'll use to sweep the deposit back after
134
- // timeout or if cooperatively withdrawing.
135
- SweepAddr string
136
+ // SweepScriptKey is the script key of the swept asset.
137
+ SweepScriptKey * btcec.PublicKey
138
+
139
+ // SweepInternalKey is the internal key of output of the swept asset.
140
+ SweepInternalKey * btcec.PublicKey
136
141
}
137
142
138
143
// Copy creates a copy of the DepositInfo struct.
@@ -146,7 +151,6 @@ func (d *DepositInfo) Copy() *DepositInfo {
146
151
State : d .State ,
147
152
ConfirmationHeight : d .ConfirmationHeight ,
148
153
Expiry : d .Expiry ,
149
- SweepAddr : d .SweepAddr ,
150
154
}
151
155
152
156
if d .Outpoint != nil {
@@ -156,6 +160,16 @@ func (d *DepositInfo) Copy() *DepositInfo {
156
160
}
157
161
}
158
162
163
+ if d .SweepScriptKey != nil {
164
+ pubKey := * d .SweepScriptKey
165
+ info .SweepScriptKey = & pubKey
166
+ }
167
+
168
+ if d .SweepInternalKey != nil {
169
+ pubKey := * d .SweepInternalKey
170
+ info .SweepInternalKey = & pubKey
171
+ }
172
+
159
173
return info
160
174
}
161
175
@@ -175,10 +189,22 @@ type Deposit struct {
175
189
AnchorRootHash []byte
176
190
}
177
191
178
- // label returns a string label that we can use for marking a transfer funding
179
- // the deposit. This is useful if we need to filter deposits.
180
- func (d * Deposit ) label () string {
181
- return fmt .Sprintf ("deposit %v" , d .ID )
192
+ // fundingLabel returns a string label that we can use for marking a transfer
193
+ // funding the deposit. This is useful if we need to filter deposits.
194
+ func (d * Deposit ) fundingLabel () string {
195
+ return fmt .Sprintf ("deposit funding %v" , d .ID )
196
+ }
197
+
198
+ // timeoutSweepLabel is a string label that we can use for marking a timeout
199
+ // sweep transfer. This is useful if we need to filter deposits.
200
+ func (d * Deposit ) timeoutSweepLabel () string {
201
+ return fmt .Sprintf ("deposit timeout sweep %v" , d .ID )
202
+ }
203
+
204
+ // withdrawLabel is a string label that we can use for marking a withdrawal
205
+ // sweep transfer. This is useful if we need to filter deposits.
206
+ func (d * Deposit ) withdrawLabel () string {
207
+ return fmt .Sprintf ("deposit withdraw sweep %v" , d .ID )
182
208
}
183
209
184
210
// lockID converts a deposit ID to a lock ID. The lock ID is used to lock inputs
@@ -200,3 +226,23 @@ func (d *Deposit) lockID() (wtxmgr.LockID, error) {
200
226
201
227
return lockID , nil
202
228
}
229
+
230
+ // GenerateSweepKeys generates the sweep script key and internal key for the
231
+ // deposit sweep.
232
+ func (d * Deposit ) GenerateSweepKeys (ctx context.Context ,
233
+ client * assets.TapdClient ) error {
234
+
235
+ if d .SweepScriptKey != nil {
236
+ return nil
237
+ }
238
+
239
+ scriptKey , internalKeyDesc , err := client .DeriveNewKeys (ctx )
240
+ if err != nil {
241
+ return err
242
+ }
243
+
244
+ d .SweepScriptKey = scriptKey .PubKey
245
+ d .SweepInternalKey = internalKeyDesc .PubKey
246
+
247
+ return nil
248
+ }
0 commit comments