Merge pull request #5095 from bottlepay/wtxmgr-parameterized-lock

lnwallet+walletrpc: list leases and parameterize duration
This commit is contained in:
Olaoluwa Osuntokun authored and GitHub committed 2021-03-25 17:31:13 -07:00
commit 24d1d9cb14
13 files changed
+491 -167

No files matched your search

+39 -8
View File
@@ -46,6 +46,7 @@ func walletCommands() []cli.Command {
listSweepsCommand,
labelTxCommand,
releaseOutputCommand,
listLeasesCommand,
psbtCommand,
},
},
@@ -605,14 +606,7 @@ func fundPsbt(ctx *cli.Context) error {
return err
}
jsonLocks := make([]*utxoLease, len(response.LockedUtxos))
for idx, lock := range response.LockedUtxos {
jsonLocks[idx] = &utxoLease{
ID: hex.EncodeToString(lock.Id),
OutPoint: NewOutPointFromProto(lock.Outpoint),
Expiration: lock.Expiration,
}
}
jsonLocks := marshallLocks(response.LockedUtxos)
printJSON(&fundPsbtResponse{
Psbt: base64.StdEncoding.EncodeToString(
@@ -625,6 +619,21 @@ func fundPsbt(ctx *cli.Context) error {
return nil
}
// marshallLocks converts the rpc lease information to a more json-friendly
// format.
func marshallLocks(lockedUtxos []*walletrpc.UtxoLease) []*utxoLease {
jsonLocks := make([]*utxoLease, len(lockedUtxos))
for idx, lock := range lockedUtxos {
jsonLocks[idx] = &utxoLease{
ID: hex.EncodeToString(lock.Id),
OutPoint: NewOutPointFromProto(lock.Outpoint),
Expiration: lock.Expiration,
}
}
return jsonLocks
}
// finalizePsbtResponse is a struct that contains JSON annotations for nice
// result serialization.
type finalizePsbtResponse struct {
@@ -767,3 +776,25 @@ func releaseOutput(ctx *cli.Context) error {
return nil
}
var listLeasesCommand = cli.Command{
Name: "listleases",
Usage: "Return a list of currently held leases.",
Action: actionDecorator(listLeases),
}
func listLeases(ctx *cli.Context) error {
req := &walletrpc.ListLeasesRequest{}
walletClient, cleanUp := getWalletClient(ctx)
defer cleanUp()
response, err := walletClient.ListLeases(context.Background(), req)
if err != nil {
return err
}
printJSON(marshallLocks(response.LockedUtxos))
return nil
}