lncli: new command wallet estimatefeerate

`lncli wallet estimatefeerate` returns the fee rate estimate for on-chain
transactions in sat/kw and sat/vb to achieve a given confirmation target.
This commit is contained in:
feelancer21 2024-05-05 23:19:32 +02:00
parent 286ee95735
commit fc90bc9b0f
No known key found for this signature in database
GPG key ID: 1F7071EE8449729C
2 changed files with 56 additions and 0 deletions

View file

@ -11,6 +11,7 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"sort"
"strconv"
"strings"
@ -22,6 +23,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
"github.com/urfave/cli"
)
@ -77,6 +79,7 @@ func walletCommands() []cli.Command {
Usage: "Interact with the wallet.",
Description: "",
Subcommands: []cli.Command{
estimateFeeRateCommand,
pendingSweepsCommand,
bumpFeeCommand,
bumpCloseFeeCommand,
@ -124,6 +127,55 @@ func getWalletClient(ctx *cli.Context) (walletrpc.WalletKitClient, func()) {
return walletrpc.NewWalletKitClient(conn), cleanUp
}
var estimateFeeRateCommand = cli.Command{
Name: "estimatefeerate",
Usage: "Estimates the on-chain fee rate to achieve a confirmation " +
"target.",
ArgsUsage: "conf_target",
Description: `
Returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target. The source of the fee
rate depends on the configuration and is either the on-chain backend or
alternatively an external URL.
`,
Action: actionDecorator(estimateFeeRate),
}
func estimateFeeRate(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getWalletClient(ctx)
defer cleanUp()
confTarget, err := strconv.ParseInt(ctx.Args().First(), 10, 64)
if err != nil {
return cli.ShowCommandHelp(ctx, "estimatefeerate")
}
if confTarget <= 0 || confTarget > math.MaxInt32 {
return errors.New("conf_target out of range")
}
resp, err := client.EstimateFee(ctxc, &walletrpc.EstimateFeeRequest{
ConfTarget: int32(confTarget),
})
if err != nil {
return err
}
rateKW := chainfee.SatPerKWeight(resp.SatPerKw)
rateVB := rateKW.FeePerVByte()
printJSON(struct {
SatPerKw int64 `json:"sat_per_kw"`
SatPerVByte int64 `json:"sat_per_vbyte"`
}{
SatPerKw: int64(rateKW),
SatPerVByte: int64(rateVB),
})
return nil
}
var pendingSweepsCommand = cli.Command{
Name: "pendingsweeps",
Usage: "List all outputs that are pending to be swept within lnd.",

View file

@ -32,6 +32,10 @@
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
`min_final_cltv_expiry_delta`
* The [`lncli wallet estimatefeerate`](https://github.com/lightningnetwork/lnd/pull/8730)
command returns the fee rate estimate for on-chain transactions in sat/kw and
sat/vb to achieve a given confirmation target.
# Improvements
## Functional Updates
## RPC Updates