From 8d58fdf1a92e64ff44c7676088b2da95eb283e30 Mon Sep 17 00:00:00 2001 From: fanquake Date: Sat, 3 Oct 2020 09:56:59 +0800 Subject: [PATCH] Merge #19956: rpc: Improve invalid vout value rpc error message f471a3be00c2b6433b8c258b716982c0539da13f scripted diff: Improve invalid vout value rpc error message (Nima Yazdanmehr) Pull request description: Since the `vout` value can start at `0`, the error message for *negative* values can be improved to something like: `vout cannot be negative`. ACKs for top commit: fanquake: ACK f471a3be00c2b6433b8c258b716982c0539da13f promag: Code review ACK f471a3be00c2b6433b8c258b716982c0539da13f. Tree-SHA512: fbdee3d0ddd5b58eb93934a1217b44e125a9ad39e672b1f35c7609c6c5fcf45ae1b731d3d6135b7225d98792dbfc34a50907b8c41274a5b029d7b5c59f886560 --- src/dash-tx.cpp | 2 +- src/rpc/rawtransaction_util.cpp | 4 ++-- src/wallet/rpcwallet.cpp | 2 +- test/functional/rpc_rawtransaction.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dash-tx.cpp b/src/dash-tx.cpp index f1bbb619b7..e791cc81fe 100644 --- a/src/dash-tx.cpp +++ b/src/dash-tx.cpp @@ -554,7 +554,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr) const int nOut = prevOut["vout"].get_int(); if (nOut < 0) - throw std::runtime_error("vout must be positive"); + throw std::runtime_error("vout cannot be negative"); COutPoint out(txid, nOut); std::vector pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey")); diff --git a/src/rpc/rawtransaction_util.cpp b/src/rpc/rawtransaction_util.cpp index 2c1f35248a..3f32edce0b 100644 --- a/src/rpc/rawtransaction_util.cpp +++ b/src/rpc/rawtransaction_util.cpp @@ -47,7 +47,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key"); int nOutput = vout_v.get_int(); if (nOutput < 0) - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); uint32_t nSequence = (rawTx.nLockTime ? CTxIn::SEQUENCE_FINAL - 1 : CTxIn::SEQUENCE_FINAL); @@ -155,7 +155,7 @@ UniValue SignTransaction(interfaces::Chain& chain, CMutableTransaction& mtx, con int nOut = find_value(prevOut, "vout").get_int(); if (nOut < 0) { - throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive"); + throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative"); } COutPoint out(txid, nOut); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c0e40e9b4a..00e450ec86 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2321,7 +2321,7 @@ static UniValue lockunspent(const JSONRPCRequest& request) const int nOutput = find_value(o, "vout").get_int(); if (nOutput < 0) { - throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive"); + throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative"); } const COutPoint outpt(uint256S(txid), nOutput); diff --git a/test/functional/rpc_rawtransaction.py b/test/functional/rpc_rawtransaction.py index 6bf0158824..79ac4d34fd 100755 --- a/test/functional/rpc_rawtransaction.py +++ b/test/functional/rpc_rawtransaction.py @@ -94,7 +94,7 @@ class RawTransactionsTest(BitcoinTestFramework): assert_raises_rpc_error(-8, "txid must be hexadecimal string", self.nodes[0].createrawtransaction, [{'txid': 'foo'}], {}) assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid}], {}) assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 'foo'}], {}) - assert_raises_rpc_error(-8, "Invalid parameter, vout must be positive", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {}) + assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {}) assert_raises_rpc_error(-8, "Invalid parameter, sequence number is out of range", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 0, 'sequence': -1}], {}) # Test `createrawtransaction` invalid `outputs`