From f6f7df37310adffbe773f3e1b8086b6e1233d72b Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kwvg@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:25:05 +0000 Subject: [PATCH] rpc: don't use GetUTXOCoin in CDeterministicMN::ToJson() The fallback introduced in dash#5607 for spent UTXOs also works for unspent UTXOs, no reason to leave it as fallback when it can be made primary. Also, if we did want to keep GetUTXOCoin around, it would need access to CChainState due to the refactoring due in the next commit, which is possible in its RPC invocations but isn't so readily available in Qt code, where it is also called. The fallback code has the benefit of not relying on CChainState. --- doc/release-notes-6078.md | 4 ++++ src/evo/deterministicmns.cpp | 18 +++++++----------- 2 files changed, 11 insertions(+), 11 deletions(-) create mode 100644 doc/release-notes-6078.md diff --git a/doc/release-notes-6078.md b/doc/release-notes-6078.md new file mode 100644 index 0000000000000..1350e0c36817f --- /dev/null +++ b/doc/release-notes-6078.md @@ -0,0 +1,4 @@ +RPC changes +----------- + +- The following RPCs, `protx list`, `protx listdiff`, `protx info` will no longer report `collateralAddress` if the transaction index has been disabled (`txindex=0`). diff --git a/src/evo/deterministicmns.cpp b/src/evo/deterministicmns.cpp index fc2146e22755f..b35dab60a9804 100644 --- a/src/evo/deterministicmns.cpp +++ b/src/evo/deterministicmns.cpp @@ -49,17 +49,13 @@ UniValue CDeterministicMN::ToJson() const obj.pushKV("collateralHash", collateralOutpoint.hash.ToString()); obj.pushKV("collateralIndex", (int)collateralOutpoint.n); - CScript scriptPubKey; - if (Coin coin; GetUTXOCoin(collateralOutpoint, coin)) { - scriptPubKey = coin.out.scriptPubKey; - } else { - uint256 tmpHashBlock; - CTransactionRef collateralTx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, collateralOutpoint.hash, Params().GetConsensus(), tmpHashBlock); - scriptPubKey = collateralTx->vout[collateralOutpoint.n].scriptPubKey; - } - CTxDestination dest; - if (ExtractDestination(scriptPubKey, dest)) { - obj.pushKV("collateralAddress", EncodeDestination(dest)); + uint256 tmpHashBlock; + CTransactionRef collateralTx = GetTransaction(/* block_index */ nullptr, /* mempool */ nullptr, collateralOutpoint.hash, Params().GetConsensus(), tmpHashBlock); + if (collateralTx) { + CTxDestination dest; + if (ExtractDestination(collateralTx->vout[collateralOutpoint.n].scriptPubKey, dest)) { + obj.pushKV("collateralAddress", EncodeDestination(dest)); + } } obj.pushKV("operatorReward", (double)nOperatorReward / 100);