From db69331db98807bcc95260094de6d3c2ff8ab3e2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 15 Feb 2021 18:59:41 -0800 Subject: [PATCH] cmd/lncli: add max shard size parsing for payment commands --- cmd/lncli/cmd_pay.go | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/cmd/lncli/cmd_pay.go b/cmd/lncli/cmd_pay.go index 3c017e2a..cb05c46b 100644 --- a/cmd/lncli/cmd_pay.go +++ b/cmd/lncli/cmd_pay.go @@ -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" @@ -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{ @@ -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. @@ -115,6 +131,7 @@ func paymentFlags() []cli.Flag { Usage: "allow sending a circular payment to self", }, dataFlag, inflightUpdatesFlag, maxPartsFlag, jsonFlag, + maxShardSizeSatFlag, maxShardSizeMsatFlag, } } @@ -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 != "" {