mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-21 06:12:38 +02:00
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:
parent
286ee95735
commit
fc90bc9b0f
@ -11,6 +11,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -22,6 +23,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
@ -77,6 +79,7 @@ func walletCommands() []cli.Command {
|
|||||||
Usage: "Interact with the wallet.",
|
Usage: "Interact with the wallet.",
|
||||||
Description: "",
|
Description: "",
|
||||||
Subcommands: []cli.Command{
|
Subcommands: []cli.Command{
|
||||||
|
estimateFeeRateCommand,
|
||||||
pendingSweepsCommand,
|
pendingSweepsCommand,
|
||||||
bumpFeeCommand,
|
bumpFeeCommand,
|
||||||
bumpCloseFeeCommand,
|
bumpCloseFeeCommand,
|
||||||
@ -124,6 +127,55 @@ func getWalletClient(ctx *cli.Context) (walletrpc.WalletKitClient, func()) {
|
|||||||
return walletrpc.NewWalletKitClient(conn), cleanUp
|
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{
|
var pendingSweepsCommand = cli.Command{
|
||||||
Name: "pendingsweeps",
|
Name: "pendingsweeps",
|
||||||
Usage: "List all outputs that are pending to be swept within lnd.",
|
Usage: "List all outputs that are pending to be swept within lnd.",
|
||||||
|
@ -32,6 +32,10 @@
|
|||||||
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
|
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
|
||||||
`min_final_cltv_expiry_delta`
|
`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
|
# Improvements
|
||||||
## Functional Updates
|
## Functional Updates
|
||||||
## RPC Updates
|
## RPC Updates
|
||||||
|
Loading…
x
Reference in New Issue
Block a user