diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 84bfe6995ff..4d377a4823d 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -229,16 +229,15 @@ static void MutateTxLocktime(CMutableTransaction& tx, const std::string& cmdVal) static void MutateTxRBFOptIn(CMutableTransaction& tx, const std::string& strInIdx) { - // parse requested index - int64_t inIdx = -1; - if (strInIdx != "" && (!ParseInt64(strInIdx, &inIdx) || inIdx < 0 || inIdx >= static_cast(tx.vin.size()))) { + const auto idx{ToIntegral(strInIdx)}; + if (strInIdx != "" && (!idx || *idx >= tx.vin.size())) { throw std::runtime_error("Invalid TX input index '" + strInIdx + "'"); } // set the nSequence to MAX_INT - 2 (= RBF opt in flag) - int cnt = 0; + uint32_t cnt{0}; for (CTxIn& txin : tx.vin) { - if (strInIdx == "" || cnt == inIdx) { + if (strInIdx == "" || cnt == *idx) { if (txin.nSequence > MAX_BIP125_RBF_SEQUENCE) { txin.nSequence = MAX_BIP125_RBF_SEQUENCE; } diff --git a/test/util/data/bitcoin-util-test.json b/test/util/data/bitcoin-util-test.json index d599731ca6e..81423724075 100644 --- a/test/util/data/bitcoin-util-test.json +++ b/test/util/data/bitcoin-util-test.json @@ -177,6 +177,15 @@ "error_txt": "error: Invalid TX input index", "description": "Tests the check for an invalid string input index with replaceable" }, + { "exec": "./bitcoin-tx", + "args": + ["-create", + "in=5897de6bd6027a475eadd57019d4e6872c396d0716c4875a5f1a6fcfdf385c1f:0", + "replaceable=+0"], + "return_code": 1, + "error_txt": "error: Invalid TX input index", + "description": "Tests the check for an invalid string input index with replaceable" + }, { "exec": "./bitcoin-tx", "args":