@@ -11,6 +11,7 @@ import (
11
11
"encoding/json"
12
12
"errors"
13
13
"fmt"
14
+ "math"
14
15
"sort"
15
16
"strconv"
16
17
"strings"
@@ -22,6 +23,7 @@ import (
22
23
"github.com/btcsuite/btcd/wire"
23
24
"github.com/lightningnetwork/lnd/lnrpc"
24
25
"github.com/lightningnetwork/lnd/lnrpc/walletrpc"
26
+ "github.com/lightningnetwork/lnd/lnwallet/chainfee"
25
27
"github.com/lightningnetwork/lnd/lnwallet/chanfunding"
26
28
"github.com/urfave/cli"
27
29
)
@@ -77,6 +79,7 @@ func walletCommands() []cli.Command {
77
79
Usage : "Interact with the wallet." ,
78
80
Description : "" ,
79
81
Subcommands : []cli.Command {
82
+ estimateFeeRateCommand ,
80
83
pendingSweepsCommand ,
81
84
bumpFeeCommand ,
82
85
bumpCloseFeeCommand ,
@@ -124,6 +127,55 @@ func getWalletClient(ctx *cli.Context) (walletrpc.WalletKitClient, func()) {
124
127
return walletrpc .NewWalletKitClient (conn ), cleanUp
125
128
}
126
129
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
+
127
179
var pendingSweepsCommand = cli.Command {
128
180
Name : "pendingsweeps" ,
129
181
Usage : "List all outputs that are pending to be swept within lnd." ,
0 commit comments