Skip to content

Commit 73dc19a

Browse files
committed
rpc, refactor: Avoid duplicate set lookup in gettxoutproof
1 parent 875e1cc commit 73dc19a

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,12 @@ static RPCHelpMan gettxoutproof()
244244
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
245245
{
246246
std::set<uint256> setTxids;
247-
uint256 oneTxid;
248247
UniValue txids = request.params[0].get_array();
249248
for (unsigned int idx = 0; idx < txids.size(); idx++) {
250-
const UniValue& txid = txids[idx];
251-
uint256 hash(ParseHashV(txid, "txid"));
252-
if (setTxids.count(hash)) {
253-
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ") + txid.get_str());
249+
auto ret = setTxids.insert(ParseHashV(txids[idx], "txid"));
250+
if (!ret.second) {
251+
throw JSONRPCError(RPC_INVALID_PARAMETER, std::string("Invalid parameter, duplicated txid: ") + txids[idx].get_str());
254252
}
255-
setTxids.insert(hash);
256-
oneTxid = hash;
257253
}
258254

259255
CBlockIndex* pblockindex = nullptr;
@@ -287,7 +283,7 @@ static RPCHelpMan gettxoutproof()
287283
LOCK(cs_main);
288284

289285
if (pblockindex == nullptr) {
290-
const CTransactionRef tx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, oneTxid, Params().GetConsensus(), hashBlock);
286+
const CTransactionRef tx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, *setTxids.begin(), Params().GetConsensus(), hashBlock);
291287
if (!tx || hashBlock.IsNull()) {
292288
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not yet in block");
293289
}

0 commit comments

Comments
 (0)