Skip to content

Commit 26892a2

Browse files
authored
Merge pull request #8730 from feelancer21/lncli-wallet-estimatefee
lncli: new command `wallet estimatefeerate`
2 parents 286ee95 + fc90bc9 commit 26892a2

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

cmd/lncli/walletrpc_active.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"encoding/json"
1212
"errors"
1313
"fmt"
14+
"math"
1415
"sort"
1516
"strconv"
1617
"strings"
@@ -22,6 +23,7 @@ import (
2223
"github.com/btcsuite/btcd/wire"
2324
"github.com/lightningnetwork/lnd/lnrpc"
2425
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
26+
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2527
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
2628
"github.com/urfave/cli"
2729
)
@@ -77,6 +79,7 @@ func walletCommands() []cli.Command {
7779
Usage: "Interact with the wallet.",
7880
Description: "",
7981
Subcommands: []cli.Command{
82+
estimateFeeRateCommand,
8083
pendingSweepsCommand,
8184
bumpFeeCommand,
8285
bumpCloseFeeCommand,
@@ -124,6 +127,55 @@ func getWalletClient(ctx *cli.Context) (walletrpc.WalletKitClient, func()) {
124127
return walletrpc.NewWalletKitClient(conn), cleanUp
125128
}
126129

130+
var estimateFeeRateCommand = cli.Command{
131+
Name: "estimatefeerate",
132+
Usage: "Estimates the on-chain fee rate to achieve a confirmation " +
133+
"target.",
134+
ArgsUsage: "conf_target",
135+
Description: `
136+
Returns the fee rate estimate for on-chain transactions in sat/kw and
137+
sat/vb to achieve a given confirmation target. The source of the fee
138+
rate depends on the configuration and is either the on-chain backend or
139+
alternatively an external URL.
140+
`,
141+
Action: actionDecorator(estimateFeeRate),
142+
}
143+
144+
func estimateFeeRate(ctx *cli.Context) error {
145+
ctxc := getContext()
146+
client, cleanUp := getWalletClient(ctx)
147+
defer cleanUp()
148+
149+
confTarget, err := strconv.ParseInt(ctx.Args().First(), 10, 64)
150+
if err != nil {
151+
return cli.ShowCommandHelp(ctx, "estimatefeerate")
152+
}
153+
154+
if confTarget <= 0 || confTarget > math.MaxInt32 {
155+
return errors.New("conf_target out of range")
156+
}
157+
158+
resp, err := client.EstimateFee(ctxc, &walletrpc.EstimateFeeRequest{
159+
ConfTarget: int32(confTarget),
160+
})
161+
if err != nil {
162+
return err
163+
}
164+
165+
rateKW := chainfee.SatPerKWeight(resp.SatPerKw)
166+
rateVB := rateKW.FeePerVByte()
167+
168+
printJSON(struct {
169+
SatPerKw int64 `json:"sat_per_kw"`
170+
SatPerVByte int64 `json:"sat_per_vbyte"`
171+
}{
172+
SatPerKw: int64(rateKW),
173+
SatPerVByte: int64(rateVB),
174+
})
175+
176+
return nil
177+
}
178+
127179
var pendingSweepsCommand = cli.Command{
128180
Name: "pendingsweeps",
129181
Usage: "List all outputs that are pending to be swept within lnd.",

docs/release-notes/release-notes-0.18.1.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
argument to `addinvoice` and `addholdinvoice`, allowing users to set the
3333
`min_final_cltv_expiry_delta`
3434

35+
* The [`lncli wallet estimatefeerate`](https://github.com/lightningnetwork/lnd/pull/8730)
36+
command returns the fee rate estimate for on-chain transactions in sat/kw and
37+
sat/vb to achieve a given confirmation target.
38+
3539
# Improvements
3640
## Functional Updates
3741
## RPC Updates

0 commit comments

Comments
 (0)