mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-18 18:17:39 +01:00
Merge pull request #5964 from bottlepay/leaseoutput
lncli: add leaseoutput command
This commit is contained in:
@@ -62,6 +62,7 @@ func walletCommands() []cli.Command {
|
|||||||
labelTxCommand,
|
labelTxCommand,
|
||||||
publishTxCommand,
|
publishTxCommand,
|
||||||
releaseOutputCommand,
|
releaseOutputCommand,
|
||||||
|
leaseOutputCommand,
|
||||||
listLeasesCommand,
|
listLeasesCommand,
|
||||||
psbtCommand,
|
psbtCommand,
|
||||||
accountsCommand,
|
accountsCommand,
|
||||||
@@ -847,6 +848,81 @@ func finalizePsbt(ctx *cli.Context) error {
|
|||||||
return nil
|
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{
|
var releaseOutputCommand = cli.Command{
|
||||||
Name: "releaseoutput",
|
Name: "releaseoutput",
|
||||||
Usage: "Release an output previously locked by lnd.",
|
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
|
The releaseoutput command unlocks an output, allowing it to be available
|
||||||
for coin selection if it remains unspent.
|
for coin selection if it remains unspent.
|
||||||
|
|
||||||
The internal lnd app lock ID is used when releasing the output.
|
If no lock ID is specified, the internal lnd app lock ID is used when
|
||||||
Therefore only UTXOs locked by the fundpsbt command can currently be
|
releasing the output. With the internal ID, only UTXOs locked by the
|
||||||
released with this command.
|
fundpsbt command can be released.
|
||||||
`,
|
`,
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
Name: "outpoint",
|
Name: "outpoint",
|
||||||
Usage: "the output to unlock",
|
Usage: "the output to unlock",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lockid",
|
||||||
|
Usage: "the hex-encoded app lock ID",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: actionDecorator(releaseOutput),
|
Action: actionDecorator(releaseOutput),
|
||||||
}
|
}
|
||||||
@@ -894,9 +974,20 @@ func releaseOutput(ctx *cli.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error parsing outpoint: %v", err)
|
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{
|
req := &walletrpc.ReleaseOutputRequest{
|
||||||
Outpoint: outpoint,
|
Outpoint: outpoint,
|
||||||
Id: walletrpc.LndInternalLockID[:],
|
Id: lockID,
|
||||||
}
|
}
|
||||||
|
|
||||||
walletClient, cleanUp := getWalletClient(ctx)
|
walletClient, cleanUp := getWalletClient(ctx)
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
when building `lnd-debug` and `lncli-debug`. It helps when stepping through the code
|
when building `lnd-debug` and `lncli-debug`. It helps when stepping through the code
|
||||||
with a debugger like Delve.
|
with a debugger like Delve.
|
||||||
|
|
||||||
|
* A new command `lncli leaseoutput` was [added](https://github.com/lightningnetwork/lnd/pull/5964).
|
||||||
|
|
||||||
## RPC Server
|
## RPC Server
|
||||||
|
|
||||||
* [Add value to the field
|
* [Add value to the field
|
||||||
@@ -53,6 +55,7 @@
|
|||||||
* Andreas Schjønhaug
|
* Andreas Schjønhaug
|
||||||
* Daniel McNally
|
* Daniel McNally
|
||||||
* ErikEk
|
* ErikEk
|
||||||
|
* Joost Jager
|
||||||
* Liviu
|
* Liviu
|
||||||
* Torkel Rogstad
|
* Torkel Rogstad
|
||||||
* Yong Yu
|
* Yong Yu
|
||||||
|
|||||||
Reference in New Issue
Block a user