-
Notifications
You must be signed in to change notification settings - Fork 2.2k
walletrpc: add raw_tx field to BumpFee response #10323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import ( | |
| "context" | ||
| "encoding/base64" | ||
| "encoding/binary" | ||
| "encoding/hex" | ||
| "errors" | ||
| "fmt" | ||
| "maps" | ||
|
|
@@ -1151,27 +1152,59 @@ func (w *WalletKit) BumpFee(ctx context.Context, | |
| return nil, err | ||
| } | ||
|
|
||
| var ( | ||
| resultChan chan sweep.Result | ||
| status string | ||
| ) | ||
|
|
||
| // If this input exists, we will update its params. | ||
| if existing { | ||
| _, err = w.cfg.Sweeper.UpdateParams(*op, params) | ||
| resultChan, err = w.cfg.Sweeper.UpdateParams(*op, params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| status = "Successfully registered rbf-tx with sweeper" | ||
| } else { | ||
| // Otherwise, create a new sweeping request for this input. | ||
| resultChan, err = w.sweepNewInput( | ||
| op, uint32(currentHeight), params, | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| status = "Successfully registered CPFP-tx with the sweeper" | ||
| } | ||
|
|
||
| return &BumpFeeResponse{ | ||
| Status: "Successfully registered rbf-tx with sweeper", | ||
| }, nil | ||
| response := &BumpFeeResponse{ | ||
| Status: status, | ||
| } | ||
|
|
||
| // Otherwise, create a new sweeping request for this input. | ||
| err = w.sweepNewInput(op, uint32(currentHeight), params) | ||
| if err != nil { | ||
| return nil, err | ||
| // If the caller requested the raw transaction, wait for the sweep | ||
| // result and extract the transaction hex. | ||
| if in.IncludeRawTx { | ||
| select { | ||
| case result := <-resultChan: | ||
| if result.Err != nil { | ||
| return nil, fmt.Errorf("sweep failed: %w", | ||
| result.Err) | ||
| } | ||
|
|
||
| if result.Tx != nil { | ||
| var buf bytes.Buffer | ||
| err := result.Tx.Serialize(&buf) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to "+ | ||
| "serialize tx: %w", err) | ||
|
Comment on lines
+1196
to
+1197
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This string concatenation is unnecessary as the line is not exceeding the length limit. Combining it into a single string improves readability.1 return nil, fmt.Errorf("failed to serialize tx: %w", err)Style Guide ReferencesFootnotes
|
||
| } | ||
| response.RawTx = hex.EncodeToString(buf.Bytes()) | ||
| } | ||
|
|
||
| case <-ctx.Done(): | ||
| return nil, ctx.Err() | ||
| } | ||
| } | ||
|
|
||
| return &BumpFeeResponse{ | ||
| Status: "Successfully registered CPFP-tx with the sweeper", | ||
| }, nil | ||
| return response, nil | ||
| } | ||
|
|
||
| // getWaitingCloseChannel returns the waiting close channel in case it does | ||
|
|
@@ -1343,7 +1376,7 @@ func (w *WalletKit) BumpForceCloseFee(_ context.Context, | |
| // | ||
| // NOTE: if the budget is not set, the default budget ratio is used. | ||
| func (w *WalletKit) sweepNewInput(op *wire.OutPoint, currentHeight uint32, | ||
| params sweep.Params) error { | ||
| params sweep.Params) (chan sweep.Result, error) { | ||
|
|
||
| log.Debugf("Attempting to sweep outpoint %s", op) | ||
|
|
||
|
|
@@ -1356,12 +1389,12 @@ func (w *WalletKit) sweepNewInput(op *wire.OutPoint, currentHeight uint32, | |
| // order to sweep the output. | ||
| utxo, err := w.cfg.Wallet.FetchOutpointInfo(op) | ||
| if err != nil { | ||
| return err | ||
| return nil, err | ||
| } | ||
|
|
||
| // We're only able to bump the fee of unconfirmed transactions. | ||
| if utxo.Confirmations > 0 { | ||
| return errors.New("unable to bump fee of a confirmed " + | ||
| return nil, errors.New("unable to bump fee of a confirmed " + | ||
| "transaction") | ||
| } | ||
|
|
||
|
|
@@ -1401,18 +1434,19 @@ func (w *WalletKit) sweepNewInput(op *wire.OutPoint, currentHeight uint32, | |
| witnessType = input.TaprootPubKeySpend | ||
| signDesc.HashType = txscript.SigHashDefault | ||
| default: | ||
| return fmt.Errorf("unknown input witness %v", op) | ||
| return nil, fmt.Errorf("unknown input witness %v", op) | ||
| } | ||
|
|
||
| log.Infof("[BumpFee]: bumping fee for new input=%v, params=%v", op, | ||
| params) | ||
|
|
||
| inp := input.NewBaseInput(op, witnessType, signDesc, currentHeight) | ||
| if _, err = w.cfg.Sweeper.SweepInput(inp, params); err != nil { | ||
| return err | ||
| resultChan, err := w.cfg.Sweeper.SweepInput(inp, params) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return nil | ||
| return resultChan, nil | ||
| } | ||
|
|
||
| // ListSweeps returns a list of the sweeps that our node has published. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment for
include_raw_txshould mention that setting this flag to true will cause the RPC call to block until the sweep transaction is created. This is a crucial detail for API users to understand the behavior of the call.