@@ -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+
127179var pendingSweepsCommand = cli.Command {
128180 Name : "pendingsweeps" ,
129181 Usage : "List all outputs that are pending to be swept within lnd." ,
0 commit comments