Skip to content

Commit 54fc96f

Browse files
committed
Merge #19956: rpc: Improve invalid vout value rpc error message
f471a3b 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 f471a3b promag: Code review ACK f471a3b. Tree-SHA512: fbdee3d0ddd5b58eb93934a1217b44e125a9ad39e672b1f35c7609c6c5fcf45ae1b731d3d6135b7225d98792dbfc34a50907b8c41274a5b029d7b5c59f886560
2 parents 171cd05 + f471a3b commit 54fc96f

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ static void MutateTxSign(CMutableTransaction& tx, const std::string& flagStr)
594594

595595
const int nOut = prevOut["vout"].get_int();
596596
if (nOut < 0)
597-
throw std::runtime_error("vout must be positive");
597+
throw std::runtime_error("vout cannot be negative");
598598

599599
COutPoint out(txid, nOut);
600600
std::vector<unsigned char> pkData(ParseHexUV(prevOut["scriptPubKey"], "scriptPubKey"));

src/rpc/rawtransaction_util.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ CMutableTransaction ConstructTransaction(const UniValue& inputs_in, const UniVal
5555
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, missing vout key");
5656
int nOutput = vout_v.get_int();
5757
if (nOutput < 0)
58-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
58+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
5959

6060
uint32_t nSequence;
6161
if (rbf) {
@@ -177,7 +177,7 @@ void ParsePrevouts(const UniValue& prevTxsUnival, FillableSigningProvider* keyst
177177

178178
int nOut = find_value(prevOut, "vout").get_int();
179179
if (nOut < 0) {
180-
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout must be positive");
180+
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "vout cannot be negative");
181181
}
182182

183183
COutPoint out(txid, nOut);

src/wallet/rpcwallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2204,7 +2204,7 @@ static RPCHelpMan lockunspent()
22042204
const uint256 txid(ParseHashO(o, "txid"));
22052205
const int nOutput = find_value(o, "vout").get_int();
22062206
if (nOutput < 0) {
2207-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout must be positive");
2207+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout cannot be negative");
22082208
}
22092209

22102210
const COutPoint outpt(txid, nOutput);

test/functional/rpc_rawtransaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def run_test(self):
9696
assert_raises_rpc_error(-8, "txid must be hexadecimal string (not 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844')", self.nodes[0].createrawtransaction, [{'txid': 'ZZZ7bb8b1697ea987f3b223ba7819250cae33efacb068d23dc24859824a77844'}], {})
9797
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid}], {})
9898
assert_raises_rpc_error(-8, "Invalid parameter, missing vout key", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 'foo'}], {})
99-
assert_raises_rpc_error(-8, "Invalid parameter, vout must be positive", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {})
99+
assert_raises_rpc_error(-8, "Invalid parameter, vout cannot be negative", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': -1}], {})
100100
assert_raises_rpc_error(-8, "Invalid parameter, sequence number is out of range", self.nodes[0].createrawtransaction, [{'txid': txid, 'vout': 0, 'sequence': -1}], {})
101101

102102
# Test `createrawtransaction` invalid `outputs`

0 commit comments

Comments
 (0)