Skip to content

Commit

Permalink
looprpc: add outgoing channel set restriction
Browse files Browse the repository at this point in the history
Expose the new channel set restriction on the loopd client rpc.
  • Loading branch information
joostjager committed May 19, 2020
1 parent 73d67e2 commit 983ac8b
Show file tree
Hide file tree
Showing 5 changed files with 162 additions and 112 deletions.
26 changes: 17 additions & 9 deletions cmd/loop/loopout.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"context"
"fmt"
"strconv"
"strings"
"time"

"github.com/btcsuite/btcutil"
Expand All @@ -25,10 +27,10 @@ var loopOutCommand = cli.Command{
Optionally a BASE58/bech32 encoded bitcoin destination address may be
specified. If not specified, a new wallet address will be generated.`,
Flags: []cli.Flag{
cli.Uint64Flag{
cli.StringFlag{
Name: "channel",
Usage: "the 8-byte compact channel ID of the channel " +
"to loop out",
Usage: "the comma-separated list of short " +
"channel IDs of the channels to loop out",
},
cli.StringFlag{
Name: "addr",
Expand Down Expand Up @@ -87,6 +89,17 @@ func loopOut(ctx *cli.Context) error {
return err
}

// Parse outgoing channel set.
chanStrings := strings.Split(ctx.String("channel"), ",")
var outgoingChanSet []uint64
for _, chanString := range chanStrings {
chanID, err := strconv.ParseUint(chanString, 10, 64)
if err != nil {
return err
}
outgoingChanSet = append(outgoingChanSet, chanID)
}

var destAddr string
switch {
case ctx.IsSet("addr"):
Expand Down Expand Up @@ -145,11 +158,6 @@ func loopOut(ctx *cli.Context) error {
return err
}

var unchargeChannel uint64
if ctx.IsSet("channel") {
unchargeChannel = ctx.Uint64("channel")
}

resp, err := client.LoopOut(context.Background(), &looprpc.LoopOutRequest{
Amt: int64(amt),
Dest: destAddr,
Expand All @@ -158,7 +166,7 @@ func loopOut(ctx *cli.Context) error {
MaxSwapFee: int64(limits.maxSwapFee),
MaxPrepayRoutingFee: int64(*limits.maxPrepayRoutingFee),
MaxSwapRoutingFee: int64(*limits.maxSwapRoutingFee),
LoopOutChannel: unchargeChannel,
OutgoingChanSet: outgoingChanSet,
SweepConfTarget: sweepConfTarget,
SwapPublicationDeadline: uint64(swapDeadline.Unix()),
})
Expand Down
12 changes: 11 additions & 1 deletion loopd/swapclient_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,19 @@ func (s *swapClientServer) LoopOut(ctx context.Context,
int64(in.SwapPublicationDeadline), 0,
),
}
if in.LoopOutChannel != 0 {

switch {
case in.LoopOutChannel != 0 && len(in.OutgoingChanSet) > 0:
return nil, errors.New("loop_out_channel and outgoing_" +
"chan_ids are mutually exclusive")

case in.LoopOutChannel != 0:
req.OutgoingChanSet = loopdb.ChannelSet{in.LoopOutChannel}

default:
req.OutgoingChanSet = in.OutgoingChanSet
}

hash, htlc, err := s.impl.LoopOut(ctx, req)
if err != nil {
log.Errorf("LoopOut: %v", err)
Expand Down
Loading

0 comments on commit 983ac8b

Please sign in to comment.