Skip to content

Commit

Permalink
cmd/lncli: add max shard size parsing for payment commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Roasbeef committed Feb 16, 2021
1 parent b73a6e2 commit db69331
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion cmd/lncli/cmd_pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import (
"strings"
"time"

"github.com/btcsuite/btcutil"
"github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/text"
"github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing/route"
"github.com/urfave/cli"
Expand Down Expand Up @@ -62,7 +64,7 @@ var (
Name: "max_parts",
Usage: "the maximum number of partial payments that may be " +
"used",
Value: 1,
Value: routerrpc.DefaultMaxParts,
}

jsonFlag = cli.BoolFlag{
Expand All @@ -71,6 +73,20 @@ var (
"messages. Set by default on Windows because table " +
"formatting is unsupported.",
}

maxShardSizeSatFlag = cli.UintFlag{
Name: "max_shard_size_sat",
Usage: "the largest payment split that should be attempted if " +
"payment splitting is required to attempt a payment, " +
"specified in satoshis",
}

maxShardSizeMsatFlag = cli.UintFlag{
Name: "max_shard_size_msat",
Usage: "the largest payment split that should be attempted if " +
"payment splitting is required to attempt a payment, " +
"specified in milli-satoshis",
}
)

// paymentFlags returns common flags for sendpayment and payinvoice.
Expand Down Expand Up @@ -115,6 +131,7 @@ func paymentFlags() []cli.Flag {
Usage: "allow sending a circular payment to self",
},
dataFlag, inflightUpdatesFlag, maxPartsFlag, jsonFlag,
maxShardSizeSatFlag, maxShardSizeMsatFlag,
}
}

Expand Down Expand Up @@ -354,6 +371,23 @@ func sendPaymentRequest(ctx *cli.Context,

req.MaxParts = uint32(ctx.Uint(maxPartsFlag.Name))

switch {
// If the max shard size is specified, then it should either be in sat
// or msat, but not both.
case ctx.Uint64(maxShardSizeMsatFlag.Name) != 0 &&
ctx.Uint64(maxShardSizeSatFlag.Name) != 0:
return fmt.Errorf("only --max_split_size_msat or " +
"--max_split_size_sat should be set, but not both")

case ctx.Uint64(maxShardSizeMsatFlag.Name) != 0:
req.MaxShardSizeMsat = ctx.Uint64(maxShardSizeMsatFlag.Name)

case ctx.Uint64(maxShardSizeSatFlag.Name) != 0:
req.MaxShardSizeMsat = uint64(lnwire.NewMSatFromSatoshis(
btcutil.Amount(ctx.Uint64(maxShardSizeSatFlag.Name)),
))
}

// Parse custom data records.
data := ctx.String(dataFlag.Name)
if data != "" {
Expand Down

0 comments on commit db69331

Please sign in to comment.