Skip to content

Commit

Permalink
fix: Let CDeterministicMN::ToJson() return correct `collateralAddress…
Browse files Browse the repository at this point in the history
…` for spent collaterals
  • Loading branch information
UdjinM6 committed Oct 7, 2023
1 parent ce9cfff commit e6f1b4a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,17 @@ UniValue CDeterministicMN::ToJson() const
obj.pushKV("collateralHash", collateralOutpoint.hash.ToString());
obj.pushKV("collateralIndex", (int)collateralOutpoint.n);

Coin coin;
if (GetUTXOCoin(collateralOutpoint, coin)) {
CTxDestination dest;
if (ExtractDestination(coin.out.scriptPubKey, dest)) {
obj.pushKV("collateralAddress", EncodeDestination(dest));
}
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));
}

obj.pushKV("operatorReward", (double)nOperatorReward / 100);
Expand Down

0 comments on commit e6f1b4a

Please sign in to comment.