Skip to content

Commit

Permalink
rpc: add psbt_version to (psbt)bumpfee
Browse files Browse the repository at this point in the history
Also have the GUI use version 0.
  • Loading branch information
Sjors committed Jan 27, 2025
1 parent 3818933 commit 31b5e29
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Wallet
CMutableTransaction& mtx) = 0;

//! Sign bump transaction.
virtual bool signBumpTransaction(CMutableTransaction& mtx) = 0;
virtual bool signBumpTransaction(CMutableTransaction& mtx, const uint32_t psbt_version) = 0;

//! Commit bump transaction.
virtual bool commitBumpTransaction(const uint256& txid,
Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ bool WalletModel::bumpFee(uint256 hash, uint256& new_hash)
assert(!m_wallet->privateKeysDisabled() || wallet().hasExternalSigner());

// sign bumped transaction
if (!m_wallet->signBumpTransaction(mtx)) {
if (!m_wallet->signBumpTransaction(mtx, /*psbt_version=*/0)) {
QMessageBox::critical(nullptr, tr("Fee bump error"), tr("Can't sign transaction."));
return false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "bumpfee", 1, "replaceable"},
{ "bumpfee", 1, "outputs"},
{ "bumpfee", 1, "original_change_index"},
{ "bumpfee", 1, "psbt_version"},
{ "psbtbumpfee", 1, "options" },
{ "psbtbumpfee", 1, "conf_target"},
{ "psbtbumpfee", 1, "fee_rate"},
{ "psbtbumpfee", 1, "replaceable"},
{ "psbtbumpfee", 1, "outputs"},
{ "psbtbumpfee", 1, "original_change_index"},
{ "psbtbumpfee", 1, "psbt_version"},
{ "logging", 0, "include" },
{ "logging", 1, "exclude" },
{ "disconnectnode", 1, "nodeid" },
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/feebumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,12 @@ Result CreateRateBumpTransaction(CWallet& wallet, const uint256& txid, const CCo
return Result::OK;
}

bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx) {
bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx, const uint32_t psbt_version) {
LOCK(wallet.cs_wallet);

if (wallet.IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
// Make a blank psbt
PartiallySignedTransaction psbtx(mtx);
PartiallySignedTransaction psbtx(mtx, psbt_version);

// First fill transaction with our data without signing,
// so external signers are not asked to sign more than once.
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/feebumper.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Result CreateRateBumpTransaction(CWallet& wallet,
//! Sign the new transaction,
//! @return false if the tx couldn't be found or if it was
//! impossible to create the signature(s)
bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx);
bool SignTransaction(CWallet& wallet, CMutableTransaction& mtx, const uint32_t psbt_version);

//! Commit the bumpfee transaction.
//! @return success in case of CWallet::CommitTransaction was successful,
Expand Down
4 changes: 2 additions & 2 deletions src/wallet/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,9 @@ class WalletImpl : public Wallet
std::vector<CTxOut> outputs; // just an empty list of new recipients for now
return feebumper::CreateRateBumpTransaction(*m_wallet.get(), txid, coin_control, errors, old_fee, new_fee, mtx, /* require_mine= */ true, outputs) == feebumper::Result::OK;
}
bool signBumpTransaction(CMutableTransaction& mtx) override
bool signBumpTransaction(CMutableTransaction& mtx, const uint32_t psbt_version) override
{
return feebumper::SignTransaction(*m_wallet.get(), mtx);
return feebumper::SignTransaction(*m_wallet.get(), mtx, psbt_version);
}
bool commitBumpTransaction(const uint256& txid,
CMutableTransaction&& mtx,
Expand Down
15 changes: 13 additions & 2 deletions src/wallet/rpc/spend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
"The remainder after paying the recipients and fees will be sent to the output script of the "
"original change output. The change output’s amount can increase if bumping the transaction "
"adds new inputs, otherwise it will decrease. Cannot be used in combination with the 'outputs' option."},
{"psbt_version", RPCArg::Type::NUM, RPCArg::Default(2), "The PSBT version number to use."},
},
RPCArgOptions{.oneline_description="options"}},
},
Expand Down Expand Up @@ -1071,6 +1072,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
std::vector<CTxOut> outputs;

std::optional<uint32_t> original_change_index;
uint32_t psbt_version = 2;

if (!request.params[1].isNull()) {
UniValue options = request.params[1];
Expand All @@ -1083,6 +1085,8 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
{"estimate_mode", UniValueType(UniValue::VSTR)},
{"outputs", UniValueType()}, // will be checked by AddOutputs()
{"original_change_index", UniValueType(UniValue::VNUM)},
{"psbt_version", UniValueType(UniValue::VNUM)},

},
true, true);

Expand Down Expand Up @@ -1110,6 +1114,13 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
if (options.exists("original_change_index")) {
original_change_index = options["original_change_index"].getInt<uint32_t>();
}

if (!options["psbt_version"].isNull()) {
psbt_version = options["psbt_version"].getInt<int>();
}
if (psbt_version != 2 && psbt_version != 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "The PSBT version can only be 2 or 0");
}
}

// Make sure the results are valid at least up to the most recent block
Expand Down Expand Up @@ -1153,7 +1164,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)
// For bumpfee, return the new transaction id.
// For psbtbumpfee, return the base64-encoded unsigned PSBT of the new transaction.
if (!want_psbt) {
if (!feebumper::SignTransaction(*pwallet, mtx)) {
if (!feebumper::SignTransaction(*pwallet, mtx, psbt_version)) {
if (pwallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Transaction incomplete. Try psbtbumpfee instead.");
}
Expand All @@ -1167,7 +1178,7 @@ static RPCHelpMan bumpfee_helper(std::string method_name)

result.pushKV("txid", txid.GetHex());
} else {
PartiallySignedTransaction psbtx(mtx, /*version=*/2);
PartiallySignedTransaction psbtx(mtx, psbt_version);
bool complete = false;
const auto err{pwallet->FillPSBT(psbtx, complete, SIGHASH_DEFAULT, /*sign=*/false, /*bip32derivs=*/true)};
CHECK_NONFATAL(!err);
Expand Down

0 comments on commit 31b5e29

Please sign in to comment.