From 0b2388bd4b1593fac1777e827315088e602b2965 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 11 Nov 2021 16:33:04 +0100 Subject: [PATCH 1/2] lncli: add leaseoutput command --- cmd/lncli/walletrpc_active.go | 76 ++++++++++++++++++++++ docs/release-notes/release-notes-0.15.0.md | 3 + 2 files changed, 79 insertions(+) diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index 460635f0e..ae36bbb9a 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -62,6 +62,7 @@ func walletCommands() []cli.Command { labelTxCommand, publishTxCommand, releaseOutputCommand, + leaseOutputCommand, listLeasesCommand, psbtCommand, accountsCommand, @@ -847,6 +848,81 @@ func finalizePsbt(ctx *cli.Context) error { return nil } +var leaseOutputCommand = cli.Command{ + Name: "leaseoutput", + Usage: "Lease an output.", + Description: ` + The leaseoutput command locks an output, making it unavailable + for coin selection. + + An app lock ID and expiration duration must be specified when locking + the output. + `, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "outpoint", + Usage: "the output to lock", + }, + cli.StringFlag{ + Name: "lockid", + Usage: "the hex-encoded app lock ID", + }, + cli.Uint64Flag{ + Name: "expiry", + Usage: "expiration duration in seconds", + }, + }, + Action: actionDecorator(leaseOutput), +} + +func leaseOutput(ctx *cli.Context) error { + ctxc := getContext() + + // Display the command's help message if we do not have the expected + // number of arguments/flags. + if ctx.NArg() != 0 || ctx.NumFlags() == 0 { + return cli.ShowCommandHelp(ctx, "leaseoutput") + } + + outpointStr := ctx.String("outpoint") + outpoint, err := NewProtoOutPoint(outpointStr) + if err != nil { + return fmt.Errorf("error parsing outpoint: %v", err) + } + + lockIDStr := ctx.String("lockid") + if lockIDStr == "" { + return errors.New("lockid not specified") + } + lockID, err := hex.DecodeString(lockIDStr) + if err != nil { + return fmt.Errorf("error parsing lockid: %v", err) + } + + expiry := ctx.Uint64("expiry") + if expiry == 0 { + return errors.New("expiry not specified or invalid") + } + + req := &walletrpc.LeaseOutputRequest{ + Outpoint: outpoint, + Id: lockID, + ExpirationSeconds: expiry, + } + + walletClient, cleanUp := getWalletClient(ctx) + defer cleanUp() + + response, err := walletClient.LeaseOutput(ctxc, req) + if err != nil { + return err + } + + printRespJSON(response) + + return nil +} + var releaseOutputCommand = cli.Command{ Name: "releaseoutput", Usage: "Release an output previously locked by lnd.", diff --git a/docs/release-notes/release-notes-0.15.0.md b/docs/release-notes/release-notes-0.15.0.md index 04bd845a4..8673f2892 100644 --- a/docs/release-notes/release-notes-0.15.0.md +++ b/docs/release-notes/release-notes-0.15.0.md @@ -30,6 +30,8 @@ * [Disable compiler optimizations](https://github.com/lightningnetwork/lnd/pull/6105) when building `lnd-debug` and `lncli-debug`. It helps when stepping through the code with a debugger like Delve. + +* A new command `lncli leaseoutput` was [added](https://github.com/lightningnetwork/lnd/pull/5964). ## RPC Server @@ -53,6 +55,7 @@ * Andreas Schjønhaug * Daniel McNally * ErikEk +* Joost Jager * Liviu * Torkel Rogstad * Yong Yu From f99b472bbb1f9e3ed5e17c98d950bd74afc7d69f Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Thu, 11 Nov 2021 16:37:01 +0100 Subject: [PATCH 2/2] lncli: add lockid parameter to releaseoutput --- cmd/lncli/walletrpc_active.go | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/lncli/walletrpc_active.go b/cmd/lncli/walletrpc_active.go index ae36bbb9a..169f53969 100644 --- a/cmd/lncli/walletrpc_active.go +++ b/cmd/lncli/walletrpc_active.go @@ -931,15 +931,19 @@ var releaseOutputCommand = cli.Command{ The releaseoutput command unlocks an output, allowing it to be available for coin selection if it remains unspent. - The internal lnd app lock ID is used when releasing the output. - Therefore only UTXOs locked by the fundpsbt command can currently be - released with this command. + If no lock ID is specified, the internal lnd app lock ID is used when + releasing the output. With the internal ID, only UTXOs locked by the + fundpsbt command can be released. `, Flags: []cli.Flag{ cli.StringFlag{ Name: "outpoint", Usage: "the output to unlock", }, + cli.StringFlag{ + Name: "lockid", + Usage: "the hex-encoded app lock ID", + }, }, Action: actionDecorator(releaseOutput), } @@ -970,9 +974,20 @@ func releaseOutput(ctx *cli.Context) error { if err != nil { return fmt.Errorf("error parsing outpoint: %v", err) } + + lockID := walletrpc.LndInternalLockID[:] + lockIDStr := ctx.String("lockid") + if lockIDStr != "" { + var err error + lockID, err = hex.DecodeString(lockIDStr) + if err != nil { + return fmt.Errorf("error parsing lockid: %v", err) + } + } + req := &walletrpc.ReleaseOutputRequest{ Outpoint: outpoint, - Id: walletrpc.LndInternalLockID[:], + Id: lockID, } walletClient, cleanUp := getWalletClient(ctx)