lncli: add settle invoice command
This commit is contained in:
parent
f450929b65
commit
f6d67945dc
@ -7,9 +7,10 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/invoicesrpc"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// invoicesCommands will return nil for non-invoicesrpc builds.
|
// invoicesCommands will return nil for non-invoicesrpc builds.
|
||||||
@ -17,6 +18,7 @@ func invoicesCommands() []cli.Command {
|
|||||||
return []cli.Command{
|
return []cli.Command{
|
||||||
cancelInvoiceCommand,
|
cancelInvoiceCommand,
|
||||||
addHoldInvoiceCommand,
|
addHoldInvoiceCommand,
|
||||||
|
settleInvoiceCommand,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,6 +32,60 @@ func getInvoicesClient(ctx *cli.Context) (invoicesrpc.InvoicesClient, func()) {
|
|||||||
return invoicesrpc.NewInvoicesClient(conn), cleanUp
|
return invoicesrpc.NewInvoicesClient(conn), cleanUp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var settleInvoiceCommand = cli.Command{
|
||||||
|
Name: "settleinvoice",
|
||||||
|
Category: "Payments",
|
||||||
|
Usage: "Reveal a preimage and use it to settle the corresponding invoice.",
|
||||||
|
Description: `
|
||||||
|
Todo.`,
|
||||||
|
ArgsUsage: "preimage",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "preimage",
|
||||||
|
Usage: "the hex-encoded preimage (32 byte) which will " +
|
||||||
|
"allow settling an incoming HTLC payable to this " +
|
||||||
|
"preimage.",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: actionDecorator(settleInvoice),
|
||||||
|
}
|
||||||
|
|
||||||
|
func settleInvoice(ctx *cli.Context) error {
|
||||||
|
var (
|
||||||
|
preimage []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
client, cleanUp := getInvoicesClient(ctx)
|
||||||
|
defer cleanUp()
|
||||||
|
|
||||||
|
args := ctx.Args()
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case ctx.IsSet("preimage"):
|
||||||
|
preimage, err = hex.DecodeString(ctx.String("preimage"))
|
||||||
|
case args.Present():
|
||||||
|
preimage, err = hex.DecodeString(args.First())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to parse preimage: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
invoice := &invoicesrpc.SettleInvoiceMsg{
|
||||||
|
Preimage: preimage,
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.SettleInvoice(context.Background(), invoice)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
printJSON(resp)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var cancelInvoiceCommand = cli.Command{
|
var cancelInvoiceCommand = cli.Command{
|
||||||
Name: "cancelinvoice",
|
Name: "cancelinvoice",
|
||||||
Category: "Payments",
|
Category: "Payments",
|
||||||
|
Loading…
Reference in New Issue
Block a user