Merge pull request #5964 from bottlepay/leaseoutput

lncli: add leaseoutput command
This commit is contained in:
Oliver Gugger 2022-01-03 18:41:26 +01:00 committed by GitHub
commit 71ecc8a299
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 4 deletions

View File

@ -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.",
@ -855,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),
}
@ -894,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)

View File

@ -31,6 +31,8 @@
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
* [Add value to the field
@ -53,6 +55,7 @@
* Andreas Schjønhaug
* Daniel McNally
* ErikEk
* Joost Jager
* Liviu
* Torkel Rogstad
* Yong Yu