refactor: Convert RPCs and merkleblock from uint256 to Txid

This commit is contained in:
marcofleon
2025-07-23 17:16:09 +01:00
parent 49b3d3a92a
commit 326f244724
12 changed files with 78 additions and 80 deletions

View File

@@ -461,12 +461,12 @@ static RPCHelpMan getmempoolancestors()
if (!request.params[1].isNull())
fVerbose = request.params[1].get_bool();
uint256 hash = ParseHashV(request.params[0], "parameter 1");
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
const auto entry{mempool.GetEntry(txid)};
if (entry == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}
@@ -483,10 +483,9 @@ static RPCHelpMan getmempoolancestors()
UniValue o(UniValue::VOBJ);
for (CTxMemPool::txiter ancestorIt : ancestors) {
const CTxMemPoolEntry &e = *ancestorIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e);
o.pushKV(_hash.ToString(), std::move(info));
o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
}
return o;
}
@@ -523,7 +522,7 @@ static RPCHelpMan getmempooldescendants()
if (!request.params[1].isNull())
fVerbose = request.params[1].get_bool();
Txid txid{Txid::FromUint256(ParseHashV(request.params[0], "parameter 1"))};
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
@@ -549,10 +548,9 @@ static RPCHelpMan getmempooldescendants()
UniValue o(UniValue::VOBJ);
for (CTxMemPool::txiter descendantIt : setDescendants) {
const CTxMemPoolEntry &e = *descendantIt;
const uint256& _hash = e.GetTx().GetHash();
UniValue info(UniValue::VOBJ);
entryToJSON(mempool, info, e);
o.pushKV(_hash.ToString(), std::move(info));
o.pushKV(e.GetTx().GetHash().ToString(), std::move(info));
}
return o;
}
@@ -576,12 +574,12 @@ static RPCHelpMan getmempoolentry()
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
uint256 hash = ParseHashV(request.params[0], "parameter 1");
auto txid{Txid::FromUint256(ParseHashV(request.params[0], "txid"))};
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
const auto entry{mempool.GetEntry(txid)};
if (entry == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}
@@ -1080,7 +1078,7 @@ static RPCHelpMan submitpackage()
UniValue rpc_result{UniValue::VOBJ};
rpc_result.pushKV("package_msg", package_msg);
UniValue tx_result_map{UniValue::VOBJ};
std::set<uint256> replaced_txids;
std::set<Txid> replaced_txids;
for (const auto& tx : txns) {
UniValue result_inner{UniValue::VOBJ};
result_inner.pushKV("txid", tx->GetHash().GetHex());
@@ -1124,7 +1122,7 @@ static RPCHelpMan submitpackage()
}
rpc_result.pushKV("tx-results", std::move(tx_result_map));
UniValue replaced_list(UniValue::VARR);
for (const uint256& hash : replaced_txids) replaced_list.push_back(hash.ToString());
for (const auto& txid : replaced_txids) replaced_list.push_back(txid.ToString());
rpc_result.pushKV("replaced-transactions", std::move(replaced_list));
return rpc_result;
},