cmd/lncli: add max shard size parsing for payment commands

This commit is contained in:
Olaoluwa Osuntokun 2021-02-15 18:59:41 -08:00
parent b73a6e2c61
commit db69331db9
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306

@ -14,12 +14,14 @@ import (
"strings" "strings"
"time" "time"
"github.com/btcsuite/btcutil"
"github.com/jedib0t/go-pretty/table" "github.com/jedib0t/go-pretty/table"
"github.com/jedib0t/go-pretty/text" "github.com/jedib0t/go-pretty/text"
"github.com/lightninglabs/protobuf-hex-display/jsonpb" "github.com/lightninglabs/protobuf-hex-display/jsonpb"
"github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/routerrpc" "github.com/lightningnetwork/lnd/lnrpc/routerrpc"
"github.com/lightningnetwork/lnd/lntypes" "github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/record" "github.com/lightningnetwork/lnd/record"
"github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/routing/route"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -62,7 +64,7 @@ var (
Name: "max_parts", Name: "max_parts",
Usage: "the maximum number of partial payments that may be " + Usage: "the maximum number of partial payments that may be " +
"used", "used",
Value: 1, Value: routerrpc.DefaultMaxParts,
} }
jsonFlag = cli.BoolFlag{ jsonFlag = cli.BoolFlag{
@ -71,6 +73,20 @@ var (
"messages. Set by default on Windows because table " + "messages. Set by default on Windows because table " +
"formatting is unsupported.", "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. // paymentFlags returns common flags for sendpayment and payinvoice.
@ -115,6 +131,7 @@ func paymentFlags() []cli.Flag {
Usage: "allow sending a circular payment to self", Usage: "allow sending a circular payment to self",
}, },
dataFlag, inflightUpdatesFlag, maxPartsFlag, jsonFlag, dataFlag, inflightUpdatesFlag, maxPartsFlag, jsonFlag,
maxShardSizeSatFlag, maxShardSizeMsatFlag,
} }
} }
@ -354,6 +371,23 @@ func sendPaymentRequest(ctx *cli.Context,
req.MaxParts = uint32(ctx.Uint(maxPartsFlag.Name)) 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. // Parse custom data records.
data := ctx.String(dataFlag.Name) data := ctx.String(dataFlag.Name)
if data != "" { if data != "" {