Skip to content

Commit 2974fa7

Browse files
committed
bumpfee: add more flags as options
New options added: 'immediate', 'target_conf', 'budget'.
1 parent b07e7b7 commit 2974fa7

File tree

1 file changed

+54
-12
lines changed

1 file changed

+54
-12
lines changed

walletkit_client.go

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ type WalletKitClient interface {
134134
// child-pays-for-parent (CPFP) scenario. If the given output has been
135135
// used in a previous BumpFee call, then a transaction replacing the
136136
// previous is broadcast, resulting in a replace-by-fee (RBF) scenario.
137-
BumpFee(context.Context, wire.OutPoint, chainfee.SatPerKWeight) error
137+
BumpFee(context.Context, wire.OutPoint, chainfee.SatPerKWeight,
138+
...BumpFeeOption) error
138139

139140
// ListAccounts retrieves all accounts belonging to the wallet by default.
140141
// Optional name and addressType can be provided to filter through all the
@@ -737,28 +738,69 @@ func (m *walletKitClient) ListSweepsVerbose(ctx context.Context,
737738
return result, nil
738739
}
739740

741+
// BumpFeeOption customizes a BumpFee call.
742+
type BumpFeeOption func(*walletrpc.BumpFeeRequest)
743+
744+
// WithImmediate is an option for enabling the immediate mode of BumpFee. The
745+
// sweeper will sweep this input without waiting for the next batch.
746+
func WithImmediate() BumpFeeOption {
747+
return func(r *walletrpc.BumpFeeRequest) {
748+
r.Immediate = true
749+
}
750+
}
751+
752+
// WithTargetConf is an option for setting the target_conf of BumpFee. If set,
753+
// the underlying fee estimator will use the target_conf to estimate the
754+
// starting fee rate for the fee function. The value of feeRate passed to
755+
// BumpFee will be ignored.
756+
func WithTargetConf(targetConf uint32) BumpFeeOption {
757+
return func(r *walletrpc.BumpFeeRequest) {
758+
r.TargetConf = targetConf
759+
760+
// We unset sat_per_vbyte, because if it is specified, it is
761+
// used instead of target_conf.
762+
r.SatPerVbyte = 0
763+
}
764+
}
765+
766+
// WithBudget is an option for setting the budget of BumpFee. It is the max
767+
// amount in sats that can be used as the fees. Setting this value greater than
768+
// the input's value may result in CPFP - one or more wallet utxos will be used
769+
// to pay the fees specified by the budget. If not set, for new inputs, by
770+
// default 50% of the input's value will be treated as the budget for fee
771+
// bumping; for existing inputs, their current budgets will be retained.
772+
func WithBudget(budget btcutil.Amount) BumpFeeOption {
773+
return func(r *walletrpc.BumpFeeRequest) {
774+
r.Budget = uint64(budget)
775+
}
776+
}
777+
740778
// BumpFee attempts to bump the fee of a transaction by spending one of its
741779
// outputs at the given fee rate. This essentially results in a
742780
// child-pays-for-parent (CPFP) scenario. If the given output has been used in a
743781
// previous BumpFee call, then a transaction replacing the previous is
744782
// broadcast, resulting in a replace-by-fee (RBF) scenario.
745783
func (m *walletKitClient) BumpFee(ctx context.Context, op wire.OutPoint,
746-
feeRate chainfee.SatPerKWeight) error {
784+
feeRate chainfee.SatPerKWeight, opts ...BumpFeeOption) error {
747785

748786
rpcCtx, cancel := context.WithTimeout(ctx, m.timeout)
749787
defer cancel()
750788

751-
_, err := m.client.BumpFee(
752-
m.walletKitMac.WithMacaroonAuth(rpcCtx),
753-
&walletrpc.BumpFeeRequest{
754-
Outpoint: &lnrpc.OutPoint{
755-
TxidBytes: op.Hash[:],
756-
OutputIndex: op.Index,
757-
},
758-
SatPerVbyte: uint64(feeRate.FeePerKVByte() / 1000),
759-
Immediate: false,
789+
req := &walletrpc.BumpFeeRequest{
790+
Outpoint: &lnrpc.OutPoint{
791+
TxidBytes: op.Hash[:],
792+
OutputIndex: op.Index,
760793
},
761-
)
794+
SatPerVbyte: uint64(feeRate.FeePerKVByte() / 1000),
795+
Immediate: false,
796+
}
797+
798+
for _, opt := range opts {
799+
opt(req)
800+
}
801+
802+
_, err := m.client.BumpFee(m.walletKitMac.WithMacaroonAuth(rpcCtx), req)
803+
762804
return err
763805
}
764806

0 commit comments

Comments
 (0)