rpc: bugfix: Properly use iswitness in converttopsbt
Also explain the param in all RPCs
This commit is contained in:
parent
fa5c5cd141
commit
fa499b5f02
3 changed files with 26 additions and 13 deletions
|
@ -435,8 +435,13 @@ static UniValue decoderawtransaction(const JSONRPCRequest& request)
|
||||||
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
|
"\nReturn a JSON object representing the serialized, hex-encoded transaction.\n",
|
||||||
{
|
{
|
||||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
|
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The transaction hex string"},
|
||||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction\n"
|
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
||||||
" If iswitness is not present, heuristic tests will be used in decoding"},
|
"If iswitness is not present, heuristic tests will be used in decoding.\n"
|
||||||
|
"If true, only witness deserialization will be tried.\n"
|
||||||
|
"If false, only non-witness deserialization will be tried.\n"
|
||||||
|
"This boolean should reflect whether the transaction has inputs\n"
|
||||||
|
"(e.g. fully valid, or on-chain transactions), if known by the caller."
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -1422,12 +1427,15 @@ UniValue converttopsbt(const JSONRPCRequest& request)
|
||||||
"createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
|
"createpsbt and walletcreatefundedpsbt should be used for new applications.\n",
|
||||||
{
|
{
|
||||||
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of a raw transaction"},
|
{"hexstring", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "The hex string of a raw transaction"},
|
||||||
{"permitsigdata", RPCArg::Type::BOOL, /* default */ "false", "If true, any signatures in the input will be discarded and conversion.\n"
|
{"permitsigdata", RPCArg::Type::BOOL, /* default */ "false", "If true, any signatures in the input will be discarded and conversion\n"
|
||||||
" will continue. If false, RPC will fail if any signatures are present."},
|
" will continue. If false, RPC will fail if any signatures are present."},
|
||||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
||||||
" If iswitness is not present, heuristic tests will be used in decoding. If true, only witness deserializaion\n"
|
"If iswitness is not present, heuristic tests will be used in decoding.\n"
|
||||||
" will be tried. If false, only non-witness deserialization will be tried. Only has an effect if\n"
|
"If true, only witness deserialization will be tried.\n"
|
||||||
" permitsigdata is true."},
|
"If false, only non-witness deserialization will be tried.\n"
|
||||||
|
"This boolean should reflect whether the transaction has inputs\n"
|
||||||
|
"(e.g. fully valid, or on-chain transactions), if known by the caller."
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
" \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n"
|
" \"psbt\" (string) The resulting raw transaction (base64-encoded string)\n"
|
||||||
|
@ -1444,7 +1452,6 @@ UniValue converttopsbt(const JSONRPCRequest& request)
|
||||||
throw std::runtime_error(help.ToString());
|
throw std::runtime_error(help.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true);
|
RPCTypeCheck(request.params, {UniValue::VSTR, UniValue::VBOOL, UniValue::VBOOL}, true);
|
||||||
|
|
||||||
// parse hex string from parameter
|
// parse hex string from parameter
|
||||||
|
@ -1452,8 +1459,8 @@ UniValue converttopsbt(const JSONRPCRequest& request)
|
||||||
bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
|
bool permitsigdata = request.params[1].isNull() ? false : request.params[1].get_bool();
|
||||||
bool witness_specified = !request.params[2].isNull();
|
bool witness_specified = !request.params[2].isNull();
|
||||||
bool iswitness = witness_specified ? request.params[2].get_bool() : false;
|
bool iswitness = witness_specified ? request.params[2].get_bool() : false;
|
||||||
bool try_witness = permitsigdata ? (witness_specified ? iswitness : true) : false;
|
const bool try_witness = witness_specified ? iswitness : true;
|
||||||
bool try_no_witness = permitsigdata ? (witness_specified ? !iswitness : true) : true;
|
const bool try_no_witness = witness_specified ? !iswitness : true;
|
||||||
if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
|
if (!DecodeHexTx(tx, request.params[0].get_str(), try_no_witness, try_witness)) {
|
||||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
|
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -3030,8 +3030,13 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
|
||||||
" \"CONSERVATIVE\""},
|
" \"CONSERVATIVE\""},
|
||||||
},
|
},
|
||||||
"options"},
|
"options"},
|
||||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction \n"
|
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
||||||
" If iswitness is not present, heuristic tests will be used in decoding"},
|
"If iswitness is not present, heuristic tests will be used in decoding.\n"
|
||||||
|
"If true, only witness deserialization will be tried.\n"
|
||||||
|
"If false, only non-witness deserialization will be tried.\n"
|
||||||
|
"This boolean should reflect whether the transaction has inputs\n"
|
||||||
|
"(e.g. fully valid, or on-chain transactions), if known by the caller."
|
||||||
|
},
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
"{\n"
|
"{\n"
|
||||||
|
|
|
@ -152,9 +152,10 @@ class PSBTTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# Make sure that a non-psbt with signatures cannot be converted
|
# Make sure that a non-psbt with signatures cannot be converted
|
||||||
# Error could be either "TX decode failed" (segwit inputs causes parsing to fail) or "Inputs must not have scriptSigs and scriptWitnesses"
|
# Error could be either "TX decode failed" (segwit inputs causes parsing to fail) or "Inputs must not have scriptSigs and scriptWitnesses"
|
||||||
|
# We must set iswitness=True because the serialized transaction has inputs and is therefore a witness transaction
|
||||||
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])
|
signedtx = self.nodes[0].signrawtransactionwithwallet(rawtx['hex'])
|
||||||
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, signedtx['hex'])
|
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, hexstring=signedtx['hex'], iswitness=True)
|
||||||
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, signedtx['hex'], False)
|
assert_raises_rpc_error(-22, "", self.nodes[0].converttopsbt, hexstring=signedtx['hex'], permitsigdata=False, iswitness=True)
|
||||||
# Unless we allow it to convert and strip signatures
|
# Unless we allow it to convert and strip signatures
|
||||||
self.nodes[0].converttopsbt(signedtx['hex'], True)
|
self.nodes[0].converttopsbt(signedtx['hex'], True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue