Skip to content

Commit b37a434

Browse files
committed
switch from SatPerVbyte to SatPerKw fields in APIs
Use SatPerKw instead of SatPerVbyte in SendCoins, CloseChannel, and walletrpc.BumpFee APIs. Added new option WithSendCoinsFeerate for SendCoins and WithOpenChannelFeerate for OpenChannel API specifying feerate in sats/kw. Use new fields provided by lightningnetwork/lnd#10067
1 parent 4988fdd commit b37a434

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

lightning_client.go

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ func WithRemoteMaxHtlc(maxHtlc uint32) OpenChannelOption {
8181
}
8282
}
8383

84+
// WithOpenChannelFeerate specifies feerate in sats/kw for OpenChannel request.
85+
func WithOpenChannelFeerate(satPerKw chainfee.SatPerKWeight) OpenChannelOption {
86+
return func(r *lnrpc.OpenChannelRequest) {
87+
r.SatPerKw = uint64(satPerKw)
88+
}
89+
}
90+
8491
// LightningClient exposes base lightning functionality.
8592
type LightningClient interface {
8693
ServiceClient[lnrpc.LightningClient]
@@ -214,7 +221,8 @@ type LightningClient interface {
214221
// upon success.
215222
SendCoins(ctx context.Context, addr btcutil.Address,
216223
amount btcutil.Amount, sendAll bool, confTarget int32,
217-
satsPerVByte chainfee.SatPerVByte, label string) (string, error)
224+
satsPerVByte chainfee.SatPerVByte, label string,
225+
opts ...SendCoinsOption) (string, error)
218226

219227
// ChannelBalance returns a summary of our channel balances.
220228
ChannelBalance(ctx context.Context) (*ChannelBalance, error)
@@ -3152,7 +3160,14 @@ type CloseChannelOption func(r *lnrpc.CloseChannelRequest)
31523160
// SatPerVbyte is an option for setting the fee rate of a CloseChannelRequest.
31533161
func SatPerVbyte(satPerVbyte chainfee.SatPerVByte) CloseChannelOption {
31543162
return func(r *lnrpc.CloseChannelRequest) {
3155-
r.SatPerVbyte = uint64(satPerVbyte)
3163+
r.SatPerKw = uint64(satPerVbyte.FeePerKWeight())
3164+
}
3165+
}
3166+
3167+
// SatPerVbyte is an option for setting the fee rate of a CloseChannelRequest.
3168+
func SatPerKw(satPerKw chainfee.SatPerKWeight) CloseChannelOption {
3169+
return func(r *lnrpc.CloseChannelRequest) {
3170+
r.SatPerKw = uint64(satPerKw)
31563171
}
31573172
}
31583173

@@ -3164,6 +3179,9 @@ func MaxFeePerVbyte(maxFeePerVbyte chainfee.SatPerVByte) CloseChannelOption {
31643179
}
31653180
}
31663181

3182+
// TODO: MaxFeePerKw
3183+
// See https://github.com/lightningnetwork/lnd/pull/10067/files#r2302906743
3184+
31673185
// WithNoWait is an option for setting the NoWait flag on an
31683186
// CloseChannelRequest.
31693187
func WithNoWait() CloseChannelOption {
@@ -3591,26 +3609,43 @@ func (s *lightningClient) Connect(ctx context.Context, peer route.Vertex,
35913609
return err
35923610
}
35933611

3612+
// SendCoinsOption is an option used in SendCoins call.
3613+
type SendCoinsOption func(*lnrpc.SendCoinsRequest)
3614+
3615+
// WithSendCoinsFeerate specifies feerate in sats/kw for SendCoins request.
3616+
// To use it pass satsPerVByte=0 and WithSendCoinsFeerate(desired_feerate) to
3617+
// SendCoins.
3618+
func WithSendCoinsFeerate(satPerKw chainfee.SatPerKWeight) SendCoinsOption {
3619+
return func(req *lnrpc.SendCoinsRequest) {
3620+
req.SatPerKw = uint64(satPerKw)
3621+
}
3622+
}
3623+
35943624
// SendCoins sends the passed amount of (or all) coins to the passed address.
35953625
// Either amount or sendAll must be specified, while confTarget, satsPerVByte
35963626
// are optional and may be set to zero in which case automatic conf target and
35973627
// fee will be used. Returns the tx id upon success.
35983628
func (s *lightningClient) SendCoins(ctx context.Context, addr btcutil.Address,
35993629
amount btcutil.Amount, sendAll bool, confTarget int32,
3600-
satsPerVByte chainfee.SatPerVByte, label string) (string, error) {
3630+
satsPerVByte chainfee.SatPerVByte, label string,
3631+
opts ...SendCoinsOption) (string, error) {
36013632

36023633
rpcCtx, cancel := context.WithTimeout(ctx, s.timeout)
36033634
defer cancel()
36043635

36053636
rpcCtx = s.adminMac.WithMacaroonAuth(rpcCtx)
36063637

36073638
req := &lnrpc.SendCoinsRequest{
3608-
Addr: addr.String(),
3609-
Amount: int64(amount),
3610-
TargetConf: confTarget,
3611-
SatPerVbyte: uint64(satsPerVByte),
3612-
SendAll: sendAll,
3613-
Label: label,
3639+
Addr: addr.String(),
3640+
Amount: int64(amount),
3641+
TargetConf: confTarget,
3642+
SatPerKw: uint64(satsPerVByte.FeePerKWeight()),
3643+
SendAll: sendAll,
3644+
Label: label,
3645+
}
3646+
3647+
for _, opt := range opts {
3648+
opt(req)
36143649
}
36153650

36163651
resp, err := s.client.SendCoins(rpcCtx, req)

walletkit_client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,8 @@ func (m *walletKitClient) BumpFee(ctx context.Context, op wire.OutPoint,
809809
TxidBytes: op.Hash[:],
810810
OutputIndex: op.Index,
811811
},
812-
SatPerVbyte: uint64(feeRate.FeePerVByte()),
813-
Immediate: false,
812+
SatPerKw: uint64(feeRate),
813+
Immediate: false,
814814
}
815815

816816
for _, opt := range opts {

0 commit comments

Comments
 (0)