Skip to content

Commit e9b4f94

Browse files
committed
bumpfee: Return PSBT when wallet has privkeys disabled
1 parent 75a5e47 commit e9b4f94

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/wallet/rpcwallet.cpp

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3365,10 +3365,11 @@ static UniValue bumpfee(const JSONRPCRequest& request)
33653365
},
33663366
RPCResult{
33673367
"{\n"
3368-
" \"txid\": \"value\", (string) The id of the new transaction\n"
3369-
" \"origfee\": n, (numeric) Fee of the replaced transaction\n"
3370-
" \"fee\": n, (numeric) Fee of the new transaction\n"
3371-
" \"errors\": [ str... ] (json array of strings) Errors encountered during processing (may be empty)\n"
3368+
" \"psbt\": \"psbt\", (string) The base64-encoded unsigned PSBT of the new transaction. Only returned when wallet private keys are disabled.\n"
3369+
" \"txid\": \"value\", (string) The id of the new transaction. Only returned when wallet private keys are enabled.\n"
3370+
" \"origfee\": n, (numeric) The fee of the replaced transaction.\n"
3371+
" \"fee\": n, (numeric) The fee of the new transaction.\n"
3372+
" \"errors\": [ str... ] (json array of strings) Errors encountered during processing (may be empty).\n"
33723373
"}\n"
33733374
},
33743375
RPCExamples{
@@ -3470,17 +3471,32 @@ static UniValue bumpfee(const JSONRPCRequest& request)
34703471
}
34713472
}
34723473

3473-
// sign bumped transaction
3474-
if (!feebumper::SignTransaction(*pwallet, mtx)) {
3475-
throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");
3476-
}
3477-
// commit the bumped transaction
3478-
uint256 txid;
3479-
if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
3480-
throw JSONRPCError(RPC_WALLET_ERROR, errors[0]);
3481-
}
34823474
UniValue result(UniValue::VOBJ);
3483-
result.pushKV("txid", txid.GetHex());
3475+
3476+
// If wallet private keys are enabled, return the new transaction id,
3477+
// otherwise return the base64-encoded unsigned PSBT of the new transaction.
3478+
if (!pwallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
3479+
if (!feebumper::SignTransaction(*pwallet, mtx)) {
3480+
throw JSONRPCError(RPC_WALLET_ERROR, "Can't sign transaction.");
3481+
}
3482+
3483+
uint256 txid;
3484+
if (feebumper::CommitTransaction(*pwallet, hash, std::move(mtx), errors, txid) != feebumper::Result::OK) {
3485+
throw JSONRPCError(RPC_WALLET_ERROR, errors[0]);
3486+
}
3487+
3488+
result.pushKV("txid", txid.GetHex());
3489+
} else {
3490+
PartiallySignedTransaction psbtx(mtx);
3491+
bool complete = false;
3492+
const TransactionError err = FillPSBT(pwallet, psbtx, complete, SIGHASH_ALL, false /* sign */, true /* bip32derivs */);
3493+
CHECK_NONFATAL(err == TransactionError::OK);
3494+
CHECK_NONFATAL(!complete);
3495+
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
3496+
ssTx << psbtx;
3497+
result.pushKV("psbt", EncodeBase64(ssTx.str()));
3498+
}
3499+
34843500
result.pushKV("origfee", ValueFromAmount(old_fee));
34853501
result.pushKV("fee", ValueFromAmount(new_fee));
34863502
UniValue result_errors(UniValue::VARR);

0 commit comments

Comments
 (0)