Skip to content

Commit 010b63d

Browse files
authored
Merge pull request #709 from sputn1ck/instantout_custom_addr
instantout: add custom address to send funds to
2 parents c19781b + 6a62be0 commit 010b63d

File tree

6 files changed

+233
-187
lines changed

6 files changed

+233
-187
lines changed

cmd/loop/instantout.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ var instantOutCommand = cli.Command{
2525
Usage: "the comma-separated list of short " +
2626
"channel IDs of the channels to loop out",
2727
},
28+
cli.StringFlag{
29+
Name: "addr",
30+
Usage: "the optional address that the looped out funds " +
31+
"should be sent to, if let blank the funds " +
32+
"will go to lnd's wallet",
33+
},
2834
},
2935
Action: instantOut,
3036
}
@@ -178,6 +184,7 @@ func instantOut(ctx *cli.Context) error {
178184
&looprpc.InstantOutRequest{
179185
ReservationIds: selectedReservations,
180186
OutgoingChanSet: outgoingChanSet,
187+
DestAddr: ctx.String("addr"),
181188
},
182189
)
183190

instantout/actions.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lightningnetwork/lnd/lnrpc"
2020
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
2121
"github.com/lightningnetwork/lnd/lntypes"
22+
"github.com/lightningnetwork/lnd/lnwallet"
2223
)
2324

2425
const (
@@ -59,6 +60,7 @@ type InitInstantOutCtx struct {
5960
initationHeight int32
6061
outgoingChanSet loopdb.ChannelSet
6162
protocolVersion ProtocolVersion
63+
sweepAddress btcutil.Address
6264
}
6365

6466
// InitInstantOutAction is the first action that is executed when the instant
@@ -165,11 +167,15 @@ func (f *FSM) InitInstantOutAction(eventCtx fsm.EventContext) fsm.EventType {
165167
}
166168

167169
// Create the address that we'll send the funds to.
168-
sweepAddress, err := f.cfg.Wallet.NextAddr(
169-
f.ctx, "", walletrpc.AddressType_TAPROOT_PUBKEY, false,
170-
)
171-
if err != nil {
172-
return f.HandleError(err)
170+
sweepAddress := initCtx.sweepAddress
171+
if sweepAddress == nil {
172+
sweepAddress, err = f.cfg.Wallet.NextAddr(
173+
f.ctx, lnwallet.DefaultAccountName,
174+
walletrpc.AddressType_TAPROOT_PUBKEY, false,
175+
)
176+
if err != nil {
177+
return f.HandleError(err)
178+
}
173179
}
174180

175181
// Now we can create the instant out.

instantout/manager.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,20 @@ func (m *Manager) recoverInstantOuts(ctx context.Context) error {
137137

138138
// NewInstantOut creates a new instantout.
139139
func (m *Manager) NewInstantOut(ctx context.Context,
140-
reservations []reservation.ID) (*FSM, error) {
140+
reservations []reservation.ID, sweepAddress string) (*FSM, error) {
141+
142+
var (
143+
sweepAddr btcutil.Address
144+
err error
145+
)
146+
if sweepAddress != "" {
147+
sweepAddr, err = btcutil.DecodeAddress(
148+
sweepAddress, m.cfg.Network,
149+
)
150+
if err != nil {
151+
return nil, err
152+
}
153+
}
141154

142155
m.Lock()
143156
// Create the instantout request.
@@ -146,6 +159,7 @@ func (m *Manager) NewInstantOut(ctx context.Context,
146159
reservations: reservations,
147160
initationHeight: m.currentHeight,
148161
protocolVersion: CurrentProtocolVersion(),
162+
sweepAddress: sweepAddr,
149163
}
150164

151165
instantOut, err := NewFSM(

loopd/swapclient_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ func (s *swapClientServer) InstantOut(ctx context.Context,
11941194
}
11951195

11961196
instantOutFsm, err := s.instantOutManager.NewInstantOut(
1197-
ctx, reservationIds,
1197+
ctx, reservationIds, req.DestAddr,
11981198
)
11991199
if err != nil {
12001200
return nil, err

0 commit comments

Comments
 (0)