Skip to content

Commit

Permalink
rpc: don't use GetUTXOCoin in CDeterministicMN::ToJson()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kwvg committed Jun 26, 2024
1 parent 6cb8dcd commit f6f7df3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 4 additions & 0 deletions doc/release-notes-6078.md
Original file line number Diff line number Diff line change
@@ -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`).
18 changes: 7 additions & 11 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit f6f7df3

Please sign in to comment.