@@ -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,70 @@ 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 block.
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. Pass feeRate=0 to BumpFee if you
755+ // add this option.
756+ func WithTargetConf (targetConf uint32 ) BumpFeeOption {
757+ return func (r * walletrpc.BumpFeeRequest ) {
758+ r .TargetConf = targetConf
759+ }
760+ }
761+
762+ // WithBudget is an option for setting the budget of BumpFee. It is the max
763+ // amount in sats that can be used as the fees. Setting this value greater than
764+ // the input's value may result in CPFP - one or more wallet utxos will be used
765+ // to pay the fees specified by the budget. If not set, for new inputs, by
766+ // default 50% of the input's value will be treated as the budget for fee
767+ // bumping; for existing inputs, their current budgets will be retained.
768+ func WithBudget (budget btcutil.Amount ) BumpFeeOption {
769+ return func (r * walletrpc.BumpFeeRequest ) {
770+ r .Budget = uint64 (budget )
771+ }
772+ }
773+
740774// BumpFee attempts to bump the fee of a transaction by spending one of its
741775// outputs at the given fee rate. This essentially results in a
742776// child-pays-for-parent (CPFP) scenario. If the given output has been used in a
743777// previous BumpFee call, then a transaction replacing the previous is
744778// broadcast, resulting in a replace-by-fee (RBF) scenario.
745779func (m * walletKitClient ) BumpFee (ctx context.Context , op wire.OutPoint ,
746- feeRate chainfee.SatPerKWeight ) error {
780+ feeRate chainfee.SatPerKWeight , opts ... BumpFeeOption ) error {
747781
748782 rpcCtx , cancel := context .WithTimeout (ctx , m .timeout )
749783 defer cancel ()
750784
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 ,
785+ req := & walletrpc.BumpFeeRequest {
786+ Outpoint : & lnrpc.OutPoint {
787+ TxidBytes : op .Hash [:],
788+ OutputIndex : op .Index ,
760789 },
761- )
790+ SatPerVbyte : uint64 (feeRate .FeePerVByte ()),
791+ Immediate : false ,
792+ }
793+
794+ for _ , opt := range opts {
795+ opt (req )
796+ }
797+
798+ // Make sure that feeRate and WithTargetConf are not used together.
799+ if feeRate != 0 && req .TargetConf != 0 {
800+ return fmt .Errorf ("can't use target_conf if feeRate != 0" )
801+ }
802+
803+ _ , err := m .client .BumpFee (m .walletKitMac .WithMacaroonAuth (rpcCtx ), req )
804+
762805 return err
763806}
764807
0 commit comments