Skip to content

Commit ccec719

Browse files
committed
looprpc: add outgoing channel set restriction
Expose the new channel set restriction on the loopd client rpc.
1 parent 8c544bf commit ccec719

File tree

5 files changed

+162
-112
lines changed

5 files changed

+162
-112
lines changed

cmd/loop/loopout.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package main
33
import (
44
"context"
55
"fmt"
6+
"strconv"
7+
"strings"
68
"time"
79

810
"github.com/btcsuite/btcutil"
@@ -25,10 +27,10 @@ var loopOutCommand = cli.Command{
2527
Optionally a BASE58/bech32 encoded bitcoin destination address may be
2628
specified. If not specified, a new wallet address will be generated.`,
2729
Flags: []cli.Flag{
28-
cli.Uint64Flag{
30+
cli.StringFlag{
2931
Name: "channel",
30-
Usage: "the 8-byte compact channel ID of the channel " +
31-
"to loop out",
32+
Usage: "the comma-separated list of short " +
33+
"channel IDs of the channels to loop out",
3234
},
3335
cli.StringFlag{
3436
Name: "addr",
@@ -87,6 +89,17 @@ func loopOut(ctx *cli.Context) error {
8789
return err
8890
}
8991

92+
// Parse outgoing channel set.
93+
chanStrings := strings.Split(ctx.String("channel"), ",")
94+
var outgoingChanSet []uint64
95+
for _, chanString := range chanStrings {
96+
chanID, err := strconv.ParseUint(chanString, 10, 64)
97+
if err != nil {
98+
return err
99+
}
100+
outgoingChanSet = append(outgoingChanSet, chanID)
101+
}
102+
90103
var destAddr string
91104
switch {
92105
case ctx.IsSet("addr"):
@@ -145,11 +158,6 @@ func loopOut(ctx *cli.Context) error {
145158
return err
146159
}
147160

148-
var unchargeChannel uint64
149-
if ctx.IsSet("channel") {
150-
unchargeChannel = ctx.Uint64("channel")
151-
}
152-
153161
resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
154162
Amt: int64(amt),
155163
Dest: destAddr,
@@ -158,7 +166,7 @@ func loopOut(ctx *cli.Context) error {
158166
MaxSwapFee: int64(limits.maxSwapFee),
159167
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
160168
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
161-
LoopOutChannel: unchargeChannel,
169+
OutgoingChanSet: outgoingChanSet,
162170
SweepConfTarget: sweepConfTarget,
163171
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
164172
})

loopd/swapclient_server.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,19 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
8989
int64(in.SwapPublicationDeadline), 0,
9090
),
9191
}
92-
if in.LoopOutChannel != 0 {
92+
93+
switch {
94+
case in.LoopOutChannel != 0 && len(in.OutgoingChanSet) > 0:
95+
return nil, errors.New("loop_out_channel and outgoing_" +
96+
"chan_ids are mutually exclusive")
97+
98+
case in.LoopOutChannel != 0:
9399
req.OutgoingChanSet = loopdb.ChannelSet{in.LoopOutChannel}
100+
101+
default:
102+
req.OutgoingChanSet = in.OutgoingChanSet
94103
}
104+
95105
hash, htlc, err := s.impl.LoopOut(ctx, req)
96106
if err != nil {
97107
log.Errorf("LoopOut: %v", err)

0 commit comments

Comments
 (0)