Skip to content

Commit fa499b5

Browse files
author
MarcoFalke
committed
rpc: bugfix: Properly use iswitness in converttopsbt
Also explain the param in all RPCs
1 parent fa5c5cd commit fa499b5

File tree

3 files changed

+26
-13
lines changed

3 files changed

+26
-13
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,13 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
435435
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
436436
{
437437
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
438-
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction\n"
439-
" If iswitness is not present, heuristic tests will be used in decoding"},
438+
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
439+
"If iswitness is not present, heuristic tests will be used in decoding.\n"
440+
"If true, only witness deserialization will be tried.\n"
441+
"If false, only non-witness deserialization will be tried.\n"
442+
"This boolean should reflect whether the transaction has inputs\n"
443+
"(e.g. fully valid, or on-chain transactions), if known by the caller."
444+
},
440445
},
441446
RPCResult{
442447
"{\n"
@@ -1422,12 +1427,15 @@ UniValue converttopsbt(const JSONRPCRequest& request)
14221427
"createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
14231428
{
14241429
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of a raw transaction"},
1425-
{"permitsigdata", RPCArg::Type::BOOL, /* default */ "false", "If true, any signatures in the input will be discarded and conversion.\n"
1430+
{"permitsigdata", RPCArg::Type::BOOL, /* default */ "false", "If true, any signatures in the input will be discarded and conversion\n"
14261431
" will continue. If false, RPC will fail if any signatures are present."},
14271432
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
1428-
" If iswitness is not present, heuristic tests will be used in decoding. If true, only witness deserializaion\n"
1429-
" will be tried. If false, only non-witness deserialization will be tried. Only has an effect if\n"
1430-
" permitsigdata is true."},
1433+
"If iswitness is not present, heuristic tests will be used in decoding.\n"
1434+
"If true, only witness deserialization will be tried.\n"
1435+
"If false, only non-witness deserialization will be tried.\n"
1436+
"This boolean should reflect whether the transaction has inputs\n"
1437+
"(e.g. fully valid, or on-chain transactions), if known by the caller."
1438+
},
14311439
},
14321440
RPCResult{
14331441
" \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n"
@@ -1444,16 +1452,15 @@ UniValue converttopsbt(const JSONRPCRequest& request)
14441452
throw std::runtime_error(help.ToString());
14451453
}
14461454

1447-
14481455
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true);
14491456

14501457
// parse hex string from parameter
14511458
CMutableTransaction tx;
14521459
bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
14531460
bool witness_specified = !request.params[2].isNull();
14541461
bool iswitness = witness_specified ? request.params[2].get_bool() : false;
1455-
bool try_witness = permitsigdata ? (witness_specified ? iswitness : true) : false;
1456-
bool try_no_witness = permitsigdata ? (witness_specified ? !iswitness : true) : true;
1462+
const bool try_witness = witness_specified ? iswitness : true;
1463+
const bool try_no_witness = witness_specified ? !iswitness : true;
14571464
if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
14581465
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
14591466
}

src/wallet/rpcwallet.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,8 +3030,13 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
30303030
" \"CONSERVATIVE\""},
30313031
},
30323032
"options"},
3033-
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction \n"
3034-
" If iswitness is not present, heuristic tests will be used in decoding"},
3033+
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
3034+
"If iswitness is not present, heuristic tests will be used in decoding.\n"
3035+
"If true, only witness deserialization will be tried.\n"
3036+
"If false, only non-witness deserialization will be tried.\n"
3037+
"This boolean should reflect whether the transaction has inputs\n"
3038+
"(e.g. fully valid, or on-chain transactions), if known by the caller."
3039+
},
30353040
},
30363041
RPCResult{
30373042
"{\n"

test/functional/rpc_psbt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ def run_test(self):
152152

153153
# Make sure that a non-psbt with signatures cannot be converted
154154
# Error could be either "TX decode failed" (segwit inputs causes parsing to fail) or "Inputs must not have scriptSigs and scriptWitnesses"
155+
# We must set iswitness=True because the serialized transaction has inputs and is therefore a witness transaction
155156
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])
156-
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, signedtx['hex'])
157-
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, signedtx['hex'], False)
157+
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, hexstring=signedtx['hex'], iswitness=True)
158+
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, hexstring=signedtx['hex'], permitsigdata=False, iswitness=True)
158159
# Unless we allow it to convert and strip signatures
159160
self.nodes[0].converttopsbt(signedtx['hex'], True)
160161

0 commit comments

Comments
 (0)