Skip to content

Commit 386b06b

Browse files
committed
TODO break up to fixups
1 parent 19b512f commit 386b06b

File tree

13 files changed

+500
-252
lines changed

13 files changed

+500
-252
lines changed

assets/deposit/deposit.go

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package deposit
22

33
import (
4+
"context"
45
"encoding/hex"
56
"fmt"
67
"time"
78

9+
"github.com/btcsuite/btcd/btcec/v2"
810
"github.com/btcsuite/btcd/wire"
911
"github.com/btcsuite/btcwallet/wtxmgr"
12+
"github.com/lightninglabs/loop/assets"
1013
"github.com/lightninglabs/taproot-assets/proof"
1114
)
1215

@@ -130,9 +133,11 @@ type DepositInfo struct {
130133
// only set if the deposit has been confirmed.
131134
Expiry uint32
132135

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
136141
}
137142

138143
// Copy creates a copy of the DepositInfo struct.
@@ -146,7 +151,6 @@ func (d *DepositInfo) Copy() *DepositInfo {
146151
State: d.State,
147152
ConfirmationHeight: d.ConfirmationHeight,
148153
Expiry: d.Expiry,
149-
SweepAddr: d.SweepAddr,
150154
}
151155

152156
if d.Outpoint != nil {
@@ -156,6 +160,16 @@ func (d *DepositInfo) Copy() *DepositInfo {
156160
}
157161
}
158162

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+
159173
return info
160174
}
161175

@@ -175,10 +189,22 @@ type Deposit struct {
175189
AnchorRootHash []byte
176190
}
177191

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)
182208
}
183209

184210
// 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) {
200226

201227
return lockID, nil
202228
}
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

Comments
 (0)